1111# Licenced under GPL-2 @ 2012
1212# Matthias Strubel matthias.strubel@aod-rgp.de
1313
14+ # #function for similar saving & getting time
15+ get_datetime () {
16+ date +%C%g%m%d%H%M
17+ }
18+
1419
1520# Load configfile
1621
@@ -34,33 +39,33 @@ if [ "$2" = "install" ] ; then
3439 echo " */5 * * * * $PIRATEBOX_FOLDER /bin/timesave.sh $PIRATEBOX_FOLDER /conf/piratebox.conf save " >> $PIRATEBOX_FOLDER /tmp/crontab
3540 crontab $PIRATEBOX_FOLDER /tmp/crontab
3641
42+ echo " initialize timesave file"
3743 touch $TIMESAVE
3844 chmod a+rw $TIMESAVE
45+ get_datetime > $TIMESAVE
3946
40- echo " Remember to have cron active..."
41- echo " on OpenWrt run: /etc/init.d/cron enable"
42- echo " /etc/init.d/cron start"
4347
44- # Save the current time
45- $0 $1 " save"
48+ echo " Remember MAY have to cron active..."
49+ echo " on OpenWrt run: /etc/init.d/piratebox enable"
50+
4651 exit 0
4752fi
4853
4954if [ " $2 " = " save" ] ; then
5055 if [ -e $TIMESAVE ] ; then
51- if [ ` date +%C%g%m%d%H%M ` -lt ` cat $TIMESAVE ` ] ; then
56+ if [ ` get_datetime ` -lt ` cat $TIMESAVE ` ] ; then
5257 logger -s " $0 : sorry, current date-time is lower then saved one, don't save it this time"
5358 exit 1
5459 fi
5560 fi
5661
5762 # Save Datetime in a recoverable format...
58- date +%C%g%m%d%H%M > $TIMESAVE
63+ get_datetime > $TIMESAVE
5964 exit 0
6065fi
6166
6267if [ " $2 " = " recover" ] ; then
63- if [ ` date +%C%g%m%d%H%M ` -lt ` cat $TIMESAVE ` ] ;
68+ if [ ` get_datetime ` -lt ` cat $TIMESAVE ` ] ;
6469 date ` cat $TIMESAVE `
6570 [ " $? " != " 0" ] && echo " error in recovering time" && exit 255
6671 echo " Time recovered"
0 commit comments