forked from al-caughey/YAMon-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
164 lines (136 loc) · 4.08 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
#!/bin/sh
##########################################################################
# Yet Another Monitor (YAMon)
# Copyright (c) 2013-present Al Caughey
# All rights reserved.
#
# Script to download, install & setup YAMon3.x
#
# Updated: 2020-01-11 - added L flag to follow symlinks when checking read permissions (about line 95)
# Updated: 2019-10-26 - updated for v4.0
# Updated: 2020-03-19 - change windows linefeeds to unix
##########################################################################
yget(){
local dst="$1"
local src="$2"
#echo "yget: $src --> $dst"
if [ ! -z "$bHasCurl" ] ; then
curl -sk --max-time 15 -o "$dst" --header "Pragma: no-cache" --header "Cache-Control: no-cache" -A YAMon-Setup "$src"
if [ ! -f "$dst" ] ; then
echo " --> download failed?!? with curl... Trying again with wget"
wget "$src" -qO "$dst"
fi
else
#echo "wget $src" -qO "$dst"
wget "$src" -qO "$dst"
if [ ! -f "$dst" ] ; then
echo " --> download $src failed?!? Trying again"
wget "$src" -qO "$dst"
fi
fi
#change windows linefeeds to unix
sed -i -e 's/\r$//' "$dst" #change windows linefeeds to unix
}
[ -x /usr/bin/clear ] && bCanClear=1
[ -x /usr/bin/curl ] && bHasCurl=1
YAMON='/tmp/mnt/sda1/YAMon4/'
directory='current'
[ ! -z "$1" ] && directory="$1"
echo "
**************************************
Welcome to the YAMon installer
For installation tips & tricks, see
https://usage-monitoring.com/install
Please report any issues to
install@usage-monitoring.com
**************************************
"
echo "Would you like to install YAMon on your router?"
tries=0
readstr="Either
- hit <enter> or \`y\` for yes, or \`n\` for no: "
while true; do
read -p "$readstr" resp
if [ -z "$resp" ] || [ "$resp" == 'y' ] || [ "$resp" == 'Y' ] ; then
break
elif [ "$resp" == 'n' ] || [ "$resp" == 'N' ] ; then
echo "
*** Cancelling installation... Hopefully you'll try again!
Please send questions to install@usage-monitoring.com.
"
exit 0
else
readstr="
Only \`y\` or \`n\` are permitted!
Please try again: "
fi
done
baseurl='https://usage-monitoring.com'
echo "
Please specify the fully qualified path to your
installation directory - e.g., \`$YAMON\`.
"
tries=0
readstr=" Either
- hit <enter> to accept \`$YAMON\`, or
- type your preferred installation location: "
while true; do
read -p "$readstr" resp
resp="${resp:-$YAMON}"
YAMON="${resp%%/}/" # ensure the path ends with a single /
#echo "YAMON: $YAMON"
p2c=$(dirname "$YAMON")
[ -z "${p2c%/}" ] && p2c="$YAMON"
#echo "$p2c: $(ls -laL "$p2c" | grep ' .$' | awk '{print $1}')"
if [ -z "$(ls -laL "$p2c" | grep ' .$' | awk '{print $1}' | grep 'w')" ] ; then
echo -e "\n *** Un-oh... You do not have write permissions in '$p2c'!\n"
elif [ -d "$YAMON" ] ; then
break
else
mkdir -p "$YAMON"
[ -d "$YAMON" ] && break
echo -e "\n *** The installation directory could not be created?!?\n"
fi
readstr=" Please try again: "
tries=$(($tries + 1))
if [ "$tries" -eq "3" ] ; then
echo -e "\n\n*** Hmmm... three tries and still not working...\nPlease check the installation requirements and try again.\nSend screenshots, etc. to questions@usage-monitoring.com."
exit 0
fi
done
echo "
**************************************
Installing YAMon...
"
umversion="/tmp/yamonsetup.txt"
yget "$umversion" "$baseurl/$directory/YAMon4/Setup/gfmd4.0.php"
if [ ! -f "$umversion" ] ; then
echo "
Installation Failed!... \`$umversion\` was not created...
the router likely does not have internet access.
Please check your settings and try again.
"
exit 0
fi
rm $umversion
chmod +x "$YAMON"
[ -d "${YAMON}data" ] && chmod -R 666 "${YAMON}data"
sleep 1
# echo "BREAKPOINT 10"
_enableLogging=1
_log2file=1
_loglevel=0
[ ! -d "${YAMON}includes" ] && mkdir -p "${YAMON}includes"
getlatest="${YAMON}includes/getlatest.sh"
_ts=$(date +"%s")
# yget "$getlatest" "$baseurl/$directory/YAMon4/Setup/includes/getlatest.sh?$_ts"
source "$getlatest"
param='verify'
chmod +x "${YAMON}compare.sh"
source "${YAMON}compare.sh"
sleep 5
echo "
Running setup...
"
[ ! -z "$bCanClear" ] && clear
source "${YAMON}setup.sh"