-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
executable file
·102 lines (88 loc) · 2.61 KB
/
index.html
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
#!/bin/bash
# Copyright 2019 Akropolis Decentralized Ltd.
# install polkahub cli
VERSION="v0.4.0"
URL="https://github.com/akropolisio/polkahub-cli/releases/download/$VERSION/"
KEY_URL="https://github.com/akropolisio/polkahub-cli/releases/download/$VERSION/"
check_os() {
if [ "$(uname)" = "Linux" ] ; then
PKG="linux" # linux is my default
elif [ "$(uname)" = "Darwin" ] ; then
PKG="darwin"
echo "Running on Apple"
else
echo "Unknown operating system"
echo "Please select your operating system"
echo "Choices:"
echo " linux - any linux distro"
echo " darwin - MacOS"
read PKG
fi
}
check_sha256() {
# how to check for sha256?
SHA256_CHECK=$(which sha256sum 2> /dev/null)
if [[ -z $SHA256_CHECK ]] ; then
# no sha256sum? try with rhash ...
SHA256_CHECK=$(which rhash 2> /dev/null)
SHA256_CHECK="$SHA256_CHECK --sha256"
fi
if [ "$PKG" = "darwin" ] ; then
SHA256_CHECK="shasum -a 256"
fi
# see if we can call the binary to calculate sha256 sums
if ! ($SHA256_CHECK --version &> /dev/null) then
echo "Unable to check SHA256 checksum, please install sha256sum or rhash binary"
cleanup
exit 1
fi
# $SHA256_CHECK $DOWNLOAD_FILE
if [ "$PKG" = "linux" ] ; then
MUST_CHECKSUM=$(curl -SsL $KEY_URL/cs.txt)
IS_CHECKSUM=$($SHA256_CHECK polkahub | awk '{print $1}')
fi
if [ "$PKG" = "darwin" ] ; then
IS_CHECKSUM=$($SHA256_CHECK polkahub_osx | awk '{print $1}')
MUST_CHECKSUM=$(curl -SsL $KEY_URL/cs_osx.txt)
fi
# debug # echo -e "is checksum:\t $IS_CHECKSUM"
# debug # echo -e "must checksum:\t $MUST_CHECKSUM"
if [[ $IS_CHECKSUM != $MUST_CHECKSUM ]]; then
echo "SHA256 Checksum missmatch, aborting installation"
cleanup
exit 1
fi
}
install() {
TMPDIR=$(mktemp -d) && cd $TMPDIR
if [ "$PKG" = "linux" ] ; then
curl -SsLO $URL/polkahub
fi
if [ "$PKG" = "darwin" ] ; then
curl -SsLO $URL/polkahub_osx
fi
check_sha256
echo "Polkahub cli successfully downloaded and checksum verified!"
echo "Installing to the terminal..."
if [ "$PKG" = "linux" ] ; then
sudo cp $TMPDIR/polkahub /usr/bin && sudo chmod +x /usr/bin/polkahub
fi
if [ "$PKG" = "darwin" ] ; then
sudo cp $TMPDIR/polkahub_osx /usr/local/bin/polkahub && sudo chmod +x /usr/local/bin/polkahub
fi
}
cleanup() {
rm $TMPDIR/*
rmdir $TMPDIR
}
## RUN ##
## curl installed?
which curl &> /dev/null
if [[ $? -ne 0 ]] ; then
echo '"curl" binary not found, please install and retry'
exit 1
fi
##
check_os
install
cleanup