-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish
executable file
·143 lines (123 loc) · 4.54 KB
/
publish
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
#!/bin/bash
#
# A simple publishing tool for these utilities.
#
# A router and webserver and associated locations are defined at top.
# My configs in place at present.
#
# Most I store in /root/bin on my OpenWRT router and ensure that's in
# root's path on the router so I can ssh to it and have access to these
# little utilities easily.
#
# This keeps them nice and separate from the core of OpenWRT.
#
# I have bash and python scripts with extensions to identify them,
# but strip those extensions when copying to the router to provide
# convenient commands.
#
# For the DDNS diagnostic tools there are some special locations:
#
# A place to copy our web page on a webserver that has a fixed IP so it can be
# consulted when DDNS updates go awry and so that it sIP can be whitelisted for the
# NameCheap API which I use to check the DDNS configuration.
# To mount the router and webserver we need to have SSH access and SSH keys installed
# as we'll use sshfs to mount them if needed
rsa_file=/home/bernd/.ssh/id_rsa
# A timestamp file to save copying files to webserver unnecessarily
tsFile="publish.time"
# Router configs
router=Cerberus
router_mount_dir=~/Mounts/$router
router_dir=/ # Root dir on the router
router_root_bin=$router_mount_dir/root/bin # Router root users bin directory
router_usr_bin=$router_mount_dir/usr/bin # Routers system /usr/bin directory
router_hotplug_file=$router_mount_dir/etc/hotplug.d/iface/96-ddns-log # A hotplug filename that will execute when the router brings the WAN interface up
# Webserver configs
webserver=AlwaysData
webserver_mount_dir=~/Mounts/$webserver
webserver_dir=/home/thumbs-place # Home directory on the web server
webserver_html=$webserver_mount_dir/www/ddns # The directory for the DDNS diagnostics web page
webserver_cgi=$webserver_mount_dir/www/cgi-bin # The ncdip utility is executed by the web page and needs to be in a CGI enabled direrctory on the server
webserver_auth=$webserver_mount_dir/.auth # ncdip utility expects a ~/.auth/namecheap.auth file to log into the API
# Ensure the router is properly mounted (or we can't publish to them)
mountpoint -q $router_mount_dir
if [ $? != 0 ];then
if [ ! -d $router_mount_dir ]; then
echo Creating $router_mount_dir ...
mkdir -p $router_mount_dir
fi
echo Mounting $router_mount_dir ...
sshfs -o IdentityFile=$rsa_file $router_account:$router_dir $router_mount_dir
fi
# Personal utiltiites: Most utilities in roots personal bin directory
putils=(clear_notifications.sh
dns.py
IPowner.sh
knot.sh
lanstat.py
list_notifications.sh
NAT.py
ncdip.py
nodename.py
search.sh
textfile.sh
wanstat.py
wantimes.py
whois.sh)
# Global utilities: Some go to /usr/bin so they are in the default path for cron and the hotplug daemon
gutils=(ddns_domains.sh
ddns_watch.sh
ddns_web.sh
ddns_check.sh
ddnsip.py
dhcp_watch.sh
IPnames.py
lanip.sh
log_wanip.sh
MACnames.py
routes.py
wanip.sh)
echo Copying utilities to $router /root/bin...
for filename in ${putils[@]}; do
cp $filename $router_root_bin/${filename%.*}
done
# Some in /usr/bin as they need to be in the path of the hotplug daemon or cron
echo Copying binaries to $router /usr/bin...
for filename in ${gutils[@]}; do
cp $filename $router_usr_bin/${filename%.*}
done
# Special hotplug configuration for wanip logging
echo Copying hotplug configuration to $router...
cp hotplug_ddns_log.sh $router_hotplug_file
# Check if we need to publish to webserver
files=(default.css index.php ncdip.py)
newest=$(stat -c %Y $tsFile)
newestFile=$tsFile
for file in ${files[@]}; do
filetime=$(stat -c %Y $file)
[[ $filetime -gt $newest ]] && newest=$filetime && newestFile="$file"
done
if [[ "$newestFile" != "$tsFile" ]]; then
# Ensure the webserver is properly mounted (or we can't publish to them)
if [ ! -d $webserver_mount_dir ]; then
echo Creating $webserver_mount_dir ...
mkdir -p $webserver_mount_dir
fi
mountpoint -q $webserver_mount_dir
if [ $? != 0 ];then
echo Mounting $webserver_mount_dir ...
sshfs -o IdentityFile=$rsa_file $webserver_account:$webserver_dir $webserver_mount_dir
fi
# The DDNS diagnostics web page on a remote server
echo Copying web page to $webserver...
cp index.php default.css $webserver_html
cp ncdip.py $webserver_cgi/ncdip
# Handle the auth file specially (used to access the Namecheap API and for logging WAN IPs)
cp ~/.auth/namecheap.auth $webserver_auth
touch $tsFile
else
echo $webserver files are up to date.
fi
echo Done.