-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
69 lines (58 loc) · 1.52 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
#!/usr/bin/env bash
set -euo pipefail
function usage() {
echo "Usage: bash install.sh [ -d directory ] [ -v version ]"
exit 2
}
INSTALL_DIR="${HOME}/bin"
VERSION=""
NAME=lingualeo
OS=$(uname -o | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
OS="${OS##*/}"
case "${ARCH}" in
x86_64) ARCH="amd64" ;;
arm) ARCH="arm64" ;;
esac
if which go &>/dev/null; then
gobin=$(go env GOBIN)
gopath="$(go env GOPATH)"
gopathbin="${gopath}/bin"
if [ -n "${gobin}" ] && [ -d "${gobin}" ]; then
INSTALL_DIR="${gobin}"
elif [ -n "${gopath}" ] && [ -d "${gopathbin}" ]; then
INSTALL_DIR="${gopathbin}"
fi
fi
while getopts hv:d: flag; do
case "${flag}" in
d) INSTALL_DIR=${OPTARG} ;;
v) VERSION=${OPTARG} ;;
h) usage ;;
*) usage ;;
esac
done
if [ ! -d "${INSTALL_DIR}" ]; then
echo "Directory ${INSTALL_DIR} does not exist"
exit 1
fi
if [ ! -w "${INSTALL_DIR}" ]; then
echo "Directory ${INSTALL_DIR} is not writable"
exit 1
fi
APP_PATH="${INSTALL_DIR}/${NAME}"
echo "Installing into ${APP_PATH}..."
if [ -z "${VERSION}" ]; then
VERSION=$(
curl -sSL --fail-with-body https://api.github.com/repos/trezorg/${NAME}/releases/latest | \
awk -F ':' '/tag_name/ { gsub("[\", ]", "", $2); print $2 }'
)
fi
DOWNLOAD_URL="https://github.com/trezorg/${NAME}/releases/download/${VERSION}/${NAME}-${OS}-${ARCH}"
if ! curl -sSL --fail-with-body "${DOWNLOAD_URL}" -o "${APP_PATH}"; then
err=$?
echo "Failed to download ${DOWNLOAD_URL} into ${APP_PATH}"
exit ${err}
fi
chmod +x "${APP_PATH}"
"${NAME}" --help