pexcn / openwrt-chinadns-ng

ChinaDNS Next Generation for OpenWrt, refactoring with epoll and ipset.
https://github.com/zfl9/chinadns-ng
GNU General Public License v3.0
189 stars 62 forks source link

Share a chinadns crontab script, which only update conf file when there is really updates available #42

Open void285 opened 1 year ago

void285 commented 1 year ago
#!/bin/sh -e

[ -d /etc/chinadns-ng ] || mkdir /etc/chinadns-ng
reload=0
for item in chnroute/chnroute chnroute/chnroute6 gfwlist/gfwlist chinalist/chinalist
do
    file=${item##*/}
    localsize=`wc -c /etc/chinadns-ng/${file}.txt | awk '{print $1}'`
    remotesize=`curl -s -I https://raw.githubusercontent.com/pexcn/daily/gh-pages/${item}.txt | grep -i "Content-Length:" | awk '{print $2}'`
    if [ $localsize != $remotesize ]; then
        wget --no-dns-cache --no-check-certificate -4 https://raw.githubusercontent.com/pexcn/daily/gh-pages/${item}.txt -O /tmp/${file}.tmp && [ "$?" == "0" ] && mv -f /tmp/${file}.tmp /etc/chinadns-ng/${file}.txt && reload=1 && echo "update ${file}, size ${localsize} -> ${remotesize}" || "update ${file} failed"
    else
        echo "ignore ${file}, size ${localsize}"
    fi
done

if [ $reload == 1 ]; then
    /etc/init.d/chinadns-ng restart
fi
pexcn commented 1 year ago

I think check the hash will better, such as md5sum.

void285 commented 1 year ago

Please achieve it, since write to nand/emmc is slow and fragile.