-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·157 lines (124 loc) · 3.21 KB
/
install.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
#!/bin/sh
export CLR_RESET='\033[1;0m'
export STL_BOLD='\033[1;1m'
export CLR_RED='\033[0;31m'
export CLR_GREEN='\033[0;32m'
export CLR_BLUE='\033[0;34m'
has() {
_cmd=$(command -v "$1") 2> /dev/null || return 1
[ -x "$_cmd" ] || return 1
}
msg() {
printf "${CLR_BLUE}${STL_BOLD}::${CLR_RESET} ${STL_BOLD}%s${CLR_RESET}\n" "$1"
shift
for i in "$@"; do
printf " ${CLR_BLUE}${STL_BOLD}|${CLR_RESET} ${STL_BOLD}%s${CLR_RESET}\n" "$i"
done
}
compl() {
printf "${CLR_GREEN}${STL_BOLD}>>>${CLR_RESET} ${STL_BOLD}%s${CLR_RESET}\n" "$1"
shift
for i in "$@"; do
printf " ${CLR_GREEN}${STL_BOLD}|${CLR_RESET} ${STL_BOLD}%s${CLR_RESET}\n" "$i"
done
}
die() {
printf "${CLR_RED}${STL_BOLD}error:${CLR_RESET} ${STL_BOLD}%s${CLR_RESET}\n" "$1"
shift
for i in "$@"; do
printf " ${CLR_RED}${STL_BOLD}|${CLR_RESET} ${STL_BOLD}%s${CLR_RESET}\n" "$i"
done
exit 1
}
download() {
curl -sfLo "$1" "$2"
}
verify_checksums() {
msg 'Verifying checksums.'
if has sha256sum; then
_ok=$(sha256sum --ignore-missing --quiet --check checksums.txt)
else
_ok=$(shasum -a 256 --ignore-missing --quiet --check checksums.txt)
fi
$_ok || die 'Checksums did not match! Abort'
}
main() {
NAME="hexedit"
OS="$(uname -s)"
msg 'OS fetched.'
ARCH="$(uname -m)"
msg 'ARCH fetched.'
TMPDIR="$(mktemp -d)"
msg 'Temp dir created.'
compl 'All required info fetched.'
RELEASES_URL="https://github.com/illegitimate-egg/${NAME}/releases"
msg 'Fetching latest version'
TAG="$(curl -sfL -o /dev/null -w "%{url_effective}" "${RELEASES_URL}/latest" | \
rev | \
cut -f1 -d'/' | \
rev)"
[ -z "$TAG" ] && {
die "Unable to get ${NAME} version." \
'try to install curl'
}
echo "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$' && {
die "Unable to get ${NAME} version."
}
VERSION="$TAG"
compl "Latest version is ${VERSION}"
case "$ARCH" in
"x86_64")
ARCH="amd64"
;;
i*)
ARCH="386"
;;
*)
die "$ARCH is unsupported"
;;
esac
msg 'ARCH configured.'
case "$OS" in
"Linux")
OS="linux"
;;
*)
die "$OS is unsupported"
;;
esac
msg 'OS configured.'
export TAR_NAME="${NAME}_${VERSION}_${OS}_${ARCH}.tar.gz"
export TAR_FILE="${TMPDIR}/${TAR_NAME}"
(
cd "$TMPDIR"
msg "Downloading $TAR_NAME"
download "$TAR_FILE" "$RELEASES_URL/download/$TAG/$TAR_NAME"
msg "Downloading checksums"
download "checksums.txt" "$RELEASES_URL/download/$TAG/checksums.txt"
verify_checksums
msg "Downloading manual page"
download "hexedit.1.gz" "$RELEASES_URL/download/$TAG/hexedit.1.gz"
)
msg "Extract ${TAR_FILE}"
tar -xzf "$TAR_FILE" -C "$TMPDIR/"
if has hexedit; then
OUT="$(dirname "$(command -v hexedit)")"
else
OUT="/usr/local/bin"
fi
mkdir -p "$OUT"
msg "Moving to '/usr/bin'"
if has doas; then
doas mv "${TMPDIR}/${NAME}_${VERSION}_${OS}_${ARCH}" "${OUT}/${NAME}"
elif has sudo; then
sudo mv "${TMPDIR}/${NAME}_${VERSION}_${OS}_${ARCH}" "${OUT}/${NAME}"
fi
msg "Install manual page"
sudo mv "${TMPDIR}/hexedit.1.gz" "/usr/share/man/man1/hexedit.1.gz"
if has man; then
msg "Update mandb"
sudo mandb -q
fi
compl "Installation COMPLETED."
}
main