-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup3.4.7.sh
860 lines (765 loc) · 30.9 KB
/
setup3.4.7.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
#!/bin/sh
##########################################################################
# Yet Another Monitor (YAMon)
# Copyright (c) 2013-2020 Al Caughey
# Copyright (c) 2023-present Mo'men Mamdouh
# All rights reserved.
#
# Script to help set baseline values in config.file for YAMon3.x
#
##########################################################################
#HISTORY
# 3.4.0 (2018-02-04): added advanced vs basic mode; added prompt for bridge
# 3.4.1 (2018-02-19): updated a lot of the regexes for prompts
# 3.4.2 (2018-02-23): updated with fixes suggested by Jeff Page; added Padavan as a firmware variant
# 3.4.3 (2018-02-26): added optional 6th topic parameter for `prompt`
# 3.4.4 (2018-03-12): re-added a prompt for _path2ip
# 3.4.6 (2019-01-21): no changes... version number updated for consistency
# 3.4.7 (2019-01-31): updated prompts; added better checking for IPv6
d_baseDir="${YAMON%/}"
[ -z "$d_baseDir" ] && d_baseDir=$(cd "$(dirname "$0")" && pwd)
[ -z "$directory" ] && delay=$1
[ -z "$delay" ] && delay=5
[ -z "$send2log" ] && send2log='send2log'
source "${d_baseDir}/includes/versions.sh"
source "${d_baseDir}/includes/util$_version.sh"
if [ ! -f "${d_baseDir}/config.file" ] && [ ! -f "${d_baseDir}/default_config.file" ] ; then
$send2log '*** Cannot find either config.file or default_config.file...' 2
echo '*** Cannot find either config.file or default_config.file...
*** Please check your installation! ***
*** Exiting the script. ***'
exit 0
elif [ -f "${d_baseDir}/config.file" ] ; then
_configFile="${d_baseDir}/config.file"
else
_configFile="${d_baseDir}/default_config.file"
fi
configStr=$(cat "$_configFile")
source "$_configFile"
source "${d_baseDir}/includes/defaults.sh"
source "${d_baseDir}/strings/en/strings.sh"
[ -z "$_enableLogging" ] && _enableLogging=1
[ -z "$_log2file" ] && _log2file=1
[ -z "$_loglevel" ] && _loglevel=0
[ -n "$_canClear" ] && clear
echo "$_s_title"
echo "
$los
This script will guide you through the process of setting up the
basic parameters in your \`config.file\` for YAMon$_version.
See http://usage-monitoring.com/download.php for more detailed
instructions regarding the setup process.
NB - a number of the advanced (aka less commonly used) settings
are not currently addressed in this script.
If you want to use any of those features, you can edit your
\`config.file\` directly (often without actually having to stop
& restart the main YAMon script).
$los
"
sleep $delay
_logDir='logs/'
_logfilename="${d_baseDir}/${_logDir}setup$_version.log"
echo "This script will create a log of the selections you make in the
upcoming prompts. The file name & path is:
\`$_logfilename\`
If you encounter any issues during the setup process, please send your
log and as much additional info to [email protected].
"
sleep $delay
[ -n "$_canClear" ] && clear
[ ! -d "${d_baseDir}/$_logDir" ] && mkdir -p "${d_baseDir}/$_logDir"
[ ! -f "$_logfilename" ] && touch "$_logfilename"
ds=$(date +"%Y-%m-%d %H:%M:%S")
$send2log "
********************************************************
$ds --> Launched setup.sh - v$_version" 1
echo "
You are running this script from \`$d_baseDir\`
with baseline settings from \`$_configFile\`"
$send2log "Baseline settings: \`$_configFile\`" 1
dd_str='DD-WRT'
op_str='OpenWrt'
le_str='LEDE'
tu_str='Turris'
am_str='ASUSWRT-Merlin'
_firmware=0
if [ -f "/etc/openwrt_release" ] ; then
distro=$(cat /etc/openwrt_release | grep -i 'DISTRIB_ID' | cut -d"'" -f2)
installedfirmware=$(cat /etc/openwrt_release | grep -i 'DISTRIB_DESCRIPTION' | cut -d"'" -f2)
installedversion=''
installedtype=''
if [ "$distro" == "$le_str" ] ; then
le_str='LEDE (*)'
_firmware=4
else
tu_str='Turris (*)'
_firmware=6
fi
elif [ "$_has_nvram" == "1" ] ; then
installedfirmware=$(uname -o)
if [ "$installedfirmware" == "$dd_str" ] ; then
_firmware=0
dd_str='DD-WRT (*)'
elif [ "$installedfirmware" == "$op_str" ] ; then
op_str='OpenWrt (*)'
_firmware=1
elif [ "$installedfirmware" == "$am_str" ] ; then
am_str='ASUSWRT-Merlin (*)'
_firmware=2
fi
if [ $_firmware == 2 ] ; then
routermodel=$(nvram get model)
installedversion=$(nvram get buildno)_$(nvram get extendno)
installedtype='merlin'
else
routermodel=$(nvram get DD_BOARD)
installedversion=$(nvram get os_version)
installedtype=$(nvram get dist_type)
fi
fi
if [ -d /tmp/sysinfo/ ] ; then
model=$(cat /tmp/sysinfo/model)
board=$(cat /tmp/sysinfo/board_name)
routermodel="$model $board"
fi
yn_y="Options:
\`0\` / \`n\` -> No
\`1\` / \`y\` -> Yes (*)"
yn_y2="Options:
\`0\` / \`n\` -> No
\`1\` / \`y\` -> Yes (*)
\`2\` / \`s\` -> Yes, install as a service"
yn_n="Options
\`0\` / \`n\` -> No (*)
\`1\` / \`y\` -> Yes"
zo_r=^[01nNyY]$
zo_r2=^[012nNyYSs]$
zot_r=^[012]$
_qn=0
re_path=^.*$
re_path_slash=^.*/$
echo "
Router Model: $routermodel"
echo "Installed firmware: $installedfirmware $installedversion $installedtype"
$send2log "Router Model: $routermodel" 1
$send2log "Installed firmware: $installedfirmware $installedversion $installedtype" 1
routerfile="${d_baseDir}/www/js/router.js"
if [ -f "$routerfile" ] ; then
installed=$(cat "$routerfile" | grep install | cut -d"'" -f2)
updated=$(date +"%Y-%m-%d %H:%M:%S")
else
installed=$(date +"%Y-%m-%d %H:%M:%S")
updated=''
fi
echo "var installed='$installed'
var updated='$updated'
var router='$routermodel'
var firmware='$installedfirmware $installedversion $installedtype'
var version='$_version'" > $routerfile
sleep $delay
echo "
In the upcoming prompts, the recommended/default value will be
denoted with an asterisk (*). To accept the default, simply
hit <enter>. Otherwise, type your preferred value & then hit <enter>.
NB - If you are updating from a previous version of YAMon, back up
everything before proceeding! This includes any customizations
you've made to devices in the reports - see
http://usage-monitoring.com/help/?t=export-users
If you have any questions about the installation process, see
http://usage-monitoring.com/help/?c=Install
"
t_installmode='b'
prompt 't_installmode' "Do you want run setup in Basic(*) or Advanced mode?" "Options:
\`b\` -> Basic mode: fewer prompts; most default settings will be selected (*)
\`a\` -> Advanced mode: more prompts to better tailor your settings" "$t_installmode" "^[aAbB]$" 'running-setup'
$send2log "Install mode: $t_installmode" 1
echo "
NB - You can always fine-tune your settings by manually editing
\`config.file\` (in \`${d_baseDir}/config.file\`)."
[ "$_webDir" == "Setup/www/" ] && updateConfig "_webDir" "www/"
[ "$_webIndex" == "yamon2.html" ] && updateConfig "_webIndex" "index.html"
[ "$_webIndex" == "yamon3.html" ] && updateConfig "_webIndex" "index.html"
[ "$_webIndex" == "yamon3.1.html" ] && updateConfig "_webIndex" "index.html"
[ "$_webIndex" == "yamon3.2.html" ] && updateConfig "_webIndex" "index.html"
[ "$_wwwData" == "data/" ] || [ "$_wwwData" == "data" ] && updateConfig "_wwwData" "data3/"
[ "$_configWWW" == "config.js" ] && updateConfig "_configWWW" "config$_file_version.js"
[ "$_configWWW" == "config3.js" ] && updateConfig "_configWWW" "config$_file_version.js"
[ "$_liveFileName" == "live_data.js" ] && updateConfig "_liveFileName" "live_data3.js"
configStr=$(echo "$configStr" | sed -re "s~_configWWW='([^']{1,})'~_configWWW=\"\1\"~")
if [ -n "$(echo "$configStr" | grep -e "^_setupWebDir")" ] ; then
$send2log "Renamed _setupWebDir to _webDir" 1
configStr="${configStr/_setupWebDir/_webDir}"
fi
if [ -n "$(echo "$configStr" | grep -e "^_setupWebIndex")" ] ; then
$send2log "Renamed _setupWebIndex to _webIndex" 1
configStr="${configStr/_setupWebIndex/_webIndex}"
fi
prompt '_firmware' 'Which firmware variant is running on your router?' "Options:
\`0\` -> $dd_str
\`1\` -> $op_str
\`2\` -> $am_str
\`3\` -> Tomato
\`4\` -> $le_str
\`5\` -> Xwrt-Vortex
\`6\` -> $tu_str
\`7\` -> Padavan" $_firmware ^[0-7]$
if [ "$_firmware" == "0" ] ; then
flags="{"
lan_proto=$(nvram get lan_proto)
$send2log "lan_proto --> $lan_proto" 1
[ ! "$lan_proto" == "dhcp" ] && echo "
$wrn
$bl_a
## It appears that your router is not the DHCP Server for
## your network.
## YAMon gets its data via \`iptables\` calls. They only
## return meaningful data from the DHCP Server.
$bl_a
## You must enable this feature on this router if you want to use YAMon!
$bl_a
## DD-WRT web GUI: \`Setup\`-->\`Basic Setup\` -->\`Network Address Server Settings (DHCP)\`
$bl_a
$loh" && sleep 5
sfe_enable=$(nvram get sfe)
$send2log "sfe_enable --> $sfe_enable" 1
[ "$sfe_enable" == "1" ] && echo "
$wrn
$bl_a
## The \`Shortcut Forwarding Engine\` is enabled in your DD-WRT config.
## SFE alters the normal flow of packets through \`iptables\` and that
## prevents YAMon from accurately reporting the traffic on
## your router.
$bl_a
## YAMon will not report properly if you do not disable this feature!
$bl_a
## DD-WRT web GUI: \`Setup\`-->\`Basic Setup\` -->\`Optional Settings\`
$bl_a
$loh" && sleep 5
upnp_enable=$(nvram get upnp_enable)
$send2log "upnp_enable --> $upnp_enable" 1
[ "$upnp_enable" == "1" ] && echo "
$wrn
$bl_a
## \`UPnP\` is enabled in your DD-WRT config.
## UPnP alters the normal flow of packets through \`iptables\` and that
## will likely prevent YAMon from accurately reporting the traffic on
## your router.
$bl_a
## It is recommended that you disable this feature!
$bl_a
## DD-WRT web GUI: \`NAT / QoS\`-->\`UPnP\` -->\`UPnP Configuration\`
$bl_a
$loh" && sleep 5
privoxy_enable=$(nvram get privoxy_enable)
$send2log "privoxy_enable --> $privoxy_enable" 1
[ "$privoxy_enable" == "1" ] && echo "
$wrn
$bl_a
## \`Privoxy\` is enabled in your DD-WRT config.
## Privoxy alters the normal flow of packets through \`iptables\` and
## that *will* prevent YAMon from accurately reporting the traffic
## on your router.
$bl_a
## YAMon will not report properly if you do not disable this feature!
$bl_a
## DD-WRT web GUI: \`Services\`-->\`Adblocking\`-->\`Privoxy\`
$bl_a
$loh" && sleep 5
ntp_enable=$(nvram get ntp_enable)
$send2log "ntp_enable --> $ntp_enable" 1
[ ! "$ntp_enable" == "1" ] && echo "
$wrn
$bl_a
## \`NTP Client\` is *not* enabled in your DD-WRT config.
## The NTP Client allows you to set your time zone and synchronize
## the clock on your router.
$bl_a
## YAMon will likely not provide accurate reports if you do not
## enabled this feature!
$bl_a
## DD-WRT web GUI: \`Setup\`-->\`Basic Setup\`-->\`Time Settings\`
$bl_a
$loh" && sleep 5
schedule_enable=$(nvram get schedule_enable)
schedule_hours=$(nvram get schedule_hours)
schedule_minutes=$(nvram get schedule_minutes)
schedule_reboot=0
$send2log "schedule_enable --> $schedule_enable ($schedule_hours:$schedule_minutes)" 1
[ "$schedule_enable" == "1" ] && [ "$schedule_hours" == "0" ] && [ "$schedule_minutes" -lt "10" ] && echo "
$wrn
$bl_a
## Your router is scheduled to auto-reboot at '$schedule_hours:$schedule_minutes'.
## This may interfere with the YAMon function that consolidates
## the daily totals into the monthly usage file.
$bl_a
## If you must auto-reboot your router, please do so after ~12:15AM!
$bl_a
## DD-WRT web GUI: \`Administration\`-->\`Keep Alive\`-->\`Schedule Reboot\`
$bl_a
$loh" && schedule_reboot=1 && sleep 5
flags="{lan_proto:$lan_proto, sfe_enable:$sfe_enable upnp_enable:$upnp_enable, privoxy_enable:$privoxy_enable, ntp_enable:$ntp_enable, schedule_reboot:$schedule_reboot}"
fi
prompt '_ispBillingDay' 'What is your ISP bill roll-over date?
(i.e., on what day of the month does your usage reset to zero)' 'Enter the day number [1-31]:' '' "^([1-9]|[12][0-9]|[3][01])$"
prompt '_monthlyDataCap' 'Does your plan with your ISP have a data usage cap?' "Options:
\`0\` -> No, I have an unlimited data plan (*)
\`##\` -> Otherwise, enter your data cap in GB [1-9999]" '0' "^[0-9]{1,4}$"
prompt '_unlimited_usage' 'Does your ISP offer `Bonus Data`?
(i.e., uncapped data usage during offpeak hours)' "$yn_n" '0' $zo_r
if [ "$_unlimited_usage" == "1" ] ; then
prompt '_unlimited_start' 'Start time for bonus data?' 'Enter the time in [hh:mm] 24hr format' '' "^(00|[1-9]|1[0-9]|2[0-3]):[0-5][0-9]$" '_unlimited_usage'
prompt '_unlimited_end' 'End time?' 'Enter the time in [hh:mm] 24hr format' '' "^(00|[1-9]|1[0-9]|2[0-3]):[0-5][0-9]$" '_unlimited_usage'
fi
if [ "$t_installmode" == 'b' ] ; then
[ "$_firmware" == "2" ] || [ "$_firmware" == "3" ] || [ "$_firmware" == "5" ] && updateConfig "_wwwPath" '/tmp/var/wwwext/'
if [ "$_firmware" == "1" ] || [ "$_firmware" == "4" ] || [ "$_firmware" == "6" ] || [ "$_firmware" == "7" ] ; then
lan_ip=$(uci get network.lan.ipaddr)
[ -z "$lan_ip" ] && lan_ip=$(ifconfig br-lan | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
updateConfig "_wwwURL" '/yamon'
else
lan_ip=$(nvram get lan_ipaddr)
fi
_dataPath="${d_baseDir}/$_dataDir"
else
prompt '_includeBridge' 'Do you have a bridge on your network?
(i.e., a second router or other device to extend the wireless range)' "$yn_n" '0' $zo_r
if [ "$_includeBridge" == "1" ] ; then
prompt '_bridgeMAC' "What is the MAC address for your bridge device?
See the help topic if you have multiple bridging devices" "Enter a valid MAC address - e.g., 11:22:33:44:55:66" '' "^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$" '_includeBridge'
fi
t_wid=1
prompt 't_wid' "Do you want to store your data in the default directory?
- i.e., \`$d_baseDir/data\`" "$yn_y" $t_wid $zo_r
[ "$t_wid" == "0" ] && prompt '_dataDir' "Enter the path to your data directory" "Options:
* a relative path within the install folder - e.g., data/ (*)
* an absolute path elsewhere on your network - e.g, /<path>/" "data/" $re_path_slash
prompt '_updatefreq' 'How frequently would you like to check the data?' 'Enter the interval in seconds [1-300 sec]' '30' "^([1-9]|[1-9][0-9]|[1-2][0-9][0-9]|300)$"
prompt '_publishInterval' 'How many checks between updates in the reports?' 'Enter the number of checks [must be a positive integer 1-99]' '2' "^([1-9]|[1-9][0-9])$"
ipv6_enable=1
[ "$_firmware" == "0" ] && ipv6_enable=$(nvram get ipv6_enable)
#todo - detect whether IPv6 is enabled in other firmware variants --> from uci?
[ -z "$ipv6_enable" ] && ipv6_enable=0
wre="$yn_y"
[ "$ipv6_enable" -ne "1" ] && wre="$yn_n"
prompt '_includeIPv6' "Do you want to include IPv6 traffic in the reports?
If yes, your firmware *must* include a full version of \`ip\` but some do not!" "$wre" "$ipv6_enable" $zo_r
if [ "$_includeIPv6" -eq "1" ] ; then
p2ip=$(which ip)
$($p2ip -6 neigh show >> /tmp/ipv6.text 2>&1)
if [ $? -ne 0 ] ; then
$send2log "p2ip --> $p2ip (neigh not supported)" 1
echo "
*******************************************************
* Your default path to the ip function (\`$p2ip\`) does not support
* the \`neigh\` option!
*******************************************************
"
t_ip=0
prompt 't_ip' "Have you manually installed a full version of \`ip\` elsewhere on your router?" "$yn_n" "$t_ip" $zo_r
if [ "$t_ip" == "1" ] ; then
prompt '_path2ip' 'What is the path to your alternate version of `ip`?' "The path must start with a \`/\`" '/opt/sbin/ip' $re_path '_path2ip'
if [ ! -f "$_path2ip" ] ; then
send2log "path to full ip \`$_path2ip\` is not correct" 2
updateConfig "_path2ip" ""
updateConfig "_includeIPv6" "0"
echo "
*******************************************************
* \`$_path2ip\` does not exist... you must fix this before
* you will see IPv6 traffic in your reports!
* the IPv6 option will be disabled.
*******************************************************
"
else
$($_path2ip -6 neigh show >> /tmp/ipv6.text 2>&1)
if [ $? -ne 0 ] ; then
echo "
*******************************************************
* That version of ip (\`$_path2ip\`) also does not support
* the \`neigh\` option... the IPv6 option will be disabled.
*******************************************************
"
updateConfig "_includeIPv6" "0"
fi
fi
else
echo "
*******************************************************
* OK... the IPv6 option will be disabled.
*******************************************************
"
updateConfig "_includeIPv6" "0"
fi
else
$send2log "p2ip --> $p2ip (neigh works)" 1
fi
rm /tmp/ipv6.text
fi
$send2log "_includeIPv6 --> $_includeIPv6" 1
if [ "$_firmware" == "1" ] || [ "$_firmware" == "4" ] || [ "$_firmware" == "6" ] || [ "$_firmware" == "7" ] ; then
lan_ip=$(uci get network.lan.ipaddr)
d_wwwPath='/www'
[ -z "$lan_ip" ] && lan_ip=$(ifconfig br-lan | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
[ "$_wwwURL" == '/user' ] && _wwwURL='/yamon'
elif [ "$_firmware" == "2" ] || [ "$_firmware" == "3" ] || [ "$_firmware" == "5" ] ; then
d_wwwPath='/tmp/var/wwwext/'
else
lan_ip=$(nvram get lan_ipaddr)
fi
[ -h "${_wwwPath}index.html" ] && rm -fv ${_wwwPath}index.html
[ -h "${_wwwPath}data" ] && rm -fv ${_wwwPath}data
[ -h "${_wwwPath}data3" ] && rm -fv ${_wwwPath}data3
[ -h "${_wwwPath}data3.3" ] && rm -fv ${_wwwPath}data3.3
[ -h "/www/user/user/" ] && rm -fv '/www/user/user/'
[ -h "/www/user/" ] && rm -fv '/www/user/'
[ -h "/tmp/www/www/" ] && rm -fv '/tmp/www/www/'
prompt '_symlink2data' 'Create symbollic links to the web data directories?' "$yn_y" '1' $zo_r
prompt '_wwwPath' 'Specify the path to the web directories?' "The path must start and end with a \`/\`" "$d_wwwPath" $re_path_slash
prompt '_wwwURL' "Specify the URL path to the reports - e.g. $lan_ip\`<path>\`?" " \`<path>\` must start and end with a \`/\`.
NB - enter just the path & do *NOT* include the IP address!" "$d_wwwURL" $re_path_slash
if [ "${_dataDir:0:1}" == "/" ] ; then
_dataPath=$_dataDir
else
_dataPath="${d_baseDir}/$_dataDir"
fi
prompt '_organizeData' 'Organize the data files (into directories by year or year-month)?' "Options:
\`0\` -> No
\`1\` -> by year
\`2\` -> by year & month (*):" '2' $zot_r
prompt '_enableLogging' 'Enable logging (for support & debugging purposes)?' "$yn_y" '1' $zo_r
[ "$_enableLogging" == "1" ] && prompt '_log2file' 'Where do you want to send the logging info?' "Options:
\`0\` -> screen
\`1\` -> file (*)
\`2\` ->both" '1' $zot_r '_enableLogging'
[ "$_enableLogging" == "1" ] && [ "$_log2file" -ne 0 ] && prompt '_logDir' 'Where do you want to create the logs directory?' "Options:
* a relative path within the install folder - e.g., logs/ (*)
* an absolute path elsewhere on your network - e.g, /<path>/" "logs/" $re_path_slash '_enableLogging'
[ "$_enableLogging" == "1" ] && prompt '_loglevel' 'How much detail do you want in the logs?' "Options:
\`-1\` -> really verbose
\`0\` -> all
\`1\` -> most (*)
\`2\` -> serious only" '1' "^([012]|-1)$" '_enableLogging'
[ "$_log2file" == "0" ] || [ "$_log2file" == "2" ] && prompt '_scrlevel' 'How much detail do you want shown on the screen?' "Options:
\`-1\` -> really verbose
\`0 \`-> all
\`1\` -> most (*)
\`2\` -> serious only" '1' "^([012]|-1)$" '_enableLogging'
prompt '_doLiveUpdates' 'Do you want to report `live` usage?' "$yn_y" '1' $zo_r
[ "$_doLiveUpdates" == "1" ] && prompt '_doArchiveLiveUpdates' 'Do you want to archive the `live` usage data?
NB - If yes, note that these files could consume a *lot* of disk space!' "$yn_n" '0' $zo_r '_doLiveUpdates'
ftpput=$(which ftpput)
if [ -z "$ftpput" ] ; then
$send2log "ftpput --> ftpput is not included" 0
updateConfig "_enable_ftp" "0"
else
$send2log "ftpput --> $ftpput" 0
prompt '_enable_ftp' 'Do you want to mirror a copy of your data files to an external FTP site?
NB - *YOU* must setup the FTP site yourself!' "$yn_n" '0' $zo_r
if [ "$_enable_ftp" == "1" ] ; then
prompt '_ftp_site' 'What is the URL for your FTP site?' 'Enter just the URL or IP address' '' '' '_enable_ftp'
prompt '_ftp_user' 'What is the username for your FTP site?' '' '' '' '_enable_ftp'
prompt '_ftp_pswd' 'What is the password for your FTP site?' '' '' '' '_enable_ftp'
prompt '_ftp_dir' 'What is the path to your FTP storage directory?' "Options: ''->root level -or- enter path" '' '' '_enable_ftp'
[ "$_organizeData" -gt "0" ] && echo "
*******************************************************
* You will have to manually create the year/month
* sub-directories on your FTP site for the data files.
*******************************************************
"
fi
fi
prompt '_doDailyBU' 'Enable daily backup of data files?' "$yn_y" '1' $zo_r
[ "$_doDailyBU" == "1" ] && prompt '_tarBUs' 'Compress the backups?' "$yn_y" '1' $zo_r '_doDailyBU'
fi
if [ ! -d "$_dataPath" ] ; then
$send2log ">>> Creating data directory" 0
mkdir -p "$_dataPath"
chmod -R 666 "$_dataPath"
fi
setWebDirectories
if [ "$_firmware" == "1" ] || [ "$_firmware" == "4" ] || [ "$_firmware" == "6" ] || [ "$_firmware" == "7" ] ; then
updateConfig "_dnsmasq_conf" "/tmp/etc/dnsmasq.conf"
updateConfig "_dnsmasq_leases" "/tmp/dhcp.leases"
_dnsmasq_conf="/tmp/etc/dnsmasq.conf"
_dnsmasq_leases="/tmp/dhcp.leases"
elif [ "$_firmware" == "2" ] || [ "$_firmware" == "3" ] ; then
updateConfig "_dnsmasq_conf" "/tmp/etc/dnsmasq.conf"
updateConfig "_dnsmasq_leases" "/tmp/var/lib/misc/dnsmasq.leases"
_dnsmasq_conf="/tmp/etc/dnsmasq.conf"
_dnsmasq_leases="/tmp/var/lib/misc/dnsmasq.leases"
fi
[ ! -f "$_dnsmasq_conf" ] && echo " >>> specified path to _dnsmasq_conf ($_dnsmasq_conf) does not exist"
[ ! -f "$_dnsmasq_leases" ] && echo " >>> specified path to _dnsmasq_leases ($_dnsmasq_leases) does not exist"
_configFile="${d_baseDir}/config.file"
if [ ! -f "$_configFile" ] ; then
touch "$_configFile"
$send2log "Created and saved settings in new file: \`$_configFile\`" 1
echo "
******************************************************************
* Created and saved settings in new file: \`$_configFile\`
******************************************************************"
else
copyfiles "$_configFile" "${d_baseDir}/config.old"
$send2log "Updated existing settings: \`$_configFile\`" 1
echo "
******************************************************************
* Saved configuration settings to \`$_configFile\`
* & copied previous file to \`${d_baseDir}/config.old\`
******************************************************************"
fi
dirty=''
mfl=''
p_list=$(cat "${d_baseDir}/default_config.file" | grep -o "^_[^=]\{1,\}")
IFS=$'\n'
for line in $(echo "$p_list")
do
dpe=$(echo "$configStr" | grep -i "^$line")
#echo "dpe-->$dpe"
[ -n "$dpe" ] && continue
eval nv=\"\$$line\"
[ -n "$nv" ] && [ "$nv" -ne '0' ] && echo "nv: *$nv*" && continue
dvn="d$line"
eval dv=\"\$$dvn\"
dirty="true"
mfl="$mfl
* $line ($dv)"
updateConfig "$line" "$dv"
done
[ -n "$dirty" ] && echo "
###########################################################
NB - One or more parameters were missing in your config.file!$mfl
The missing entries have been appended to that file with the default
values copied from \`default_config.file\`.
See \`default_config.file\` for more info about these values and check to ensure
that the selected values are appropriate for your network configuration.
###########################################################
"
echo "$configStr" > "$_configFile"
su="${d_baseDir}/startup.sh"
sd="${d_baseDir}/shutdown.sh"
rs="${d_baseDir}/restart.sh"
ya="${d_baseDir}/yamon${_version}.sh"
h2m="${d_baseDir}/h2m.sh"
glc="${d_baseDir}/glc.sh"
t_perm="775"
t_perm_msg="e.g., $t_perm (*)-> rwxrwxr-x"
if [ "$t_installmode" == 'b' ] ; then
chmod $t_perm -R "$d_baseDir"
chmod $t_perm "$su"
chmod $t_perm "$rs"
chmod $t_perm "$sd"
chmod $t_perm "$ya"
chmod $t_perm "$h2m"
chmod $t_perm "$glc"
chmod "$t_perm" -R "$_wwwPath"
$send2log "Changed \`$_wwwPath\` permissions to: \`$t_perm\`" 1
chmod "$t_perm" -R "${d_baseDir}/www"
$send2log "Changed \`${d_baseDir}/www\` permissions to: \`$t_perm\`" 1
else
perm_r=^[0-7][0-7][0-7]$
prompt 't_permissions' "Do you want to set directory permissions for \`${d_baseDir}\`?" "$yn_y" '1' $zo_r
if [ "$t_permissions" == "1" ] ; then
prompt 't_perm' "What permission value do you want to use?" "$t_perm_msg" "$t_perm" $perm_r 't_permissions'
$send2log "Changed ${d_baseDir} permissions to: \`$t_perm\`" 1
fi
chmod $t_perm -R "$d_baseDir"
chmod $t_perm "$su"
chmod $t_perm "$rs"
chmod $t_perm "$sd"
chmod $t_perm "$ya"
chmod $t_perm "$h2m"
chmod $t_perm "$glc"
t_www=0
if [ "$_firmware" == "1" ] || [ "$_firmware" == "4" ] || [ "$_firmware" == "6" ] || [ "$_firmware" == "7" ] ; then
t_perm="a+rX"
t_perm_msg="e.g., $t_perm (*)-> r-xr-xr-x"
perm_r=^[0-7a-zA-z+]{3,4}$
prompt 't_www' "Do you want to set directory permissions for \`${_wwwPath}\`?" "$yn_y" '1' $zo_r 't_permissions'
fi
if [ "$t_www" == "1" ] ; then
prompt 't_perm' "What permissions value do you want to use?" "$t_perm_msg" "$t_perm" $perm_r 't_permissions'
chmod "$t_perm" -R "$_wwwPath"
$send2log "Changed \`$_wwwPath\` permissions to: \`$t_perm\`" 1
chmod "$t_perm" -R "${d_baseDir}/www"
$send2log "Changed \`${d_baseDir}/www\` permissions to: \`$t_perm\`" 1
else
chmod 664 -R "$_wwwPath"
$send2log "Changed \`$_wwwPath\` permissions to: \`664\`" 1
fi
fi
startup_delay='10'
if [ "$_firmware" == "1" ] || [ "$_firmware" == "4" ] ; then
etc_init="/etc/init.d/yamon3"
t_init=1
[ "$t_installmode" == 'a' ] && prompt 't_init' 'Create YAMon init script in `/etc/init.d/`?' "$yn_y" '1' $zo_r
if [ "$t_init" == "1" ] ; then
[ "$t_installmode" == 'a' ] && prompt 'startup_delay' "By default, \`startup.sh\` will delay for 10 seconds prior to starting \`yamon${_version}.sh\`.
Some older/slower routers may require extra time." 'Enter the start-up delay [0-300]' '10' "^([0-9]|[1-9][0-9]|[1-2][0-9][0-9]|300)$"
$send2log "Created YAMon init script in `/etc/init.d/`" 1
[ ! -d "/etc/init.d/" ] && mkdir -p "/etc/init.d/" # is this even necessary?
echo "#!/bin/sh /etc/rc.common
START=99
STOP=10
start() {
# commands to launch application
if [ -d "$_lockDir" ]; then
echo "Unable to start, found $_lockDir directory"
return 1
fi
${d_baseDir}/startup.sh 10 &
}
stop() {
${d_baseDir}/shutdown.sh
return 0
}
restart() {
${d_baseDir}/restart.sh
return 0
}
boot() {
start
}" > "$etc_init"
chmod +x "$etc_init"
else
$send2log "Did not create start/stop entries in $etc_init --> $t_init" 1
fi
elif [ "$_firmware" == "6" ] || [ "$_firmware" == "7" ] ; then
etc_rc="/etc/rc.local"
t_init=1
[ "$t_installmode" == 'a' ] && prompt 't_init' 'Create YAMon init script in `/etc/rc.local`?' "$yn_y" '1' $zo_r
if [ "$t_init" == "1" ] ; then
[ "$t_installmode" == 'a' ] && prompt 'startup_delay' "By default, \`startup.sh\` will delay for 10 seconds prior to starting \`yamon${_version}.sh\`.
Some older/slower routers may require extra time." 'Enter the start-up delay [0-300]' '10' "^([0-9]|[1-9][0-9]|[1-2][0-9][0-9]|300)$"
$send2log "Created YAMon init script in $etc_rc" 1
[ ! -f "$etc_rc" ] && touch "$etc_rc" # is this even necessary?
c_txt=$(cat "$etc_rc")
if [ -z "$(echo "$c_txt" | grep 'startup.sh')" ] ; then
sed -i "s~exit 0~${su} \nexit 0~g" "$etc_rc"
else
$send2log "Skipped adding startup.sh to $etc_rc" 1
echo -e "
\`$etc_rc\` already contains the string \`startup.sh\`...
\`$su\` was not added again"
fi
else
$send2log "Did not create start/stop entries in $etc_rc --> $t_init" 1
fi
else
t_startup=1
[ "$t_installmode" == 'a' ] && prompt 't_startup' 'Do you want to create startup and shutdown scripts?' "$yn_y2" '1' $zo_r2
need2commit=''
if [ "$t_startup" == "1" ] ; then
[ "$t_installmode" == 'a' ] && prompt 'startup_delay' "By default, \`startup.sh\` will delay for 10 seconds prior to starting \`yamon${_version}.sh\`.
Some older/slower routers may require extra time." 'Enter the start-up delay [0-300]' '10' "^([0-9]|[1-9][0-9]|[1-2][0-9][0-9]|300)$"
cnsu=$(nvram get rc_startup)
if [ -z "$cnsu" ] ; then
$send2log "Created nvram-->rc_startup" 1
echo "
\`rc_startup\` was empty... \`$su\` was added"
nvram set rc_startup="$su $startup_delay"
need2commit="true"
elif [ -z "$(echo $cnsu | grep 'startup.sh')" ] ; then
$send2log "Added to nvram-->rc_startup" 1
echo "
\`rc_startup\` was not empty but does not contain the string \`startup.sh\`...
\`$su\` was appended"
nvram set rc_startup="$cnsu
$su $startup_delay"
need2commit="true"
else
$send2log "Skipped adding nvram-->rc_startup" 1
echo -e "
\`rc_startup\` already contains the string \`startup.sh\`...
\`$su\` was not added again"
fi
cnsd=$(nvram get rc_shutdown)
if [ -z "$cnsd" ] ; then
$send2log "Created nvram-->rc_shutdown" 1
echo "
\`rc_shutdown\` was empty... \`$sd\` was added"
nvram set rc_shutdown="$sd"
need2commit="true"
elif [ -z "$(echo $cnsd | grep 'shutdown.sh')" ] ; then
$send2log "Added to nvram-->rc_shutdown" 1
echo "
\`rc_shutdown\` was not empty but does not contain the string \`shutdown.sh\`...
\`$sd\` was appended"
nvram set rc_shutdown="$cnsd
$sd"
need2commit="true"
else
$send2log "Skipped nvram-->rc_shutdown" 1
echo -e "
\`rc_shutdown\` already contains the string \`shutdown.sh\`...
\`$sd\` was not added again"
fi
[ -n "$need2commit" ] && nvram commit
elif [ "$t_startup" == "2" ] ; then
etc_init="/opt/etc/init.d/S99yamon3"
t_init=1
if [ "$t_init" == "1" ] ; then
[ "$t_installmode" == 'a' ] && prompt 'startup_delay' "By default, \`startup.sh\` will delay for 10 seconds prior to starting \`yamon${_version}.sh\`.
Some older/slower routers may require extra time." 'Enter the start-up delay [0-300]' '10' "^([0-9]|[1-9][0-9]|[1-2][0-9][0-9]|300)$"
$send2log "Created YAMon init script in `/opt/etc/init.d/`" 1
cat > "$etc_init" <<EOF
#!/bin/sh
ENABLED=yes
DESC=YAMon3
start() {
sh $su $startup_delay
}
stop() {
sh $sd
}
restart() {
sh $rs
}
case "\$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: /opt/etc/init.d/S99yamon3 {start|stop|restart}"
;;
esac
EOF
chmod +x "$etc_init"
fi
else
$send2log "Did not create start/stop entries in nvram --> $t_startup" 1
fi
fi
ip4=$(eval iptables -nL | grep "Chain $YAMON_IP4")
[ -n "$ip4" ] && $(iptables -F "$YAMON_IP4")
if [ "$_includeIPv6" == "1" ] ; then
ip6=$(eval ip6tables -nL | grep "Chain $YAMON_IP6")
[ -n "$ip6" ] && $(ip6tables -F "$YAMON_IP6")
fi
echo "
****************************************************************
Set up is complete!!!
"
prompt 't_launch' 'Do you want to launch YAMon now?' "$yn_y" '1' $zo_r
if [ "$t_launch" == "1" ] ; then
$send2log "Launched " 1
echo "
****************************************************************
[Re]starting YAMon$_version
"
${d_baseDir}/restart.sh
exit 0
fi
echo "
****************************************************************
YAMon$_version is now configured and ready to run.
To launch YAMon manually, enter \`${d_baseDir}/startup.sh\`.
If you have questions, please send them to [email protected]
(Include log files and/or screenshots if you have installation difficulties)
Thx!
Al
"