-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-webint-ob.sh
202 lines (174 loc) · 4.68 KB
/
install-webint-ob.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env bash
# Copyright (c) 2024 rM-self-serve
# SPDX-License-Identifier: MIT
# --- Values replaced in github actions ---
version='VERSION'
webinterface_onboot_sha256sum='WEBINTERFACE_ONBOOT_SHA256SUM'
service_file_sha256sum='SERVICE_FILE_SHA256SUM'
# -----------------------------------------
installfile='./install-webint-ob.sh'
pkgname='webinterface-onboot'
localbin='/home/root/.local/bin'
binfile="${localbin}/${pkgname}"
servicefile="/lib/systemd/system/${pkgname}.service"
aliasfile="${localbin}/webint-onboot"
wget_path=/home/root/.local/share/rM-self-serve/wget
wget_remote=http://toltec-dev.org/thirdparty/bin/wget-v1.21.1-1
wget_checksum=c258140f059d16d24503c62c1fdf747ca843fe4ba8fcd464a6e6bda8c3bbb6b5
main() {
case "$@" in
'install' | '')
install
;;
'remove')
remove
;;
*)
echo 'input not recognized'
cli_info
exit 0
;;
esac
}
cli_info() {
echo "${pkgname} installer ${version}"
echo -e "${CYAN}COMMANDS:${NC}"
echo ' install'
echo ' remove'
echo ''
}
pkg_sha_check() {
sha256sum -c <(echo "$webinterface_onboot_sha256sum $binfile") >/dev/null 2>&1
}
srvc_sha_check() {
sha256sum -c <(echo "$service_file_sha256sum $servicefile") >/dev/null 2>&1
}
sha_fail() {
echo "sha256sum did not pass, error downloading ${pkgname}"
echo "Exiting installer and removing installed files"
[[ -f $binfile ]] && rm $binfile
[[ -f $servicefile ]] && rm $servicefile
exit 1
}
install() {
echo "Install ${pkgname} ${version}"
echo ''
echo "This program will be installed in ${localbin}"
echo "${localbin} will be added to the path in ~/.bashrc if necessary"
echo ''
if [ -f "$wget_path" ] && ! sha256sum -c <(echo "$wget_checksum $wget_path") >/dev/null 2>&1; then
rm "$wget_path"
fi
if ! [ -f "$wget_path" ]; then
echo "Fetching secure wget"
# Download and compare to hash
mkdir -p "$(dirname "$wget_path")"
if ! wget -q "$wget_remote" --output-document "$wget_path"; then
echo "Error: Could not fetch wget, make sure you have a stable Wi-Fi connection"
exit 1
fi
fi
if ! sha256sum -c <(echo "$wget_checksum $wget_path") >/dev/null 2>&1; then
echo "Error: Invalid checksum for the local wget binary"
exit 1
fi
chmod 755 "$wget_path"
mkdir -p $localbin
case :$PATH: in
*:$localbin:*) ;;
*) echo "PATH=\"${localbin}:\$PATH\"" >>/home/root/.bashrc ;;
esac
need_bin=true
if [ -f $binfile ]; then
if pkg_sha_check; then
need_bin=false
echo "Already have the right version of ${pkgname}"
else
rm $binfile
fi
fi
if [ "$need_bin" = true ]; then
"$wget_path" -q "https://github.com/rM-self-serve/${pkgname}/releases/download/${version}/${pkgname}" \
-O "$binfile"
if ! pkg_sha_check; then
sha_fail
fi
chmod +x "$binfile"
echo "Fetched ${pkgname}"
fi
need_service=true
if [ -f $servicefile ]; then
if srvc_sha_check; then
need_service=false
echo "Already have the right version of ${pkgname}.service"
else
rm $servicefile
fi
fi
if [ "$need_service" = true ]; then
"$wget_path" -q "https://github.com/rM-self-serve/${pkgname}/releases/download/${version}/${pkgname}.service" \
-O "$servicefile"
if ! srvc_sha_check; then
sha_fail
fi
echo "Fetched ${pkgname}.service"
fi
systemctl daemon-reload
echo ''
echo "Applying usb0 ip persistence"
if ! "$binfile" apply-prstip -y >/dev/null; then
echo "Error, exiting"
exit 1
fi
echo "Success"
if "$binfile" is-hack-version >/dev/null; then
echo ''
echo "Applying binary modification"
if ! "$binfile" apply-hack -y >/dev/null; then
echo "Error, exiting"
exit 1
fi
echo "Success"
fi
echo ''
echo "Finished installing $pkgname"
echo ''
echo "Run the following command to use ${pkgname}"
echo "$ systemctl enable ${pkgname} --now"
echo ''
[[ -f $installfile ]] && rm $installfile
}
remove() {
echo "Remove ${pkgname}"
echo ''
echo "This will not remove the /home/root/.local/bin directory nor the path in .bashrc"
echo ''
if "$binfile" is-prstip-applied >/dev/null; then
if ! "$binfile" revert-prstip -y >/dev/null; then
echo "Error, exiting"
exit 1
fi
fi
echo "Reverted persist-ip"
if "$binfile" is-hack-applied >/dev/null; then
if ! "$binfile" revert-hack --reverse -y >/dev/null; then
echo "Error, exiting"
exit 1
fi
fi
echo "Reverted binary hack"
if systemctl --quiet is-active "$pkgname" 2>/dev/null; then
echo "Stopping $pkgname"
systemctl stop "$pkgname"
fi
if systemctl --quiet is-enabled "$pkgname" 2>/dev/null; then
echo "Disabling $pkgname"
systemctl disable "$pkgname"
fi
[[ -f $binfile ]] && rm $binfile
[[ -f $servicefile ]] && rm $servicefile
[[ -f $aliasfile ]] && rm $aliasfile
[[ -f $installfile ]] && rm $installfile
echo "Successfully reverted and removed ${pkgname}"
}
main "$@"