-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
105 lines (90 loc) · 2.32 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
#!/bin/bash
set -e
main() {
# set ${variable-default}
BIN_DIR=${BIN_DIR-"$HOME/.bin"}
mkdir -p BIN_DIR
# Detect shell
case $SHELL in
*/zsh)
PROFILE=$HOME/.zshrc
PREF_SHELL=zsh
;;
*/bash)
PROFILE=$HOME/.bashrc
PREF_SHELL=bash
;;
*/ash)
PROFILE=$HOME/.PROFILE
PREF_SHELL=ash
;;
*)
echo "could not detect shell, manually add ${BIN_DIR} to your path."
exit 1
esac
# Add BIN_DIR to path if not exist
if [[ ":$PATH:" != *":${BIN_DIR}:"* ]]; then
echo >> $PROFILE && echo "export PATH=\"\$PATH:$BIN_DIR\"" >> $PROFILE
fi
# Detect OS & Arch
PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux"
;;
Darwin)
PLATFORM="darwin"
;;
Windows)
PLATFORM="windows"
;;
*)
echo "unsupported platform: $PLATFORM"
exit 1
esac
ARCH="$(uname -m)"
if [ "${ARCH}" == "x86_64"]; then
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" != "1" ]; then
ARCH="x86_64"
else
echo "unsupported architecture"
exit 1
fi
elif [ "${ARCH}" = "arm64" ] || [ "${ARCH}" = "aarch64" ]; then
echo "unsupported architecture: ${ARCH}"
exit 1
fi
# File extension
if [ PLATFORM == "windows" ]; then
EXT="zip"
else
EXT="tar.gz"
fi
# Download url
BASE_URL="https://github.com/atikahe/auto-test/releases/latest"
BIN_URL="${BASE_URL}/download/auto-test-${PLATFORM}-${ARCH}.${EXT}"
echo BIN_URL
# Start download
echo "Downloading latest binary"
catch curl -L "$BIN_URL" -o "$BIN_DIR/auto-test.${EXT}"
# Extract binary
if [ "$EXT" == "zip" ]; then
unzip "$BIN_DIR/auto-test.${EXT}" -d "$BIN_DIR"
elif [ "$EXT" == "tar.gz" ]; then
tar -xvzf "$BIN_DIR/auto-test.${EXT}" -C "$BIN_DIR"
fi
# Make executable
chmod +x "$BIN_DIR/auto-test"
# Get version
location=$(curl -L -I "$BIN_URL" | grep -i location | awk '{print $2}')
version=$(echo $location | awk -F '/' '{print $NF}')
echo "Installed - ${version}"
}
# If argument fails, print error message and terminate
catch() {
if ! "$@"; then
echo"command failed: $*"
exit 1
fi
}
main "$@" || exit 1