-
Notifications
You must be signed in to change notification settings - Fork 8
/
updater.sh
executable file
·49 lines (40 loc) · 1.18 KB
/
updater.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
#!/bin/sh
set -euf
# check dependences
checkDep() {
command -v "$1" >/dev/null 2>&1 || {
echo >&2 "hosty requires '$1' but it's not installed."
exit 1
}
}
checkDep curl
checkDep gpg
checkDep mktemp
# creating tmp files
astrokeys=$(mktemp)
hosty=$(mktemp)
signature=$(mktemp)
# download function
downloadFile() {
if ! curl -sSL --retry 3 -o "$1" "$2"; then
echo "error downloading $2"
rm "$astrokeys" "$hosty" "$signature"
exit 1
fi
}
# download files
downloadFile "$astrokeys" https://keybase.io/astrolince/pgp_keys.asc
downloadFile "$hosty" https://4st.li/hosty/hosty.sh
downloadFile "$signature" https://4st.li/hosty/hosty.sh.sig
# verify signature
gpg --dearmor "$astrokeys" >/dev/null 2>&1
# if there is a problem, kill the program
if ! gpg --no-default-keyring --keyring "$astrokeys.gpg" --verify "$signature" "$hosty" >/dev/null 2>&1; then
rm "$astrokeys" "$hosty" "$signature" "$astrokeys.gpg"
echo "there is a problem with the signature, probably hosty repository was compromised, no changes were made to your system."
exit 1
fi
rm "$astrokeys" "$signature" "$astrokeys.gpg"
# shellcheck source=/dev/null
. "$hosty"
rm "$hosty"