pihole_lists/pull.lists.sh
robocopAlpha 4e52559f79 simplified updates
as the idea is to generate blocklists daily, the update package will be downloaded daily without checksum. Easier this way.
Can implement checksum of the update package if needed.
2021-07-16 03:40:56 +03:00

72 lines
No EOL
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
[[ -f set_env.sh ]] && source set_env.sh || { echo "set_env.sh not found"; exit 1; }
# Mounting storage
if df | grep -c dropbox > /dev/null; then
umount "${HOME_DIR}/dropbox" || sudo umount "${HOME_DIR}/dropbox"
fi
if [[ -d "${HOME_DIR}/dropbox" ]]; then
rm -rf "${HOME_DIR}/dropbox"
mkdir "${HOME_DIR}/dropbox"
else
mkdir "${HOME_DIR}/dropbox"
fi
rclone mount --daemon dropbox:blocklist "${HOME_DIR}/dropbox" --volname dropbox
cd "${WRK_DIR}/"
echo $(date +%d.%m.%y-%H:%M:%S) >| lastpull
# Fetch blocklists
bash "${WRK_DIR}/get_blocklists.sh"
if [ $? -ne 0 ]; then
echo "Failed to get blocklists. Execution terminated!"
exit 1
fi
# Block FB
source "${WRK_DIR}/block_FB.sh" || { echo "Failed to get Facebook blocklist. Execution terminated!"; exit 1; }
# Combining blocklists
echo "Consolidating blocklists..."
${catCMD} Mirrors/* | sort -u | uniq >| MyBlocklist.txt
wc -l MyBlocklist.txt
echo -e "\nAdding these to my own Blacklist: \n"
${catCMD} blocked | rg -vIN "^[\\#]" | sd '\s+$' '' | sort -u | uniq >> MyBlocklist.txt
echo -e " $(wc -l MyBlocklist.txt) unique domains. \n"
#-------
# Clean-up
echo "Cleaning up..."
rm -rf Mirrors
rm -f blocklists/MyBlocklist.txt.xz blocklists/facebook_block.txt.xz
mkdir blocklists
mv MyBlocklist.txt blocklists/.
mv facebook_block.txt blocklists/.
#--------
# Archiving
echo "Compressing blocklists..."
cd "${WRK_DIR}/blocklists/"
# getMD5 "MyBlocklist.txt" >| MyBlocklist.checksum
# getMD5 "facebook_block.txt" >| facebook_block.checksum
sleep 1
xz -v -T4 MyBlocklist.txt
xz -v -T4 facebook_block.txt
chmod 777 ./*
#---------
# Moving to target
echo "Moving blocklists to destination..."
cd "${WRK_DIR}/"
rsync -a --progress blocklists/* "${HOME_DIR}/dropbox/"
echo "Final clean up..."
umount "${HOME_DIR}/dropbox" || sudo umount "${HOME_DIR}/dropbox"
rm -rf "${HOME_DIR}/dropbox"
rm -rf "blocklists"
echo "Done!"