forked from dinoex/iroffer-dinoex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynip.sh
executable file
·45 lines (38 loc) · 1.09 KB
/
dynip.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
#!/bin/sh
#### WHAT THIS DOES ####
#
# If you have a dynamic ip address and require setting 'usenatip'
# in the iroffer config file this script can auto-generate a 1 line
# config file containing your current ip address
# run iroffer with multiple config files (your normal config plus
# this auto-generated config)
#
# If your ip address changes, the file will be updated by this script
# and iroffer rehashed to see the change
#
# Call this scrip when your IP changes or put in in your crontab.
# Rin "crontab -e" and place the following line in the editor:
# */5 * * * * /full/path/to/iroffer/dynip.sh
URL="http://iroffer.org/myip.cgi"
CONFIGFILE="dynip.config"
PIDFILE="mybot.pid"
set -e
set -u
curl --silent ${URL} \
|sed -e 's=^=usenatip =' \
> ${CONFIGFILE}.tmp
test -f ${CONFIGFILE} || touch ${CONFIGFILE}
if diff ${CONFIGFILE} ${CONFIGFILE}.tmp; then
echo ip unchanged
rm -f ${CONFIGFILE}.tmp
else
echo ip changed
mv -f ${CONFIGFILE}.tmp ${CONFIGFILE}
if [ -f ${PIDFILE} ]; then
echo rehashing iroffer
kill -USR2 `cat ${PIDFILE}`
else
echo no iroffer running
fi
fi
exit 0