-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmodify-features.sh
More file actions
121 lines (96 loc) · 3.57 KB
/
modify-features.sh
File metadata and controls
121 lines (96 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh
# Made by Jack'lul <jacklul.github.io>
#
# Modify rc_support nvram variable to show/hide features in the WebUI
# This does not unlock any hidden features
#
#jas-update=modify-features.sh
#shellcheck shell=ash
#shellcheck disable=SC2155
#shellcheck source=./common.sh
readonly common_script="$(dirname "$0")/common.sh"
if [ -f "$common_script" ]; then . "$common_script"; else { echo "$common_script not found" >&2; exit 1; } fi
FEATURES_REMOVE="" # features to remove from the list
FEATURES_ADD="" # features to add to the list
RUN_EVERY_MINUTE= # verify that the features list is still modified (true/false), empty means false when service-event script is available but otherwise true
load_script_config
state_file="$TMP_DIR/$script_name"
backup_file="$TMP_DIR/$script_name.bak"
rc_support() {
local _rc_support _rc_support_last
case "$1" in
"modify")
{ [ -z "$FEATURES_REMOVE" ] && [ -z "$FEATURES_ADD" ] ; } && { logecho "Error: FEATURES_REMOVE/FEATURES_ADD is not set" error; exit 1; }
if [ ! -f "$backup_file" ]; then
_rc_support="$(nvram get rc_support)"
echo "$_rc_support" > "$backup_file"
chmod 644 "$backup_file"
else
_rc_support="$(cat "$backup_file")"
fi
if [ -f "$state_file" ]; then
_rc_support_last="$(cat "$state_file")"
fi
[ "$(nvram get rc_support)" = "$_rc_support_last" ] && exit
local _feature_to_remove _feature_to_add
for _feature_to_remove in $FEATURES_REMOVE; do
if echo "$_rc_support" | grep -Fq "$_feature_to_remove"; then
_rc_support="$(echo "$_rc_support" | sed "s/$_feature_to_remove//g")"
fi
done
for _feature_to_add in $FEATURES_ADD; do
if ! echo "$_rc_support" | grep -Fq "$_feature_to_add"; then
_rc_support="$_rc_support $_feature_to_add"
fi
done
_rc_support="$(echo "$_rc_support" | tr -s ' ')"
echo "$_rc_support" > "$state_file"
nvram set rc_support="$_rc_support"
logecho "Modified rc_support" alert
;;
"restore")
rm -f "$state_file"
if [ -f "$backup_file" ]; then
local _rc_support="$(cat "$backup_file")"
nvram set rc_support="$_rc_support"
logecho "Restored original rc_support" alert
else
logecho "Could not find '$backup_file' - cannot restore original rc_support!" error
fi
;;
esac
}
case "$1" in
"run")
rc_support modify
;;
"check")
# used by service-event script
if [ -f "$state_file" ]; then
rc_support_last="$(cat "$state_file")"
[ "$(nvram get rc_support)" = "$rc_support_last" ] && exit 0
fi
exit 1
;;
"start")
rc_support modify
# Set value of empty RUN_EVERY_MINUTE depending on situation
execute_script_basename "service-event.sh" check && service_event_active=true
[ -z "$RUN_EVERY_MINUTE" ] && [ -z "$service_event_active" ] && RUN_EVERY_MINUTE=true
if [ "$RUN_EVERY_MINUTE" = true ]; then
crontab_entry add "*/1 * * * * $script_path run"
fi
;;
"stop")
crontab_entry delete
rc_support restore
;;
"restart")
sh "$script_path" stop
sh "$script_path" start
;;
*)
echo "Usage: $0 run|start|stop|restart"
exit 1
;;
esac