This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
forked from LamaAni/zbash-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·109 lines (91 loc) · 2.64 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
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
#!/bin/bash
type curl >&2
if [ $? -ne 0 ]; then
echo "Curl must be installed"
fi
function assert() {
local code="$1"
shift
if [ "$code" -ne 0 ]; then
echo "ERROR: " "$@"
fi
return "$code"
}
HELP="
Installs the zbash-commons library
USAGE: Install [branch]
ARGS:
-l --location The install location (default: /lib/zbash-commons)
"
while [ "$#" -gt 0 ]; do
case $1 in
-h | --help)
echo "$HELP"
exit 0
;;
-l | --location)
shift
ZBASH_COMMONS_INSTALL_LOCATION="$1"
;;
-*)
assert 2 "Invalid argument: $1"
;;
*)
if [ -z "$ZBASH_COMMONS_VERSION" ]; then
ZBASH_COMMONS_VERSION="$1"
else
assert 2 "Unknown input: $1"
fi
;;
esac
shift
done
: "${ZBASH_COMMONS_VERSION:="latest"}"
: "${ZBASH_COMMONS_SOURCE_COMMAND_LOCATION:="/usr/bin/zbash_commons"}"
# ------------------
: "${ZBASH_COMMONS_TEMP_PATH:="/tmp/zbash_commons.temp.$RANDOM.download.sh"}"
function install() {
URL_BRANCH="$ZBASH_COMMONS_VERSION"
if [ "$URL_BRANCH" == "latest" ]; then
URL_BRANCH="master"
fi
GET_SCRIPT_URL="https://raw.githubusercontent.com/LamaAni/zbash-commons/$URL_BRANCH/get?v_$(date +"%S")=$RANDOM"
echo "$GET_SCRIPT_URL"
curl -sL "$GET_SCRIPT_URL" | bash -s "$ZBASH_COMMONS_VERSION" >|"$ZBASH_COMMONS_TEMP_PATH"
assert $? "Failed to download zbash_commons compiled script" || return $?
source "$ZBASH_COMMONS_TEMP_PATH"
assert $? "Failed to load zbash_commons script, error in script?" || return $?
log:sep "Installing zbash-commons as $(whoami)"
log "Checking required premissions"
if [ "$(whoami)" != "root" ]; then
log "checking if sudo is available..."
type sudo >/dev/null 2>&1
if [ $? -ne 0 ]; then
warn 2 "Sudo not found. Attempting to install with user $(whoami)"
else
assert 2 "Sudo found, please rerun as root" || return $?
fi
fi
if [ -f "$ZBASH_COMMONS_SOURCE_COMMAND_LOCATION" ]; then
rm -rf "$ZBASH_COMMONS_SOURCE_COMMAND_LOCATION"
assert $? "Failed to remove old code" || return $?
fi
log "Downloading.."
cat "$ZBASH_COMMONS_TEMP_PATH" >"$ZBASH_COMMONS_SOURCE_COMMAND_LOCATION" && chmod +x "$ZBASH_COMMONS_SOURCE_COMMAND_LOCATION"
log "Installed OK -> $ZBASH_COMMONS_SOURCE_COMMAND_LOCATION ($(wc -l $ZBASH_COMMONS_SOURCE_COMMAND_LOCATION) lines)"
}
function cleanup() {
local code=$?
rm -rf "$ZBASH_COMMONS_TEMP_PATH"
assert "$@" || return $?
}
install
cleanup $? "Failed to install" || exit $?
echo '
Library installed. To use, add the following at the head of your script,
#!/bin/bash
source zbash_commons
if [ $? -ne 0 ]; then
echo "zbash_commons not found. Please see: https://github.com/LamaAni/zbash-commons"
fi
'