generated from cloud-native-toolkit/template-typescript-library
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinstall.sh
executable file
·97 lines (81 loc) · 3.28 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
#!/usr/bin/env sh
DEST_DIR="${1:-$DEST_DIR}"
RELEASE="${2:-$RELEASE}"
TMP_DIR="/tmp"
if [ -z "${DEST_DIR}" ]; then
DEST_DIR="/usr/local/bin"
fi
if ! command -v curl 1> /dev/null 2> /dev/null; then
echo "curl cli not found" >&2
exit 1
fi
if [ "${RELEASE}" = "beta" ]; then
if ! command -v jq 1> /dev/null 2> /dev/null; then
echo "jq cli not found. It is required to get the latest beta release" >&2
exit 1
fi
RELEASE=$(curl -sL "https://api.github.com/repos/cloud-native-toolkit/iascable/releases" | jq -r 'map(select(.prerelease)) | first | .tag_name // empty')
if [ -z "${RELEASE}" ]; then
echo "Unable to find beta release" >&2
exit 1
fi
elif [ -z "${RELEASE}" ]; then
RELEASE=$(curl -sL "https://api.github.com/repos/cloud-native-toolkit/iascable/releases/latest" | grep tag_name | sed 's/"tag_name"//g' | sed 's/ //g' | sed 's/://g' | sed 's/,//g' | sed 's/"//g')
fi
TYPE="linux"
OS=$(uname)
if [ "$OS" = "Linux" ]; then
TYPE=$(cat /etc/os-release | grep -E "^ID=" | sed "s/ID=//g")
if [ "${TYPE}" != "alpine" ]; then
TYPE="linux"
fi
elif [ "$OS" = "Darwin" ]; then
TYPE="macos"
else
echo "OS not supported"
exit 1
fi
ARCH=""
case $(uname -m) in
i386) ARCH="" ;;
i686) ARCH="" ;;
x86_64) ARCH="" ;;
aarch64) ARCH="-arm64" ;;
arm64) ARCH="-arm64" ;;
*) echo "Unable to determine system architecture" >&2; exit 1 ;;
esac
# If an Apple M1 Mac, use AMD64 architecture with Rosetta
if [[ "${TYPE}" == "macos" ]] && [[ "${ARCH}" == "-arm64" ]]; then
# Check that Rosetta is installed before continuing (Rosetta is known as oah by macos)
if [[ ! $(/usr/bin/pgrep oahd) ]]; then
echo "Rosetta must be installed. Please install and try again."
exit 2;
fi
# Create temporary directory if it does nto exist
if [[ ! -d "${TMP_DIR}" ]]; then
mkdir -p "${TMP_DIR}"
fi
# Download the binary to a temporary directory (/tmp by default)
echo "Downloading ${RELEASE} of iascable for ${TYPE} into ${TMP_DIR}"
curl --progress-bar -Lo "${TMP_DIR}/iascable-${RELEASE}" "https://github.com/cloud-native-toolkit/iascable/releases/download/${RELEASE}/iascable-${TYPE}"
chmod +x "${TMP_DIR}/iascable-${RELEASE}"
# Check if there is an existing version of iascable installed.
if [[ -h "${DEST_DIR}/iascable" ]]; then # Link file
# Remove link file
echo "Detected existing linked file ${DEST_DIR}/iascable"
rm "${DEST_DIR}/iascable"
elif [[ -x "${DEST_DIR}/iascable" ]]; then
# Get current version number
VERSION=$($DEST_DIR/iascable --version)
echo "Detected existing executable with version ${VERSION}"
# Copy existing binary to copy with current release
mv "${DEST_DIR}/iascable" "${DEST_DIR}/iascable-${VERSION}"
fi
# Move binary to destination directory and create link
echo "Moving ${TMP_DIR}/iascable-${RELEASE} to ${DEST_DIR} and creating symbolic link"
mv "${TMP_DIR}/iascable-${RELEASE}" "${DEST_DIR}/iascable-${RELEASE}"
ln -s "${DEST_DIR}/iascable-${RELEASE}" "${DEST_DIR}/iascable"
else # Non-Mac M1
echo "Installing version ${RELEASE} of iascable for ${TYPE}${ARCH} into ${DEST_DIR}"
curl --progress-bar -Lo "${DEST_DIR}/iascable" "https://github.com/cloud-native-toolkit/iascable/releases/download/${RELEASE}/iascable-${TYPE}${ARCH}" && chmod +x "${DEST_DIR}/iascable"
fi