-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
82 lines (72 loc) · 2.51 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
#!/bin/sh
TMP_NAME="./$(head -n 1 -c 32 /dev/urandom | tr -dc 'a-zA-Z0-9'| fold -w 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 [ -f "/usr/sbin/ami" ]; then
rm -f /usr/sbin/ami # remove old ami
fi
if ami --version | grep "$LATEST"; then
echo "Latest ami already available."
exit 0
fi
# check destination folder
if [ -d "/usr/bin" ]; then
DESTINATION="/usr/bin/ami"
elif [ -d "/bin" ]; then
DESTINATION="/bin/ami"
elif [ -d "/usr/local/bin" ]; then
DESTINATION="/usr/local/bin/ami"
elif [ -d "/usr/sbin" ]; then
DESTINATION="/usr/sbin/ami"
else
echo "No destination folder found." 1>&2
exit 1
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