-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·97 lines (72 loc) · 1.61 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
#!/bin/bash
INSTALL_PATH="/usr/bin"
function main() {
case "$1" in
-r|--remote)
init_remote "${2-main}"
install || {
echo "[ERROR] Installation failed!" >&2
}
finish_remote
;;
-u|--uninstall)
uninstall
;;
*)
install
esac
}
function install() {
for script in src/*.sh; do
local path="$(to_install_path "$script")"
(
set -x
cp -f "$script" "$path"
chmod +x "$path"
)
done
}
function uninstall() {
for script in src/*.sh; do
local path="$(to_install_path "$script")"
(
set -x
rm -f "$path"
)
done
}
function init_remote() {
local branch="$1"
local path="$(mktemp -d)"
(
set -x
git clone -b "$branch" --single-branch https://github.com/freedev-org/dalias "$path"
)
pushd "$path" > /dev/null
}
function finish_remote() {
local path="$PWD"
assert "[ '${path:0:5}' == '/tmp/' ]" \
"PWD is not on temp dir and this assertion prevent to delete the wrong directory."
popd > /dev/null
(
set -x
rm -rf "$path"
)
}
function to_install_path() {
echo "$INSTALL_PATH/$(basename -s .sh "$1")"
}
function assert() {
local assertion="$1"
local message="$2"
( eval "$assertion" ) || {
caller 0 | head -c-1
echo ": assert: Assertion '$assertion' failed!" >&2
if [ -n "$message" ]; then
echo " $message"
fi
exit 9
}
}
main "$@"