-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathinstall.sh
executable file
·145 lines (125 loc) · 3.67 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
set -euo pipefail
function run() {
declare TALISMAN_BINARY_NAME
E_UNSUPPORTED_ARCH=5
DEBUG=${DEBUG:-''}
VERSION=${VERSION:-'latest'}
INSTALL_ORG_REPO=${INSTALL_ORG_REPO:-'thoughtworks/talisman'}
INSTALL_LOCATION=${INSTALL_LOCATION:-'/usr/local/bin'}
TEMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'talisman_setup')
# shellcheck disable=SC2064
trap "rm -r $TEMP_DIR" EXIT
chmod 0700 "$TEMP_DIR"
function echo_error() {
echo -ne "$(tput setaf 1)" >&2
echo "$1" >&2
echo -ne "$(tput sgr0)" >&2
}
function echo_debug() {
[[ -z "$DEBUG" ]] && return
echo -ne "$(tput setaf 3)" >&2
echo "$1" >&2
echo -ne "$(tput sgr0)" >&2
}
function echo_success() {
echo -ne "$(tput setaf 2)"
echo "$1" >&2
echo -ne "$(tput sgr0)"
}
function operating_system() {
OS=$(uname -s)
case $OS in
"Linux")
echo "linux"
;;
"Darwin")
echo "darwin"
;;
MINGW32_NT-*)
echo "windows"
;;
MINGW64_NT-*)
echo "windows"
;;
MSYS_NT-*)
echo "windows"
;;
*)
echo_error "Talisman currently only supports Windows, Linux and MacOS(darwin) systems."
echo_error "If this is a problem for you, please open an issue: https://github.com/$INSTALL_ORG_REPO/issues/new"
exit $E_UNSUPPORTED_ARCH
;;
esac
}
function set_talisman_binary_name() {
# based on OS (linux/darwin) and ARCH(32/64 bit)
declare SUFFIX
SUFFIX=$(operating_system)
ARCH=$(uname -m)
case $ARCH in
"x86_64")
SUFFIX="${SUFFIX}_amd64"
;;
"i686" | "i386")
SUFFIX="${SUFFIX}_386"
;;
"arm64" | "aarch64")
SUFFIX="${SUFFIX}_arm64"
;;
*)
echo_error "Talisman currently only supports x86 and x86_64 and arm64 architectures."
echo_error "If this is a problem for you, please open an issue: https://github.com/$INSTALL_ORG_REPO/issues/new"
exit $E_UNSUPPORTED_ARCH
;;
esac
TALISMAN_BINARY_NAME="talisman_$SUFFIX"
if [[ $SUFFIX == *"windows"* ]]; then
TALISMAN_BINARY_NAME="$TALISMAN_BINARY_NAME.exe"
fi
}
function download() {
OBJECT=$1
DOWNLOAD_URL=$(curl -Ls https://api.github.com/repos/"$INSTALL_ORG_REPO"/releases/latest |
grep download_url | awk '{print $2}' | tr -d '"' | grep "$OBJECT")
echo_debug "Downloading $OBJECT from $DOWNLOAD_URL"
curl --location --silent "$DOWNLOAD_URL" >"$TEMP_DIR/$OBJECT"
}
function verify_checksum() {
FILE_NAME=$1
CHECKSUM_FILE_NAME='checksums'
echo_debug "Verifying checksum for $FILE_NAME"
download $CHECKSUM_FILE_NAME
pushd "$TEMP_DIR" >/dev/null 2>&1
grep "$TALISMAN_BINARY_NAME" $CHECKSUM_FILE_NAME >$CHECKSUM_FILE_NAME.single
if ! command -v shasum &> /dev/null; then
sha256sum -c $CHECKSUM_FILE_NAME.single
else
shasum -a 256 -c $CHECKSUM_FILE_NAME.single
fi
popd >/dev/null 2>&1
echo_debug "Checksum verification successfully!"
echo
}
function download_talisman_binary() {
download "$TALISMAN_BINARY_NAME"
verify_checksum "$TALISMAN_BINARY_NAME"
}
function setup_talisman() {
if (touch "$INSTALL_LOCATION/talisman" &>/dev/null); then
cp "$TEMP_DIR/$TALISMAN_BINARY_NAME" "$INSTALL_LOCATION/talisman"
chmod +x "$INSTALL_LOCATION/talisman"
elif (which sudo &>/dev/null); then
sudo cp "$TEMP_DIR/$TALISMAN_BINARY_NAME" "$INSTALL_LOCATION/talisman"
sudo chmod +x "$INSTALL_LOCATION/talisman"
else
echo_error "Insufficient permission to install to $INSTALL_LOCATION"
exit 126
fi
}
set_talisman_binary_name
echo_success "Downloading talisman binary"
download_talisman_binary
setup_talisman
}
run