-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
117 lines (107 loc) · 2.57 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
set -e
# Global vars
INSTALLATION_PATH="/usr/local/bin/"
BINARY_NAME="mtoc"
happyexit(){
echo ""
echo "$BINARY_NAME successfully installed! 🎉"
echo ""
echo "Now run: $ $BINARY_NAME --help"
echo ""
exit 0
}
# Check OS
OS=$(uname -s)
arch=$(uname -m)
cli_arch=""
case $OS in
Darwin)
case $arch in
x86_64)
cli_arch=amd64
;;
arm64)
cli_arch=$arch
;;
*)
echo "There is no $BINARY_NAME $OS support for $arch"
exit 1
;;
esac
;;
Linux)
case $arch in
x86_64)
cli_arch=amd64
;;
armv8*)
cli_arch=arm64
;;
aarch64*)
cli_arch=arm64
;;
amd64|arm64)
cli_arch=$arch
;;
*)
echo "There is no $BINARY_NAME $OS support for $arch"
exit 1
;;
esac
;;
*)
echo "There is no $BINARY_NAME $OS support for $arch"
exit 1
;;
esac
OS=$(echo "$OS" | tr '[:upper:]' '[:lower:]')
download_release() {
LATEST_VERSION=$(curl -s https://api.github.com/repos/containerscrew/$BINARY_NAME/releases/latest | jq -r ".name")
if [ -z "$1" ]; then VERSION=$LATEST_VERSION; else VERSION=$1; fi
printf "\033[0;32m[info] - Downloading version: ${VERSION}/$BINARY_NAME-${OS}-${cli_arch}.zip \033[0m\n"
curl -L --fail --remote-name-all https://github.com/containerscrew/$BINARY_NAME/releases/download/"${VERSION}"/$BINARY_NAME-"${OS}"-"${cli_arch}".zip -o /tmp/$BINARY_NAME.zip
unzip -o /tmp/$BINARY_NAME.zip -d /tmp/
}
install_binary(){
if [ "$(id -u)" = 0 ]; then
cp /tmp/$BINARY_NAME $INSTALLATION_PATH
chmod +x $INSTALLATION_PATH/$BINARY_NAME
else
sudo cp /tmp/$BINARY_NAME $INSTALLATION_PATH
sudo chmod +x $INSTALLATION_PATH/$BINARY_NAME
fi
rm -rf /tmp/$BINARY_NAME*
happyexit
}
# Function to display help text
usage() {
echo "Usage: $0 [-v] [-h]"
echo "Options:"
echo " -v Select which version do you want to install."
echo " -h Display the help message"
}
# Parse options using getopts
while getopts "v:h" option; do
case "${option}" in
v) # Install specific version
version=${OPTARG}
download_release "$version"
install_binary
;;
h) # Help option
usage
exit 0
;;
\?) # Invalid option
echo "Invalid option: -${OPTARG}"
usage
exit 1
;;
esac
done
# If no flags, by default install latest version
if [ $# -eq 0 ]; then
download_release
install_binary
fi