-
Notifications
You must be signed in to change notification settings - Fork 11
/
get-istatserver.sh
190 lines (163 loc) · 5.41 KB
/
get-istatserver.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/sh
set -e
# This script is meant for quick & easy install via:
# $ curl -fsSL https://raw.githubusercontent.com/bjango/istatserverlinux/master/get-istatserver.sh
# $ sh get-istatserver.sh
#
command_exists() {
command -v "$@" > /dev/null 2>&1
}
get_distribution() {
lsb_dist=""
if [ -r /etc/os-release ]; then
lsb_dist="$(. /etc/os-release && echo "$ID")"
else
lsb_dist="$(uname)"
fi
echo "$lsb_dist"
}
get_distribution_like() {
lsb_dist_like=""
if [ -r /etc/os-release ]; then
lsb_dist_like="$(. /etc/os-release && echo "$ID_LIKE")"
fi
echo "$lsb_dist_like"
}
we_did_it() {
if command_exists istatserver && [ -e /usr/local/etc/istatserver/istatserver.conf ]; then
(
set -x
$sh_c 'istatserver -v'
) || true
fi
echo
echo "Perfetto, you got yourself a brand new iStat Server."
echo
echo "You can now run it as a daemon using the following command:"
echo " sudo /usr/local/bin/istatserver -d"
echo
echo "The istatserver config file is located at"
echo " /usr/local/etc/istatserver/istatserver.conf"
echo
echo "iStat View will ask for a passcode the first time you connect."
echo "You can edit this passcode in the istatserver config file."
echo
echo "Here is your current passcode"
grep -w /usr/local/etc/istatserver/istatserver.conf -e server_code | grep -v "#" | sed -e "s/server_code//g" | sed -e 's/[ \t]//g'
echo
echo "Make sure to take a look at the documentation at:"
echo "https://bjango.com/help/istat3/istatserverlinux/"
echo
echo "Learn how to run istatserver at boot:"
echo "https://github.com/bjango/istatserverlinux#starting-istat-server-at-boot"
echo
}
istat_pls() {
echo "# Executing iStat Server for Linux install script"
user="$(id -un 2>/dev/null || true)"
sh_c='sh -c'
if [ "$user" != 'root' ]; then
if command_exists sudo; then
sh_c='sudo -E sh -c'
else
if command_exists su; then
sh_c='su -c'
else
echo "Error: this installer needs the ability to run commands as root."
echo "We are unable to find either 'sudo' or 'su' available to make this happen."
exit 1
fi
fi
fi
# Some platform detection
lsb_dist=$( get_distribution )
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
lsb_dist_like=$( get_distribution_like )
lsb_dist_like="$(echo "$lsb_dist_like" | tr '[:upper:]' '[:lower:]')"
# Check if OS is supported or find what OS it is like and try that instead
case "$lsb_dist" in
ubuntu|debian|raspbian|linuxmint|elementary|centos|fedora|freebsd|dragonfly|netbsd|solus|arch|opensuse|manjaro|slackware|sabayon|gentoo)
;;
*)
case "$lsb_dist_like" in
ubuntu|debian)
lsb_dist="ubuntu";
;;
fedora)
lsb_dist="fedora";
;;
freebsd)
lsb_dist="freebsd";
;;
arch)
lsb_dist="arch";
;;
opensuse)
lsb_dist="opensuse";
;;
esac
esac
# Run setup for each distribution accordingly
echo "Installing required packages"
case "$lsb_dist" in
ubuntu|debian|raspbian|linuxmint|elementary)
$sh_c "apt-get update -qq > /dev/null"
$sh_c "apt-get install -y -qq curl g++ autoconf autogen libxml2-dev libssl-dev libsqlite3-dev libsensors4-dev libavahi-common-dev libavahi-client-dev > /dev/null"
;;
centos|fedora)
if [ -r /bin/dnf ]; then
$sh_c "dnf -q -y install curl autoconf automake gcc-c++ libxml2-devel openssl-devel sqlite-devel lm_sensors lm_sensors-devel avahi-devel > /dev/null"
else
$sh_c "yum -q -y install curl autoconf automake gcc-c++ libxml2-devel openssl-devel sqlite-devel lm_sensors lm_sensors-devel avahi-devel > /dev/null"
fi
;;
freebsd|dragonfly)
$sh_c "env ASSUME_ALWAYS_YES=YES pkg install curl autoconf automake openssl sqlite > /dev/null"
;;
solus)
$sh_c "eopkg install -y -c system.devel > /dev/null"
$sh_c "eopkg install -y curl openssl-devel sqlite3-devel lm_sensors-devel > /dev/null"
;;
opensuse)
$sh_c "zypper install -y gcc-c++ libxml2-devel autoconf automake curl openssl-devel sqlite3-devel > /dev/null"
;;
#openbsd)
# $sh_c "pkg_add -I automake-1.9.6p12 autoconf-2.69p2 > /dev/null"
# ;;
arch|manjaro)
$sh_c "pacman -S --noconfirm automake autoconf openssl sqlite > /dev/null || :"
;;
netbsd)
$sh_c "pkg_add -I automake autoconf > /dev/null || :"
;;
slackware)
$sh_c "slackpkg -batch=on -default_answer=y install automake autoconf gcc-g++ curl lm_sensors > /dev/null || :"
;;
sabayon|gentoo)
$sh_c "emerge --ask=n automake autoconf gcc curl > /dev/null || :"
;;
*)
echo "unsupported OS";
exit 1
;;
esac
if [ -r ./istatserverlinux ]; then
$sh_c "rm -r ./istatserverlinux"
fi
echo "Downloading istatserver"
$sh_c "curl -fsSL https://github.com/bjango/istatserverlinux/archive/master.tar.gz -o istatserverlinux.tar.gz"
echo "Extracting istatserver"
$sh_c "tar -zxf istatserverlinux.tar.gz"
$sh_c "mv istatserverlinux-* istatserverlinux"
echo "Building istatserver"
$sh_c "cd istatserverlinux && ./autogen > /dev/null"
$sh_c "cd istatserverlinux && ./configure > /dev/null"
$sh_c "cd istatserverlinux && make > /dev/null"
$sh_c "cd istatserverlinux && make install > /dev/null"
echo "Cleaning up"
$sh_c "rm -r ./istatserverlinux > /dev/null"
$sh_c "rm ./istatserverlinux.tar.gz > /dev/null"
we_did_it
exit 0
}
istat_pls