Skip to content

Instantly share code, notes, and snippets.

@empireshades
Last active September 2, 2021 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save empireshades/6fc526c5c4e75eaad39599468d9f2ea6 to your computer and use it in GitHub Desktop.
Save empireshades/6fc526c5c4e75eaad39599468d9f2ea6 to your computer and use it in GitHub Desktop.
Block access to google for younger kid when logged in on mac but make sure it works for everyone else. Run on root's crontab every minute and make sure common_hosts contains what you want as baseline hosts file.
cd "${0%/*}"
# Check which user is logged in
user=$(stat -f '%Su' /dev/console)
# Check if hosts file contains 'google'
if $(grep -q google /etc/hosts);then
GOOGLE=true
else
GOOGLE=false
fi
# Add google if it doesn't exist and user is Kylie
if [ $user == "bobby" ] && ! $GOOGLE; then
cat common_hosts > /etc/hosts
cat >> /etc/hosts << EOF
127.0.0.1 google.com www.google.com
EOF
# Else, clear it out
elif [ $user != "bobby" ] && $GOOGLE; then
cat common_hosts > /etc/hosts
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment