forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·147 lines (138 loc) · 3.54 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
#!/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/statping/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
printf "$green> Installing to $DEST/statping\n"
mv "$temp"/statping "$DEST"
rm -rf "$temp"
rm $tarball_tmp*
printf "$cyan> Statping is now installed! $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
}
statping_reset() {
unset -f statping_install statping_reset statping_get_tarball 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 statping/statping$reset\n"
brew tap statping/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
statping_get_tarball $OS $ARCH
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'
;;
'OpenBSD')
OS='openbsd'
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='darwin'
DEST=/usr/local/bin
;;
'SunOS')
OS='linux'
DEST=/usr/local/bin
;;
'AIX') ;;
*) ;;
esac
}
# get 64x or 32 machine arch
getArch() {
MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
ARCH="amd64"
elif [ ${MACHINE_TYPE} == 'arm' ]; then
ARCH="arm"
elif [ ${MACHINE_TYPE} == 'arm64' ]; then
ARCH="arm64"
elif [ ${MACHINE_TYPE} == 'aarch64' ]; then
ARCH="arm64"
else
ARCH="386"
fi
}
cd ~
statping_install $1 $2