You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.7 KiB
77 lines
1.7 KiB
8 years ago
|
#!/bin/sh
|
||
|
#
|
||
7 years ago
|
# a workaround for the sucking date behavior of doscam, oscam and ncam
|
||
8 years ago
|
#
|
||
|
|
||
|
. /etc/init.d/globals
|
||
|
|
||
|
BINARY="/var/bin/$2"
|
||
|
FLAGFILE="/var/etc/.$2"
|
||
|
|
||
|
case "$1" in
|
||
|
"start")
|
||
|
DATE_TODAY=$(date +%Y%m%d%H%M)
|
||
7 years ago
|
# keep line below in sync with dummy time in rcS
|
||
|
if [ "${DATE_TODAY:0:8}" = "20170101" ]; then
|
||
8 years ago
|
# try to read date from flagfile
|
||
|
test -e $FLAGFILE && \
|
||
|
DATE_FLAG=$(date -r $FLAGFILE +%Y%m%d%H%M)
|
||
|
|
||
|
# try to read date from binary
|
||
7 years ago
|
DATE_CAMD=$(strings $BINARY | grep -B1 "is smaller than the build date")
|
||
|
DATE_CAMD=${DATE_CAMD:0:11}
|
||
|
_m=$(echo $DATE_CAMD | cut -d\ -f1)
|
||
|
_d=$(echo $DATE_CAMD | cut -d\ -f2)
|
||
|
_y=$(echo $DATE_CAMD | cut -d\ -f3)
|
||
8 years ago
|
|
||
|
c=0
|
||
|
for m in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec; do
|
||
|
c=$(($c+1))
|
||
|
if [ "$m" = "$_m" ]; then
|
||
|
_m=$c
|
||
|
break
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
test ${#_m} -lt 2 && _m=0$_m
|
||
|
test ${#_d} -lt 2 && _d=0$_d
|
||
|
|
||
7 years ago
|
DATE_CAMD=$_y$_m$_d
|
||
8 years ago
|
|
||
|
# try to read date from versionfile
|
||
|
DATE_IMAGE=$(cat /.version | grep "^version=" | cut -d= -f2)
|
||
|
DATE_IMAGE=${DATE_IMAGE:4}
|
||
|
|
||
|
c=0
|
||
7 years ago
|
for date in "$DATE_FLAG" "$DATE_CAMD" "$DATE_IMAGE"; do
|
||
8 years ago
|
c=$(($c+1))
|
||
|
while [ ${#date} -lt 12 ]; do
|
||
|
date=$date"0"
|
||
|
done
|
||
|
test $c = 1 && DATE_FLAG=$date
|
||
7 years ago
|
test $c = 2 && DATE_CAMD=$date
|
||
8 years ago
|
test $c = 3 && DATE_IMAGE=$date
|
||
|
done
|
||
|
|
||
|
SHOWINFO "manipulating date ... "
|
||
7 years ago
|
for date in "$DATE_FLAG" "$DATE_CAMD" "$DATE_IMAGE"; do
|
||
8 years ago
|
echo $date;
|
||
|
done | sort -r -u | while read date; do
|
||
|
if date -s $date > /dev/null; then
|
||
|
SHOWINFO "done ($date)"
|
||
|
break
|
||
|
else
|
||
|
continue
|
||
|
fi
|
||
|
SHOWWARN "failed"
|
||
|
done
|
||
|
fi
|
||
|
;;
|
||
|
"stop")
|
||
|
test -e $FLAGFILE && touch $FLAGFILE
|
||
|
;;
|
||
|
*)
|
||
7 years ago
|
echo "[$BASENAME] Usage: $0 {start|stop}"
|
||
8 years ago
|
;;
|
||
|
esac
|