-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModify-RC-Support-Features.sh
74 lines (63 loc) · 1.87 KB
/
Modify-RC-Support-Features.sh
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
#!/bin/sh
# rc_support modify script
BACKUP_DIR="/jffs/backups"
INIT_SCRIPT="/jffs/scripts/init-start"
RC_SUPPORT_BACKUP="$BACKUP_DIR/rc_support.bak"
INIT_MARKER="#rc_support modification"
# Ensure backup directory exists
mkdir -p "$BACKUP_DIR"
# Function to modify rc_support
modify_rc_support() {
local action="$1"
local feature="$2"
# Backup current rc_support if not already backed up
if [ ! -f "$RC_SUPPORT_BACKUP" ]; then
nvram get rc_support > "$RC_SUPPORT_BACKUP"
fi
# Read current rc_support
local rc_support
rc_support=$(nvram get rc_support)
case "$action" in
"add")
if ! echo "$rc_support" | grep -q "$feature"; then
rc_support="$rc_support $feature"
fi
;;
"remove")
rc_support=$(echo "$rc_support" | sed "s/$feature//g" | tr -s ' ')
;;
esac
# Set new rc_support value
nvram set rc_support="$rc_support"
echo "$INIT_MARKER" >> "$INIT_SCRIPT"
logger -st "rc_support_script" "Modified rc_support: $rc_support"
}
# Function to restore original rc_support
restore_rc_support() {
if [ -f "$RC_SUPPORT_BACKUP" ]; then
local original_rc_support
original_rc_support=$(cat "$RC_SUPPORT_BACKUP")
nvram set rc_support="$original_rc_support"
logger -st "rc_support_script" "Restored original rc_support"
# Remove the marker line from init-start
sed -i "/$INIT_MARKER/d" "$INIT_SCRIPT"
else
logger -st "rc_support_script" "Backup not found, cannot restore original rc_support!"
fi
}
# Main script logic
case "$1" in
"restore")
restore_rc_support
;;
"add")
modify_rc_support "add" "$2"
;;
"remove")
modify_rc_support "remove" "$2"
;;
*)
echo "Usage: $0 restore|add|remove [feature]"
exit 1
;;
esac