-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
88 lines (80 loc) · 2.75 KB
/
install.sh
File metadata and controls
88 lines (80 loc) · 2.75 KB
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
#!/bin/sh
TMP_NAME="./$(head -c 24 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 32)"
PRERELEASE=false
PRERELEASE_FLAG=""
if [ "$1" = "--prerelease" ]; then
PRERELEASE=true
PRERELEASE_FLAG="--prerelease"
fi
if which curl >/dev/null; then
if curl --help 2>&1 | grep "--progress-bar" >/dev/null 2>&1; then
PROGRESS="--progress-bar"
fi
set -- curl -L $PROGRESS -o "$TMP_NAME"
if [ "$PRERELEASE" = true ]; then
LATEST=$(curl -sL https://api.github.com/repos/alis-is/ami/releases | grep tag_name | sed 's/ "tag_name": "//g' | sed 's/",//g' | head -n 1 | tr -d '[:space:]')
else
LATEST=$(curl -sL https://api.github.com/repos/alis-is/ami/releases/latest | grep tag_name | sed 's/ "tag_name": "//g' | sed 's/",//g' | tr -d '[:space:]')
fi
else
if wget --help 2>&1 | grep "--show-progress" >/dev/null 2>&1; then
PROGRESS="--show-progress"
fi
set -- wget -q $PROGRESS -O "$TMP_NAME"
if [ "$PRERELEASE" = true ]; then
LATEST=$(wget -qO- https://api.github.com/repos/alis-is/ami/releases | grep tag_name | sed 's/ "tag_name": "//g' | sed 's/",//g' | head -n 1 | tr -d '[:space:]')
else
LATEST=$(wget -qO- https://api.github.com/repos/alis-is/ami/releases/latest | grep tag_name | sed 's/ "tag_name": "//g' | sed 's/",//g' | tr -d '[:space:]')
fi
fi
# install eli
echo "Downloading eli setup script..."
if ! "$@" https://raw.githubusercontent.com/alis-is/eli/master/install.sh; then
echo "failed to download eli, please retry ... "
rm "$TMP_NAME"
exit 1
fi
if ! sh "$TMP_NAME" $PRERELEASE_FLAG; then
echo "failed to download eli, please retry ... "
rm "$TMP_NAME"
exit 1
fi
rm "$TMP_NAME"
if ami --version | grep "$LATEST"; then
echo "latest ami already available"
exit 0
fi
BIN="ami"
rm -f "/usr/local/bin/$BIN"
rm -f "/usr/bin/$BIN"
rm -f "/bin/$BIN"
rm -f "/usr/local/sbin/$BIN"
rm -f "/usr/sbin/$BIN"
rm -f "/sbin/$BIN"
# check destination folder
if [ -w "/usr/local/bin" ]; then
DESTINATION="/usr/local/bin/$BIN"
elif [ -w "/usr/local/sbin" ]; then
DESTINATION="/usr/local/sbin/$BIN"
elif [ -w "/usr/bin" ]; then
DESTINATION="/usr/bin/$BIN"
elif [ -w "/usr/sbin" ]; then
DESTINATION="/usr/sbin/$BIN"
elif [ -w "/bin" ]; then
DESTINATION="/bin/$BIN"
elif [ -w "/sbin" ]; then
DESTINATION="/sbin/$BIN"
else
echo "No writable system binary directory found, installing locally."
DESTINATION="./$BIN"
fi
# install ami
echo "Downloading ami $LATEST..."
if "$@" "https://github.com/alis-is/ami/releases/download/$LATEST/ami.lua" &&
cp "$TMP_NAME" "$DESTINATION" && rm "$TMP_NAME" && chmod +x "$DESTINATION"; then
echo "ami $LATEST successfuly installed"
else
rm "$TMP_NAME"
echo "ami installation failed!" 1>&2
exit 1
fi