forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·175 lines (161 loc) · 4.72 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# Statping installation script for Linux, Mac, and maybe Windows.
#
# This installation script is a modification of Yarn's installation
set -e
reset="\033[0m"
red="\033[31m"
green="\033[32m"
yellow="\033[33m"
cyan="\033[36m"
white="\033[37m"
gpg_key=64B9C6AAE2D55278
gpgurl=https://statping.com/statping.gpg
repo=https://github.com/hunterlong/statping
statping_get_tarball() {
fext='tar.gz'
if [ ${OS} == 'windows' ]; then
fext='zip'
ARCH='x64'
fi
url="$repo/releases/latest/download/statping-$1-$2.$fext"
printf "$cyan> Downloading latest version for $OS $ARCH...\n$url $reset\n"
# Get both the tarball and its GPG signature
tarball_tmp=`mktemp -t statping.tar.gz.XXXXXXXXXX`
if curl --fail -L -o "$tarball_tmp" "$url"; then
# All this dance is because `tar --strip=1` does not work everywhere
temp=$(mktemp -d statping.XXXXXXXXXX)
if [ ${OS} == 'windows' ]; then
unzip $tarball_tmp -d "$temp"
else
tar xzf $tarball_tmp -C "$temp"
fi
statping_verify_integrity "$temp"/statping
printf "$green> Installing to $DEST/statping\n"
mv "$temp"/statping "$DEST"
newversion=`$DEST/statping version`
rm -rf "$temp"
rm $tarball_tmp*
printf "$cyan> Statping is now installed! $reset\n"
printf "$white> Version: $newversion $reset\n"
printf "$white> Repo: $repo $reset\n"
printf "$white> Wiki: $repo/wiki $reset\n"
printf "$white> Issues: $repo/issues $reset\n"
printf "$cyan> Try to run \"statping help\" $reset\n"
else
printf "$red> Failed to download $url.$reset\n"
exit 1;
fi
}
# Verifies the GPG signature of the tarball
statping_verify_integrity() {
# Check if GPG is installed
if [[ -z "$(command -v gpg)" ]]; then
printf "$yellow> WARNING: GPG is not installed, integrity can not be verified!$reset\n"
return
fi
if [ "$statping_GPG" == "no" ]; then
printf "$cyan> WARNING: Skipping GPG integrity check!$reset\n"
return
fi
printf "$cyan> Verifying integrity with gpg key from $gpgurl...$reset\n"
# Grab the public key if it doesn't already exist
gpg --list-keys $gpg_key >/dev/null 2>&1 || (curl -sS -L $gpgurl | gpg --import)
if [ ! -f "$1.asc" ]; then
printf "$red> Could not download GPG signature for this Statping release. This means the release can not be verified!$reset\n"
statping_verify_or_quit "> Do you really want to continue?"
return
fi
# Actually perform the verification
if gpg --verify "$1.asc" $1 &> /dev/null; then
printf "$green> GPG signature looks good$reset\n"
else
printf "$red> GPG signature for this Statping release is invalid! This is BAD and may mean the release has been tampered with. It is strongly recommended that you report this to the Statping developers.$reset\n"
statping_verify_or_quit "> Do you really want to continue?"
fi
}
statping_reset() {
unset -f statping_install statping_reset statping_get_tarball statping_verify_integrity statping_verify_or_quit statping_brew_install getOS getArch
}
statping_brew_install() {
if [[ -z "$(command -v brew --version)" ]]; then
printf "${white}Using Brew to install!$reset\n"
printf "${yellow}---> brew tap hunterlong/statping$reset\n"
brew tap hunterlong/statping
printf "${yellow}---> brew install statping$reset\n"
brew install statping
printf "${green}Brew installation is complete!$reset\n"
printf "${yellow}You can use 'brew upgrade' to upgrade Statping next time.$reset\n"
else
statping_get_tarball $OS $ARCH
fi
}
statping_install() {
printf "${white}Installing Statping!$reset\n"
getOS
getArch
if [ "$OS" == "osx" ]; then
statping_brew_install
else
statping_get_tarball $OS $ARCH
fi
statping_reset
}
statping_verify_or_quit() {
read -p "$1 [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
printf "$red> Aborting$reset\n"
exit 1
fi
}
# get the users operating system
getOS() {
OS="`uname`"
case $OS in
'Linux')
OS='linux'
DEST=/usr/local/bin
alias ls='ls --color=auto'
;;
'FreeBSD')
OS='freebsd'
DEST=/usr/local/bin
alias ls='ls -G'
;;
'WindowsNT')
OS='windows'
DEST=/usr/local/bin
;;
'MINGW*')
OS='windows'
DEST=/usr/local/bin
;;
'CYGWIN*')
OS='windows'
DEST=/usr/local/bin
;;
'Darwin')
OS='osx'
DEST=/usr/local/bin
;;
'SunOS')
OS='solaris'
DEST=/usr/local/bin
;;
'AIX') ;;
*) ;;
esac
}
# get 64x or 32 machine arch
getArch() {
MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
ARCH="x64"
else
ARCH="x32"
fi
}
cd ~
statping_install $1 $2