ใช้งานอยู่กับ ipcop 1.4.21 , ipcop-1.4.21-kernel-2.4.36 , qos_ng_ipcop_1.4.21
เนื้อหา file l7update
#!/bin/bash
#
#modification to change the year automatically
setyear=2009
#thisyear=`date +%Y`
thisyear=2009
if [ "x$setyear" != "x$thisyear" ]
then
sed -i -e "s/$setyear/$thisyear/g" $0
echo -e "\nautomatically updated download-link, please start l7update again!\n"
exit 0
fi
# end modification
if [ "x$1" != "x" -a "x$1" != "xstartup" ]
then
MIRROR=$1
else
MIRROR=switch
fi
cd /var/ipcop/l7filter
/var/ipcop/l7filter/wget -O "/var/ipcop/l7filter/index.html" -q "
http://sourceforge.net/projects/l7-filter/files/"
currentY=$(cat localversion | cut -f1 -d"-")
currentM=$(cat localversion | cut -f2 -d"-")
currentD=$(cat localversion | cut -f3 -d"-")
currentV="$currentD$currentM$currentY"
#echo $currentV
lastY=$(cat "/var/ipcop/l7filter/index.html" |grep -B 1 l7-protocols 2>/dev/null|grep -B 0 title | sort -b -r| grep -m 1 "2009-" 2>/dev/null|cut -d- -f5 2>/dev/null)
lastM=$(cat "/var/ipcop/l7filter/index.html" |grep -B 1 l7-protocols 2>/dev/null|grep -B 0 title | sort -b -r| grep -m 1 "2009-" 2>/dev/null|cut -d- -f6 2>/dev/null)
lastD=$(cat "/var/ipcop/l7filter/index.html" |grep -B 1 l7-protocols 2>/dev/null|grep -B 0 title | sort -b -r| grep -m 1 "2009-" 2>/dev/null|cut -d- -f7|cut -d. -f1 2>/dev/null)
lastV="$lastD$lastM$lastY"
lastupdate="$lastY-$lastM-$lastD"
#echo $lastupdate
[ "$lastV" == "" ] && echo -e "Unable to detect online Version, exiting..........." && exit 1
[ "$currentV" == "" ] && echo -e "Unable to detect installed Version, exiting..........." && exit 1
/bin/rm index.html
if [ "$lastV" != "$currentV" ]
then
CHECK=`/var/ipcop/l7filter/wget --spider http://$MIRROR.dl.sourceforge.net/project/l7-filter/Protocol%20definitions/"$lastupdate"/l7-protocols-"$lastupdate".tar.gz 2>&1`
#echo $CHECK
SIZE=`/bin/echo $CHECK| cut -dL -f2| awk {'print $2'}|cut -d, -f1`
NOTFOUND=`/bin/echo $SIZE|grep http`
NOTFOUND="x${NOTFOUND}"
FAILED=`/bin/echo $CHECK| grep failed| cut -d: -f6`
FAILED="x${FAILED}"
#echo $SIZE
#echo;echo;echo
#echo $NOTFOUND
#echo;echo;echo
#echo $FAILED
if [ "$FAILED" != "x" ]
then
if [ "x$1" != "xstartup" ]
then
/bin/echo "Error while downloading file."
exit 0
else
/bin/echo -e "[\033[1;31m Failed \033[0m]"
exit 0
fi
fi
if [ "$NOTFOUND" != "x" ]
then
if [ "x$1" != "xstartup" ]
then
/bin/echo "File is not on the mirror right now."
exit 0
else
/bin/echo -e "[\033[1;31m Failed \033[0m]"
exit 0
fi
fi
if [ $SIZE -le 2 ]
then
if [ "x$1" != "xstartup" ]
then
/bin/echo "File is not on the mirror right now."
exit 0
else
/bin/echo -e "[\033[1;31m Failed \033[0m]"
exit 0
fi
fi
/var/ipcop/l7filter/wget -q http://$MIRROR.dl.sourceforge.net/project/l7-filter/Protocol%20definitions/"$lastupdate"/l7-protocols-"$lastupdate".tar.gz
/bin/echo $lastupdate > localversion
/bin/tar xfz l7-protocols-"$lastupdate".tar.gz
/bin/rm -rf /etc/l7-protocols/
/bin/mv l7-protocols-"$lastupdate" /etc/l7-protocols
/bin/chown -R root.root /etc/l7-protocols
/bin/rm l7-protocols-"$lastupdate".tar.gz
/bin/echo "$(date) : Layer7 protocols updated successefully" >>/var/log/messages
if [ "x$1" == "xstartup" ]
then
echo -e "[\033[1;32m Done \033[0m]"
fi
else
/bin/echo "$(date) : Your Layer7 protocols are up to date" >>/var/log/messages
if [ "x$1" == "xstartup" ]
then
echo -e "[\033[1;32m Done \033[0m]"
fi
fi