Skip to content

Commit 9e86692

Browse files
committed
v1.2.1
1 parent 6b9602b commit 9e86692

File tree

2 files changed

+82
-76
lines changed

2 files changed

+82
-76
lines changed

install-webint-ob.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Copyright (c) 2023 rM-self-serve
33
# SPDX-License-Identifier: MIT
44

5-
webinterface_onboot_sha256sum='8d85162190511fd2da47276ccf122370ec9445c3cd54f7c519d0a821a759e4e7'
5+
webinterface_onboot_sha256sum='edad550010f408ede2d85f723174735a19e9ffa12ffa31330a3b772e339ed841'
66
service_file_sha256sum='64cfdd5c8eaea1bc8df2e734a41c7ff038585cc2f4248c79e50531901b1ef651'
77

8-
release='v1.2.0'
8+
release='v1.2.1'
99

1010
installfile='./install-webint-ob.sh'
1111
pkgname='webinterface-onboot'

webinterface-onboot

Lines changed: 80 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,30 @@
22
# Copyright (c) 2023 rM-self-serve
33
# SPDX-License-Identifier: MIT
44

5-
webinterface_onboot_version='v1.2.0'
5+
webinterface_onboot_version='v1.2.1'
66

77
main() {
88
# collect options before or after command
99
no_prompt=false
10-
if nop_match "$1"; then
11-
no_prompt=true
12-
shift
13-
fi
14-
cmd=("$1")
15-
if [[ "$2" != "" ]]; then
16-
shift
17-
if [ "$no_prompt" == false ] && nop_match "$1"; then
10+
revert_backup=false
11+
revert_reverse=false
12+
cmd=()
13+
for value in "$@"; do
14+
case $value in
15+
'-y' | '--no-prompt')
1816
no_prompt=true
19-
shift
20-
fi
21-
cmd+=("$@")
22-
fi
17+
;;
18+
'-b' | '--backup')
19+
revert_backup=true
20+
;;
21+
'-r' | '--reverse')
22+
revert_reverse=true
23+
;;
24+
*)
25+
cmd+=("$value")
26+
;;
27+
esac
28+
done
2329

2430
case ${cmd[@]} in
2531
'-h' | '--help' | '')
@@ -32,62 +38,30 @@ main() {
3238
run
3339
;;
3440
'apply-hack')
35-
checkspace
3641
apply_hack
3742
;;
3843
'revert-hack')
39-
checkspace
4044
revert_hack
4145
;;
4246
'apply-prstip')
43-
checkspace
4447
apply_prstip
4548
;;
4649
'revert-prstip')
47-
checkspace
4850
revert_prstip
4951
;;
52+
'is-hack-applied')
53+
cli_hack_applied
54+
;;
55+
'is-prstip-applied')
56+
cli_prstip_applied
57+
;;
5058
*)
5159
echo 'input not recognized'
5260
cli_info
5361
;;
5462
esac
5563
}
5664

57-
checkspace() {
58-
if ! _checkspace / 1; then
59-
(
60-
echo "Not enough space on /"
61-
echo "Try to free space by running: journalctl --vacuum-time=1m"
62-
echo "Or: systemctl restart xochitl"
63-
exit 10
64-
)
65-
exit 1
66-
fi
67-
if ! _checkspace /home 10; then
68-
(
69-
echo "Not enough space on /home"
70-
exit 10
71-
)
72-
exit 1
73-
fi
74-
}
75-
76-
_checkspace() {
77-
part=$1
78-
needed=$2
79-
_available=$(df "$part" | tail -n1 | awk '{print $4}')
80-
available=$(("$_available" / 1024))
81-
if [ $available -lt "$needed" ]; then
82-
echo "Less than ${needed}MB free, ${available}MB"
83-
return 1
84-
fi
85-
}
86-
87-
nop_match() {
88-
[[ "$1" == *"-y"* ]] || [[ "$1" == *"--no-prompt"* ]]
89-
}
90-
9165
cli_info() {
9266
echo -e "${GREEN}webinterface-onboot ${webinterface_onboot_version}${NC}"
9367
echo ''
@@ -108,16 +82,18 @@ cli_info() {
10882
echo ' webinterface-onboot [COMMANDS] [OPTIONS]'
10983
echo ''
11084
echo -e "${CYAN}COMMANDS:${NC}"
111-
echo ' apply-hack Apply webinterface-onboot hack for versions >= v2.15'
112-
echo ' revert-hack Revert webinterface-onboot hack'
113-
echo ' apply-prstip Apply persist ip modification'
114-
echo ' revert-prstip Revert persist ip modification'
115-
echo ' local-exec Run webinterface-onboot in current shell'
85+
echo ' apply-hack Apply webinterface-onboot hack'
86+
echo ' revert-hack Revert webinterface-onboot hack'
87+
echo ' apply-prstip Apply persist ip modification'
88+
echo ' revert-prstip Revert persist ip modification'
89+
echo ' is-hack-applied Return true or false'
90+
echo ' is-prstip-applied Return true or false'
91+
echo ' local-exec Run webinterface-onboot in current shell'
11692
echo ''
11793
echo -e "${CYAN}OPTIONS:${NC}"
118-
echo ' -s, --status Status of webinterface-onboot'
119-
echo ' -y, --no-prompt Do not prompt for confirmation'
120-
echo ' -h, --help Show help'
94+
echo ' -s, --status Status of webinterface-onboot'
95+
echo ' -y, --no-prompt Do not prompt for confirmation'
96+
echo ' -h, --help Show help'
12197
}
12298

12399
run_vars() {
@@ -268,6 +244,24 @@ status() {
268244
fi
269245
}
270246

247+
cli_hack_applied() {
248+
help_vars
249+
if ! hack_applied "$xo_file"; then
250+
echo "false"
251+
exit 1
252+
fi
253+
echo "true"
254+
}
255+
256+
cli_prstip_applied() {
257+
vars_prstip
258+
if ! is_action_moded "$prstip_content"; then
259+
echo "false"
260+
exit 1
261+
fi
262+
echo "true"
263+
}
264+
271265
hack_applied() {
272266
strings "$1" | grep usb | xargs | grep -q 'usbF usb0'
273267
}
@@ -363,7 +357,6 @@ apply_hack() {
363357
rm_temp
364358
echo ""
365359
echo "Success: webinterface-onboot hack applied"
366-
echo "Now run: systemctl restart xochitl"
367360
exit 0
368361
else
369362
echo "Error: mv ${tmp_xo} -> ${xo_file}"
@@ -379,10 +372,25 @@ apply_hack() {
379372
}
380373

381374
revert_hack() {
375+
if [ "$revert_backup" == true ] && [ "$revert_reverse" == true ]; then
376+
echo "Select either --backup or --reverse"
377+
exit 1
378+
fi
379+
if [ "$no_prompt" == true ] && [ "$revert_backup" == false ] && [ "$revert_reverse" == false ]; then
380+
echo "Select either --backup or --reverse"
381+
exit 1
382+
fi
383+
382384
echo "Revert webinterface-onboot hack"
383385
echo ""
384386
help_vars
385-
if [ "$is_hack_version" = true ]; then
387+
388+
if hack_possible "$xo_file"; then
389+
echo "Initial hack has not been applied to this file, nothing to revert"
390+
exit 0
391+
fi
392+
393+
if [ "$is_hack_version" == true ]; then
386394
echo "Compatible xochitl version: v${xo_version}"
387395
else
388396
echo "Incompatible xochitl version: v${xo_version}"
@@ -392,32 +400,32 @@ revert_hack() {
392400
echo "or by applying the hack in reverse order."
393401
echo ""
394402

395-
if hack_possible "$xo_file"; then
396-
echo "Initial hack has not been applied to this file, nothing to revert"
397-
exit 0
398-
fi
399-
if [ "$no_prompt" = false ]; then
403+
if [ "$revert_reverse" == false ]; then
400404
if [ -f "$bak_xo" ]; then
401405
echo "Backup file found: ${bak_xo}"
406+
if [ "$no_prompt" == true ]; then
407+
echo "Reverting from backup file"
408+
revert_from_backup && exit 0 || exit 1
409+
fi
410+
402411
read -r -p "Would you like to revert from backup file? [y/N] " response
403412
case "$response" in
404413
[yY][eE][sS] | [yY])
405414
echo "Reverting from backup file"
406-
if revert_from_backup; then
407-
exit 0
408-
fi
415+
revert_from_backup && exit 0
409416
;;
410417
*)
411418
echo "Cancel revert from backup file"
412419
;;
413420
esac
414421
else
415422
echo "Can't find backup file ${bak_xo}"
416-
echo "Backup files can be at ${STORAGE_HOME} or ${STORAGE_OPT}"
423+
[ "$revert_backup" == true ] && exit 1
417424
fi
418425
fi
419426

420-
if [ "$no_prompt" = false ]; then
427+
if [ "$no_prompt" == false ]; then
428+
echo ""
421429
read -r -p "Would you like to revert by reversing hack? [y/N] " response
422430
case "$response" in
423431
[yY][eE][sS] | [yY])
@@ -436,7 +444,6 @@ revert_from_backup() {
436444
echo ""
437445
if cp "$bak_xo" "$xo_file"; then
438446
echo "Success: Revert from backup file"
439-
echo "Now run: systemctl restart xochitl"
440447
return 0
441448
else
442449
echo "Error: Revert from backup file"
@@ -493,7 +500,6 @@ hack_backwards() {
493500
rm_temp
494501
echo ""
495502
echo "Success: webinterface-onboot hack reverted"
496-
echo "Now run: systemctl restart xochitl"
497503
exit 0
498504
else
499505
echo "Error: mv ${tmp_xo} -> ${xo_file}"
@@ -530,7 +536,7 @@ apply_prstip() {
530536
set -e
531537
vars_prstip
532538

533-
echo "Applying webint-upldbtn will edit: $prstip_file"
539+
echo "Applying the persist ip modification will edit: $prstip_file"
534540
echo 'And create a backup at:'
535541
echo "$prstip_bak_file"
536542
echo ""

0 commit comments

Comments
 (0)