-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·105 lines (89 loc) · 2.5 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
#!/bin/bash
type curl >/dev/null
if [ $? -ne 0 ]; then
echo "Curl must be installed"
fi
type assert &>/dev/null
if [ $? -ne 0 ] || [ "$ZBASH_COMMONS_LIB_LOADED" != "true" ]; then
type zbash_commons &>/dev/null
if [ $? -ne 0 ]; then
echo "[DOWNLOAD] Downloading zbash_commons from latest release.." 1>&2
ZBASH_COMMONS_GET_SCRIPT="$(curl -Ls "https://raw.githubusercontent.com/LamaAni/zbash-commons/master/get?ts_$(date +%s)=$RANDOM")"
ZBASH_COMMONS="$(bash -c "$ZBASH_COMMONS_GET_SCRIPT")"
eval "$ZBASH_COMMONS"
else
source zbash_commons
fi
fi
HELP="
Installs the zbash-config library
USAGE: [version]
INPUTS:
version The version to use. Defautls to latest.
ARGS:
--location The filepath where to install.
"
INSTALL_LOCATION="$HOME/.local/bin/zbash_config"
while [ "$#" -gt 0 ]; do
case $1 in
-h | --help)
echo "$HELP"
exit 0
;;
-l | --location)
shift
INSTALL_LOCATION="$1"
;;
-*)
assert 2 "Invalid argument: $1"
;;
*)
: "${positional:=0}"
case $positional in
0)
VERSION="$1"
;;
*)
assert 2 "Invalid input: $1" || return $?
;;
esac
positional=$((positional + 1))
;;
esac
shift
done
: "${VERSION:="latest"}"
TEMP_DOWNLOAD_PATH="$(mktemp)"
REPO_SUBPATH="LamaAni/zbash_config"
function install_lib() {
log:sep "Prepare temp files"
URL_BRANCH="$VERSION"
if [ "$URL_BRANCH" == "latest" ]; then
URL_BRANCH="master"
fi
local get_script=""
GET_SCRIPT_URL="https://raw.githubusercontent.com/$REPO_SUBPATH/$URL_BRANCH/get?v_$(date +"%S")=$RANDOM"
log:info "Downloading $GET_SCRIPT_URL"
get_script="$(curl -sL "$GET_SCRIPT_URL")"
assert $? "Failed to download versioned get script"
log:info "Getting version script"
echo "$get_script" | bash -s "$VERSION" >|"$TEMP_DOWNLOAD_PATH"
assert $? "Failed to download zbash_config compiled script" || return $?
log:sep "Installing zbash_config as $(whoami) @ $INSTALL_LOCATION"
mkdir -p "$(dirname "$INSTALL_LOCATION")"
assert $? "Failed to validate install location @ $INSTALL_LOCATION"
if [ -f "$INSTALL_LOCATION" ]; then
rm -rf "$INSTALL_LOCATION"
assert $? "Failed to remove old code" || return $?
fi
cat "$TEMP_DOWNLOAD_PATH" >"$INSTALL_LOCATION" && chmod +x "$INSTALL_LOCATION"
log "Installed OK -> $INSTALL_LOCATION ($(wc -l $INSTALL_LOCATION) lines)"
}
function cleanup() {
local code=$?
rm -rf "$TEMP_DOWNLOAD_PATH"
assert "$@" || return $?
return $code
}
install_lib
cleanup $? "Failed to install" || exit $?