-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·71 lines (63 loc) · 1.82 KB
/
install
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
#!/usr/bin/env sh
_exists() {
cmd="$1"
if [ -z "$cmd" ]; then
echo "Usage: _exists cmd"
return 1
fi
if type command >/dev/null 2>&1; then
command -v "$cmd" >/dev/null 2>&1
else
type "$cmd" >/dev/null 2>&1
fi
ret="$?"
return $ret
}
# Tiago Lopo: https://stackoverflow.com/a/29436423/9264137
# This is used to ask the user for confirmation.
_yes_or_no() {
while true; do
read -r -p "$* [y/N]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*)
return 1
;;
esac
done
}
if [ -z "$BRANCH" ]; then
BRANCH="main"
fi
download() {
if _exists curl && [ "${RESERVER_USE_WGET:-0}" = "0" ]; then
curl -fsSL https://raw.githubusercontent.com/ceiphr/reserver/$BRANCH/reserver.sh >reserver.sh && chmod +x reserver.sh
elif _exists wget; then
wget -O - https://raw.githubusercontent.com/ceiphr/reserver/$BRANCH/reserver.sh >reserver.sh && chmod +x reserver.sh
else
echo "You must have curl or wget installed before running this script." >&2
exit 1
fi
}
install=true
if [ -z "${RESERVER_INSTALL}" ]; then
_yes_or_no "Install reserver to /usr/local/bin? Root required." || install=false
fi
if [ "$install" = false ]; then
echo "Run './reserver.sh' to reserve some space!"
download
exit 1
fi
if [ -d "/usr/local/bin" ] && [ "$install" = true ]; then
if [ -f "/usr/local/bin/reserver" ]; then
echo "You already have reserver installed." >&2
echo "You'll need to remove '/usr/local/bin/reserver' before you can reinstall." >&2
exit 1
fi
download
sudo mv reserver.sh "/usr/local/bin/reserver"
echo "Done. Run 'reserver' to reserve some space!"
else
echo "Could not find /usr/local/bin. Ensure your OS is supported." >&2
exit 1
fi