Created
March 25, 2019 06:13
-
-
Save janlay/26da391c0e016b309b0a89043974d07c to your computer and use it in GitHub Desktop.
ChinaDNS Updater for OpenWRT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE=/etc/chinadns_chnroute.txt | |
TEMP_FILE="$FILE.tmp" | |
TELEGRAM_BOT=/root/scripts/telegram-bot | |
SOURCE="https://raw.githubusercontent.com/ym/chnroutes2/master/chnroutes.txt" | |
LOGFILE=/root/scripts/chinadns-updater.log | |
echo -e "\nChinaDNS Updater started at `date`." >> $LOGFILE | |
echo "Current routes: `wc -l "$FILE" | cut -d' ' -f1`." >> $LOGFILE | |
echo "Fetching networks from $SOURCE ..." >> $LOGFILE | |
if ! curl -sfk "$SOURCE" -o "$TEMP_FILE"; then | |
echo "Error returned, check the source." >> $LOGFILE | |
exit 1 | |
fi | |
grep '#' "$TEMP_FILE" | cut -d' ' -f2- > "$FILE.stats" | |
cat "$FILE.stats" >> $LOGFILE | |
sed -i "/^#/d" "$TEMP_FILE" | |
echo "Backing up $FILE ..." >> $LOGFILE | |
cp "$FILE" "$FILE.bak" | |
echo "Restarting ChinaDNS service ..." >> $LOGFILE | |
mv "$TEMP_FILE" "$FILE" | |
/etc/init.d/chinadns restart | |
$TELEGRAM_BOT "*ChinaDNS routes updated*: | |
`cat $FILE.stats`" | |
rm $FILE.stats | |
echo "All done." >> $LOGFILE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment