-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
95 lines (86 loc) · 2.94 KB
/
install.sh
File metadata and controls
95 lines (86 loc) · 2.94 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
89
90
91
92
93
94
95
#!/bin/sh
TMP_NAME="./$(head -c 24 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 32)"
PRERELEASE=false
if [ "$1" = "--prerelease" ]; then
PRERELEASE=true
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/eli/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/eli/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/eli/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/eli/releases/latest | grep tag_name | sed 's/ "tag_name": "//g' | sed 's/",//g' | tr -d '[:space:]')
fi
fi
if eli -v | grep "$LATEST"; then
echo "latest eli already available"
exit 0
fi
PLATFORM=$(uname -m)
UNAME=$(uname -s | tr '[:upper:]' '[:lower:]')
OS=linux
if [ "$UNAME" = "darwin" ]; then
mkdir -p /usr/local/bin
OS=macos
if [ "$PLATFORM" = "x86_64" ]; then
PLATFORM="amd64"
elif [ "$PLATFORM" = "arm64" ]; then
PLATFORM="aarch64"
else
echo "Unsupported platform: $PLATFORM" 1>&2
exit 1
fi
fi
BIN="eli"
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
if [ "$1" = "--prerelease" ]; then
echo "downloading latest eli prerelease for $PLATFORM..."
else
echo "downloading eli-$OS-$PLATFORM $LATEST..."
fi
if "$@" "https://github.com/alis-is/eli/releases/download/$LATEST/eli-$OS-$PLATFORM" &&
cp "$TMP_NAME" "$DESTINATION" && rm "$TMP_NAME" && chmod +x "$DESTINATION"; then
if [ "$1" = "--prerelease" ]; then
echo "latest eli prerelease for $PLATFORM successfully installed"
else
echo "eli $LATEST for $PLATFORM successfully installed"
fi
else
echo "eli installation failed!" 1>&2
exit 1
fi