Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function catcherror {
- "$@"
- STATUS=$?
- if [ $STATUS -ne 0 ]; then
- echo Error with $@ $TS >> $LOG;
- fi
- return $STATUS
- }
- function cleanup {
- SUCCESS=-1
- if [ $ALT == 0 ]; then #remove the .gz
- catcherror rm $GZ
- if [ $STATUS -ne 0 ]; then
- SUCCESS=0
- else
- SUCCESS=1
- fi
- else #remove the .zip
- echo Alternate download was used $TS >> $LOG
- catcherror rm $ZIP
- if [ $STATUS -ne 0 ]; then
- SUCCESS=0
- else
- SUCCESS=1
- fi
- fi
- if [ $SUCCESS == 1 ]; then
- echo Complete $TS >> $LOG
- else
- echo Failed to remove archive file $TS >> $LOG
- fi
- return
- }
- ALT=0 # flag that alternate download is to be attempted
- ALTFAIL=-1 # flag that alternate download failed
- LOG=/root/scripts/p2p-update.log # path of log
- GZ=/root/scripts/.lvl1/level1.gz # path of .gz
- ZIP=/root/scripts/.lvl1/level1.zip # path of .zip
- BL=/root/.config/transmission/blocklists # path of blocklist dir
- DL=/root/scripts/.lvl1 # path of download location
- TS=`date` # timestamp
- catcherror wget "http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz" -O $GZ
- if [ $STATUS -ne 0 ]; then #wget failed first try
- ALT=1 #try alternate means
- else #wget worked first try
- catcherror file-roller -e $BL $GZ
- if [ $STATUS -ne 0 ]; then #file-roller failed to extract the list
- ALT=1 #try alternate means
- else #everything worked first try
- cleanup
- fi
- fi
- if [ $ALT == 1 ]; then #try to wget .zip
- catcherror wget "http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=zip" -O $ZIP
- if [ $STATUS -ne 0 ]; then #wget of .zip failed
- ALTFAIL=1
- else #wget of .zip worked
- catcherror unzip -o -d $BL $ZIP #try to unzip .zip
- if [ $STATUS -ne 0 ]; then #unzip failed
- ALTFAIL=1
- else #everything worked second try
- cleanup
- fi
- fi
- fi
- if [ $ALTFAIL == 1 ]; then
- echo Alternate means failed. $TS >> $LOG
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement