-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall-webint-wf.sh
167 lines (138 loc) · 4.47 KB
/
install-webint-wf.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
#!/usr/bin/env bash
# --- Values replaced in github actions ---
version='VERSION'
webinterface_wifi64_sha256sum='WEBINTERFACE_WIFI64_SHA256SUM'
webinterface_wifi32_sha256sum='WEBINTERFACE_WIFI32_SHA256SUM'
service_file_sha256sum='SERVICE_FILE_SHA256SUM'
config_sha256sum='CONFIG_SHA256SUM'
repo_name='REPO_NAME'
gowget_checksum='GOWGET_CHECKSUM'
wget_checksum='WGET_CHECKSUM'
# -----------------------------------------
pkgname='webinterface-wifi'
installfile='./install-webint-wf.sh'
localbin='/home/root/.local/bin'
binfile="${localbin}/${pkgname}"
aliasfile="${localbin}/webint-wifi"
servicefile="/lib/systemd/system/${pkgname}.service"
configdir="/home/root/.config/${pkgname}"
configfile="${configdir}/config.toml"
sharedir="/home/root/.local/share/${pkgname}"
ssldir="${sharedir}/ssl"
authdir="${sharedir}/auth"
assetsdir="${sharedir}/assets"
faviconfile="${assetsdir}/favicon.ico"
platform=$(uname -m)
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 ''
}
sha_check() {
if ! sha256sum -c <(echo "$1 $2") >/dev/null 2>&1; then
echo "$2 sha256sum did not pass, error downloading ${pkgname}"
echo "Exiting installer and removing installed files"
[[ -f $binfile ]] && rm $binfile
[[ -f $servicefile ]] && rm $servicefile
[[ -f $wget_path ]] && rm $wget_path
exit 1
fi
}
extract_downloader() {
wget_path="/tmp/downloader-$version"
[[ -f "$wget_path" ]] && rm "$wget_path"
PAYLOAD_LINE=$(awk '/^__PAYLOAD__/ { print NR + 1; exit 0; }' $0)
if [[ "$platform" == "aarch64" ]]; then
tail -n +$PAYLOAD_LINE $0 | tar -xzf - gowget -O > "$wget_path"
sha_check "$gowget_checksum" "$wget_path"
else
tail -n +$PAYLOAD_LINE $0 | tar -xzf - wget -O > "$wget_path"
sha_check "$wget_checksum" "$wget_path"
fi
chmod 755 "$wget_path"
}
install() {
printf "\n${pkgname}\n"
printf "View the web interface over wifi\n"
printf "This program will be installed in %s\n" "${localbin}"
printf "%s will be added to the path in ~/.bashrc if necessary\n" "${localbin}"
extract_downloader
mkdir -p $localbin
case :$PATH: in
*:$localbin:*) ;;
*) echo "PATH=\"${localbin}:\$PATH\"" >>/home/root/.bashrc ;;
esac
[[ -f $binfile ]] && rm $binfile
if [[ "$platform" == "aarch64" ]]; then
"$wget_path" -O "$binfile" \
"https://github.com/rM-self-serve/${repo_name}/releases/download/${version}/${pkgname}-arm64"
sha_check $webinterface_wifi64_sha256sum $binfile
else
"$wget_path" -O "$binfile" \
"https://github.com/rM-self-serve/${repo_name}/releases/download/${version}/${pkgname}-arm32"
sha_check $webinterface_wifi32_sha256sum $binfile
fi
chmod +x $binfile
ln -s $binfile $aliasfile
[[ -f $servicefile ]] && rm $servicefile
"$wget_path" -O "$servicefile" \
"https://github.com/rM-self-serve/${repo_name}/releases/download/${version}/${pkgname}.service"
sha_check "$service_file_sha256sum" "$servicefile"
if ! [ -f $configfile ]; then
mkdir -p $configdir
"$wget_path" -O "$configfile" \
"https://github.com/rM-self-serve/${repo_name}/releases/download/${version}/config.default.toml"
sha_check "$config_sha256sum" "$configfile"
fi
mkdir -p $ssldir
mkdir -p $authdir
mkdir -p $assetsdir
[[ -f $faviconfile ]] && rm $faviconfile
"$wget_path" -O "favicon.ico" \
"https://github.com/rM-self-serve/${repo_name}/releases/download/${version}/favicon.ico"
systemctl daemon-reload
printf "\nFinished installing ${pkgname}, removing install script\n\n"
printf "Run the following command to use ${pkgname}\n"
printf "systemctl enable ${pkgname} --now\n\n"
[[ -f $wget_path ]] && rm $wget_path
[[ -f $installfile ]] && rm $installfile
}
remove() {
printf "Remove ${pkgname}\n"
echo "This will not remove the /home/root/.local/bin directory nor the path in .bashrc"
[[ -f $binfile ]] && rm $binfile
[[ -L $aliasfile ]] && rm $aliasfile
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 $servicefile ]] && rm $servicefile
[[ -f $installfile ]] && rm $installfile
rmdir "$sharedir"/*/* "$sharedir"/* "$sharedir" 2> /dev/null || true
echo "Tried to remove ${sharedir}"
echo "Did not remove ${configdir}"
echo "Successfully removed webinterface-wifi"
}
main "$@"
exit 0