my-scripts/update-hosts

45 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2022-09-19 02:13:02 +00:00
#!/usr/bin/env sh
#===================
#TODO:
# + currently making /etc/hosts a symlink to a user owned file to allow script to run w/o sudo, possible security issue.
#
#FLAGS:
# if $1 is -u then update files from internet
#
# ==================
BLOCKFILE="$HOME/.config/blocklist"
update() {
mkdir -p ~/.local/share/update_hosts
cd ~/.local/share/update_hosts
if [ ! -f "./.hosts.orig" ]; then
cp /etc/hosts ./.hosts.orig
fi
if [ "$1" = "-u" ]; then
rm ./.swc_hosts
#get someonewhocares.org hosts file
curl https://someonewhocares.org/hosts/hosts -o ./.swc_hosts
fi
#[ -f "$BLOCKFILE" ] && echo "blocklist file found." && sed 's/^/127.0.0.1 /g' "$BLOCKFILE" > ./blocklist
#if [ -f "./blocklist" ]; then
2022-12-24 07:17:20 +00:00
# cat ./.hosts.orig ./.swc_hosts ./blocklist > ./hosts
2022-09-19 02:13:02 +00:00
#else
cat ./.hosts.orig ./.swc_hosts > ./hosts
#fi
#cat ./.hosts.orig ./.swc_hosts > ./hosts
#sudo mv ./hosts /etc/
[ "$1" = "-u" ] && sudo rm /etc/hosts && sudo ln -s $HOME/.local/share/update_hosts/hosts /etc/ && exit
}
update "$1"