-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller.sh
executable file
·80 lines (66 loc) · 2.19 KB
/
installer.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
#!/bin/sh
############################################################################################
# Installer for entry_point, always will download the latest version #
############################################################################################
set -e
get_arch() {
arch=$(uname -m)
case $arch in
x86_64) arch="amd64" ;;
x86) arch="386" ;;
esac
echo ${arch}
}
download_url() {
api_url=$1
url_for=$2
wget -q -O- ${api_url} | grep browser_download_url | grep ${url_for} | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -n 1 | awk '{print $2}' | tr -d '"' | tr -d ','
}
get_filename() {
api_url=$1
url_for=$2
wget -q -O- ${api_url} | grep name | grep ${url_for} | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -n 1 | awk '{print $2}' | tr -d '"' | tr -d ','
}
release_version() {
api_url=$1
wget -q -O- ${api_url} | grep tag_name | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -n 1 | awk '{print $2}' | tr -d '"' | tr -d ','
}
check_sha() {
org=$1
expected=$2
current=$(sha256sum $1 | cut -d ' ' -f 1)
if [ "$expected" != "$current" ]; then
echo "failed sha256sum for '$org', ${expected} vs ${current} don't match"
return 1
fi
}
BINARY=entry_point
REPO=docker_entrypoint
FORMAT=tar.gz
BINDIR=/
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(get_arch)
API_URL=https://api.github.com/repos/Vauxoo/${REPO}/releases
URL=$(download_url ${API_URL} ${OS}_${ARCH})
CHECKSUMS=$(download_url ${API_URL} checksums.txt)
TEMP=$(mktemp -d)
SUMSLOCAL=${TEMP}/checksums.txt
TAG=$(release_version ${API_URL})
FULLNAME=$(get_filename ${API_URL} ${OS}_${ARCH})
download() {
url=$1
dest=$2
wget -q -O ${dest} "${url}"
}
echo "Version ${TAG} will be installed"
echo "Downloading binaries..."
download ${URL} ${TEMP}/${FULLNAME}
download ${CHECKSUMS} ${SUMSLOCAL}
# Check sha256 sum
echo "Cheking sha of the file"
sha=$(grep "${FULLNAME}" "${SUMSLOCAL}" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f 1)
check_sha ${TEMP}/${FULLNAME} $sha
echo "Decompressing and installing"
(cd "${TEMP}" && tar --no-same-owner -xzf "${FULLNAME}" && mv ${BINARY} ${BINDIR})
rm -r ${TEMP}
echo "Done"