-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-webint-upldbtn.sh
147 lines (128 loc) · 3.31 KB
/
install-webint-upldbtn.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
#!/usr/bin/env bash
# Copyright (c) 2023 rM-self-serve
# SPDX-License-Identifier: MIT
upldbtn_sha256sum='6cc1c350fbcaf599f8a498050a1cb843501bd8615dc29449a15b303e08f88e4e'
js_sha256sum='6488bfce61b20912e097029942b8a77a4d8fabbafc69f53cbf1dbd634ecd6711'
release='v1.2.0'
installfile='./install-webint-upldbtn.sh'
pkgname='webinterface-upload-button'
localbin='/home/root/.local/bin'
binfile="$localbin/$pkgname"
jsname="$pkgname.js"
jsfile="/usr/share/remarkable/webui/$jsname"
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
remove_install_script
}
remove_install_script() {
read -r -p "Would you like to remove installation script? [y/N] " response
case "$response" in
[yY][eE][sS] | [yY])
printf "Exiting installer and removing script\n"
[[ -f $installfile ]] && rm $installfile
;;
*)
printf "Exiting installer and leaving script\n"
;;
esac
}
sha_check() {
if sha256sum -c <(echo "$1 $2") >/dev/null 2>&1; then
return 0
else
return 1
fi
}
sha_fail() {
echo "sha256sum did not pass, error downloading ${pkgname}"
echo "Exiting installer and removing installed files"
remove_install_files
remove_install_script
exit
}
install_wget() {
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"
}
install() {
echo "${pkgname} ${release}"
echo "Add an upload button to the web interface."
echo 'Ability to revert modification.'
echo ''
echo "This program will be installed in ${localbin}"
echo "${localbin} will be added to the path in ~/.bashrc if necessary"
echo ''
install_wget
mkdir -p $localbin
case :$PATH: in
*:$localbin:*) ;;
*) echo "PATH=\"${localbin}:\$PATH\"" >>/home/root/.bashrc ;;
esac
[[ -f $binfile ]] && revert_mod && remove_install_files
"$wget_path" "https://github.com/rM-self-serve/${pkgname}/releases/download/${release}/${pkgname}" \
-O "$binfile"
if ! sha_check "$upldbtn_sha256sum" "$binfile"; then
sha_fail
fi
chmod +x $binfile
[[ -f $jsfile ]] && rm $jsfile
"$wget_path" "https://github.com/rM-self-serve/${pkgname}/releases/download/${release}/${jsname}" \
-O "$jsfile"
if ! sha_check "$js_sha256sum" "$jsfile"; then
sha_fail
fi
$binfile apply -y
echo ""
echo "${pkgname} applied"
echo ""
}
remove() {
revert_mod
remove_install_files
echo ""
echo "${pkgname} reverted"
echo ""
}
remove_install_files() {
[[ -f $binfile ]] && rm $binfile
[[ -f $jsfile ]] && rm $jsfile
}
revert_mod() {
set -e
if ! [[ -f $binfile ]]; then
echo "$binfile could not be found, can not revert"
exit 1
fi
$binfile revert -y
}
main "$@"