-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanchshilscript.sh
More file actions
112 lines (91 loc) · 3.15 KB
/
Copy pathpanchshilscript.sh
File metadata and controls
112 lines (91 loc) · 3.15 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
#!/bin/sh
LOG_FILE="/var/log/tor_modbus_setup.log"
APP_DIR="/data/applications/tor_modbus"
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}
exit_on_error() {
log "ERROR: $1"
exit 1
}
log "========== Tor Modbus Setup Script Started =========="
# 1️⃣ Check root privileges
if [ "$(id -u)" -ne 0 ]; then
exit_on_error "Script must be run as root."
fi
log "Root privilege check passed."
# 2️⃣ Check internet connectivity
log "Checking internet connectivity..."
ping -c 3 -W 5 google.com > /dev/null 2>&1
if [ $? -ne 0 ]; then
exit_on_error "No internet connection. Cannot proceed with package updates."
fi
log "Internet connectivity verified."
# 3️⃣ Update opkg repositories
log "Running opkg update..."
opkg update >> "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
exit_on_error "opkg update failed."
fi
log "opkg update successful."
# 4️⃣ Reinstall tor-modbus
log "Reinstalling tor-modbus package..."
opkg install --force-reinstall tor-modbus >> "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
exit_on_error "tor-modbus installation failed."
fi
log "tor-modbus installed successfully."
# 5️⃣ Reinstall cygmin
log "Reinstalling cygmin package..."
opkg install --force-reinstall cygmin >> "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
exit_on_error "cygmin installation failed."
fi
log "cygmin installed successfully."
# 5️⃣ Reinstall Avahi
log "Reinstalling avahi package..."
opkg install --force-reinstall libnss-mdns libavahi-core libavahi-client libavahi-common avahi avahi-daemon >> "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
exit_on_error "avahi installation failed."
fi
log "avahi installed successfully."
# 5️⃣ Create avahi system user (if not exists)
log "Ensuring avahi system user exists..."
if ! getent group avahi >/dev/null 2>&1; then
log "Creating avahi group..."
addgroup -S avahi >> "$LOG_FILE" 2>&1 || exit_on_error "Failed to create avahi group"
else
log "avahi group already exists."
fi
if ! id avahi >/dev/null 2>&1; then
log "Creating avahi system user..."
adduser -S -D -H -G avahi -s /sbin/nologin avahi >> "$LOG_FILE" 2>&1 \
|| exit_on_error "Failed to create avahi user"
else
log "avahi user already exists."
fi
log "avahi system user verification completed."
# 5️⃣ Reinstall setupdevice
log "Reinstalling setupdevice package..."
opkg install --force-reinstall --force-overwrite setupdevice >> "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
exit_on_error "setupdevice installation failed."
fi
log "setupdevice installed successfully."
# 5️⃣ Reinstall tor-networking
log "Reinstalling tor-networking package..."
opkg install --force-reinstall --force-overwrite tor-networking >> "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
exit_on_error "tor-networking installation failed."
fi
log "tor-networking installed successfully."
# 6️⃣ Remove application directory safely
if [ -d "$APP_DIR" ]; then
log "Removing existing directory: $APP_DIR"
rm -rf "$APP_DIR" || exit_on_error "Failed to delete $APP_DIR"
log "Directory removed successfully."
else
log "Directory $APP_DIR does not exist. Skipping removal."
fi
log "========== Script Completed Successfully =========="
exit 0