mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
200 lines
4.2 KiB
Bash
Executable File
200 lines
4.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# copyrights
|
|
# (1)epg dowload Script VER 0.10for openwrt by zjhzzyf
|
|
|
|
|
|
. /lib/functions.sh
|
|
|
|
|
|
epg_down()
|
|
{
|
|
bsuc=1
|
|
echo "File Path:"$path
|
|
filename="epg.xml"
|
|
echo "Setup FileName:"$filename
|
|
sfullfilename=`echo $path$filename`
|
|
echo "sFullFileName:"$sfullfilename
|
|
|
|
index=0
|
|
echo "Try Times Max:"$trytimes
|
|
while [ "$index" -lt "$trytimes" ]
|
|
do
|
|
echo "Try Times:"$index
|
|
if wget -qO- -t3 $url > $sfullfilename;then
|
|
break
|
|
fi
|
|
index=`expr $index + 1`
|
|
done
|
|
if [ "$index" -eq "$trytimes" ]; then
|
|
ErrMsg=`date`
|
|
ErrMsg=$ErrMsg" 下载配置文件失败"
|
|
bsuc=0
|
|
return
|
|
fi
|
|
echo "down $filename completed"
|
|
mfullfilename=`echo ${path}store/${filename}.md5`
|
|
echo "MD5 File Name:"$mfullfilename
|
|
md5old=`cat $mfullfilename`
|
|
md5old=`echo $md5old|awk '{print $1}'|tr "[a-z]" "[A-Z]"`
|
|
echo "Old File MD5:"$md5old
|
|
md5new=`/usr/bin/md5sum $sfullfilename`
|
|
md5new=`echo $md5new|awk '{print $1}'|tr "[a-z]" "[A-Z]"`
|
|
echo "New File MD5:"$md5new
|
|
if [ "$md5old" = "$md5new" ]; then
|
|
ErrMsg=`date`
|
|
ErrMsg=$ErrMsg" 数据不需要更新"
|
|
bsuc=1
|
|
return
|
|
else
|
|
|
|
counttimes=0
|
|
suctimes=0
|
|
counttimes=`expr $counttimes + 1`
|
|
url=$(grep -m 1 "URL" $sfullfilename |awk -F "<URL>" '{print $2}'|awk -F "</URL>" '{print $1}')
|
|
echo "Down Data URL:" $url
|
|
|
|
filename=`echo ${url##*/}`
|
|
echo "Down File Name:"$filename
|
|
|
|
echo "====="
|
|
echo $url
|
|
replaces=`echo ${url%/*}`
|
|
|
|
replaces=`echo ${replaces#*//}`
|
|
|
|
echo replaces: $replaces
|
|
echo -e `sed -e "s#$replaces#$replaced#g" $sfullfilename` > `echo $sfullfilename`
|
|
echo "====="
|
|
|
|
dfullfilename=`echo $path$filename`
|
|
echo "Down Data Save File Name:"$dfullfilename
|
|
|
|
index=0
|
|
while [ "$index" -lt "$trytimes" ]
|
|
do
|
|
echo "Try Times:"$index
|
|
if wget -t3 -T120 -qO- $url > $dfullfilename;then
|
|
suctimes=`expr $suctimes + 1`
|
|
|
|
break
|
|
fi
|
|
index=`expr $index + 1`
|
|
|
|
done
|
|
|
|
if [ "$index" -eq "$trytimes" ]; then
|
|
bsuc=0
|
|
ErrMsg=`date`
|
|
ErrMsg=$ErrMsg" 下载"$url"失败"
|
|
|
|
fi
|
|
|
|
|
|
if [ "$counttimes" -eq "$suctimes" ]; then
|
|
echo $md5new > `echo $mfullfilename`
|
|
|
|
mount -o bind /tmp/epg/ /www/atmosphere
|
|
rm -rf ${path}/epg/*
|
|
|
|
cp ${path}$filename ${path}/epg
|
|
cp ${path}epg.xml ${path}/epg
|
|
rm -rf ${path}$filename
|
|
rm -rf ${path}epg.xml
|
|
ErrMsg=`date`
|
|
ErrMsg=$ErrMsg" 下载EPG数据成功"
|
|
echo $ErrMsg
|
|
exit 0
|
|
else
|
|
ErrMsg=`date`
|
|
ErrMsg= $ErrMsg " 未知原因失败"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
epg_start() {
|
|
|
|
config_get enable $1 enable
|
|
config_get interval $1 interval
|
|
[ "$enable" = "" ]&&enable=0
|
|
|
|
#make scheduler
|
|
|
|
epg_cron=`cat /etc/crontabs/root | grep "/usr/bin/epg scheduler"`
|
|
if [ "$enable" == "1" -a "${interval}" != "0" ]; then
|
|
mkdir -p /tmp/epg/
|
|
mkdir -p /tmp/epg/store
|
|
mkdir -p /tmp/epg/epg
|
|
mkdir -p /www/atmosphere
|
|
epg_new="*/${interval} * * * * /usr/bin/epg scheduler"
|
|
if [ "z${epg_cron}" != "z${epg_new}" ] ; then
|
|
cat /etc/crontabs/root | grep -v "/etc/init.d/epg scheduler" > /tmp/crontabs_epg
|
|
echo "*/${interval} * * * * /etc/init.d/epg scheduler" >> /tmp/crontabs_epg
|
|
echo "" >> /tmp/crontabs_epg
|
|
cat /tmp/crontabs_epg | grep -v ^$ > /etc/crontabs/root
|
|
/etc/init.d/cron restart
|
|
fi
|
|
else
|
|
if [ "z${epg_cron}" != "z" ] ; then
|
|
cat /etc/crontabs/root | grep -v "/etc/init.d/epg scheduler" > /tmp/crontabs_epg
|
|
cat /tmp/crontabs_epg | grep -v ^$ > /etc/crontabs/root
|
|
/etc/init.d/cron restart
|
|
fi
|
|
rm -f /tmp/crontabs_epg
|
|
|
|
fi
|
|
|
|
/etc/init.d/cron restart
|
|
|
|
}
|
|
|
|
|
|
con_get_addr(){
|
|
|
|
config_get addr_enable $1 addr_enable
|
|
config_get address $1 address
|
|
|
|
[ "$addr_enable" == "1" ]&&{
|
|
url=$address
|
|
echo $url
|
|
ErrMsg=`date`
|
|
ErrMsg=$ErrMsg" 开始从"$url"下载"
|
|
echo $ErrMsg >> `echo /tmp/epglog.txt`
|
|
rm `echo $path"*"`
|
|
epg_down
|
|
echo $ErrMsg >> `echo /tmp/epglog.txt`
|
|
echo $bsuc
|
|
echo "******************************************************************" >> `echo /tmp/epglog.txt`
|
|
}
|
|
}
|
|
|
|
|
|
|
|
epg_scheduler(){
|
|
|
|
path="/tmp/epg/"
|
|
trytimes=3
|
|
bsuc=1
|
|
ErrMsg=""
|
|
lan_ipaddr=$(uci get network.lan.ipaddr)
|
|
replaced="${lan_ipaddr}/atmosphere/epg"
|
|
|
|
|
|
}
|
|
|
|
|
|
config_load epg
|
|
case "$1" in
|
|
start)
|
|
config_foreach epg_start epg_set
|
|
;;
|
|
stop)
|
|
echo "stop test "
|
|
;;
|
|
scheduler)
|
|
epg_scheduler
|
|
config_foreach con_get_addr downaddress
|
|
;;
|
|
esac
|
|
|