-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathopensync_disabler.sh
More file actions
111 lines (99 loc) · 3.33 KB
/
Copy pathopensync_disabler.sh
File metadata and controls
111 lines (99 loc) · 3.33 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
#!/bin/ash
echo "=============================================="
echo " opensync_disabler "
echo " Disable Opensync-related services "
echo " and patch init scripts "
echo " "
echo " Usage: "
echo " ./opensync_disabler.sh "
echo " ./opensync_disabler.sh --restore "
echo "=============================================="
set -e
SERVICES="healthcheck opensync jioWifiManagerStartup jioDscpPriority jioWifiNotifierStartup jioWifiLoggerStartup"
INIT_SCRIPTS="plumeConfigMerge platformConfigMerge opensync dnsmasq"
restore_script() {
SCRIPT="/etc/init.d/$1"
BACKUP="$SCRIPT.bak"
if [ -f "$BACKUP" ]; then
echo " -> Restoring $SCRIPT"
cp "$BACKUP" "$SCRIPT" || {
echo " !! Failed to restore $SCRIPT from backup"
return 1
}
chmod +x "$SCRIPT"
else
echo " !! No backup found for $SCRIPT"
fi
}
patch_script() {
SCRIPT="/etc/init.d/$1"
[ -f "$SCRIPT" ] || return
# Always backup before patching
cp "$SCRIPT" "$SCRIPT.bak"
case "$1" in
plumeConfigMerge|platformConfigMerge)
# Collapse any PlumeEnabled assignment down to 0
sed -i 's/PlumeEnabled=".*"/PlumeEnabled="0"/g' "$SCRIPT"
;;
opensync)
# Replace service-enabled function to always return false
awk '
BEGIN {skip=0}
/^opensync_service_enabled\(\)/ {
print "opensync_service_enabled() {\n false\n}"
skip=1
next
}
skip && /^\}/ { skip=0; next }
!skip { print }
' "$SCRIPT.bak" > "$SCRIPT"
;;
dnsmasq)
# Comment out the bind-dynamic append_bool line
sed -i '/append_bool.*nonwildcard.*--bind-dynamic/ s/^/#/' "$SCRIPT"
;;
esac
}
disable_services() {
echo "[*] Disabling services..."
for svc in $SERVICES; do
INIT_PATH="/etc/init.d/$svc"
if [ -x "$INIT_PATH" ]; then
echo " -> Disabling $svc"
$INIT_PATH stop 2>/dev/null || true
$INIT_PATH disable 2>/dev/null || true
chmod -x "$INIT_PATH"
else
echo " !! Service $svc not found or not executable"
fi
done
}
restore_services() {
echo "[*] Restoring services..."
for svc in $SERVICES; do
# If we have a backed-up init script, restore and re-enable it
if [ -f "/etc/init.d/$svc.bak" ]; then
echo " -> Re-enabling $svc"
cp "/etc/init.d/$svc.bak" "/etc/init.d/$svc"
chmod +x "/etc/init.d/$svc"
/etc/init.d/$svc enable 2>/dev/null || true
fi
done
}
# Main execution flow
if [ "$1" = "--restore" ] || [ "$1" = "-r" ]; then
echo "[*] Restoring all changes..."
for script in $INIT_SCRIPTS; do
restore_script "$script"
done
restore_services
echo "[*] Restore complete."
else
disable_services
echo "[*] Patching init scripts..."
for script in $INIT_SCRIPTS; do
patch_script "$script"
done
echo "[*] Done. All services disabled and init scripts patched."
echo "[*] Please reboot the device for changes to take effect."
fi