#!/bin/bash

echo "Attempting to disable System Hosts Blocker..."
echo "Make sure to run as root."

echo "Running MD5Sum Check..."
echo "Moving to script directory..."
cd /etc/SystemHostsBlocker/
echo "Moved to directory..."
echo "Starting check..."
if md5sum -c /etc/SystemHostsBlocker/Security/disable.md5; then
    echo "Heck yeah! Your files were verified! Continuing to run script!"
else
  echo "We couldn't verify this script is genuine. It may have been tempered with. Removing SHB and its files..."
  apt-get --yes remove com.nathanaccidentally.systemhostsblocker
  apt-get --yes remove com.nathanaccidentally.mdnsflush
  echo "Should be removed. Crashing to Safe Mode..."
  killall -SEGV SpringBoard
  echo "Should be dead. :/"
fi

echo "Creating Stash2 (For running enable script.)"
cp -a /etc/hosts /etc/SystemHostsBlocker/StashedHosts/stash2
chmod 644 /etc/SystemHostsBlocker/StashedHosts/stash2
chown root:wheel /etc/SystemHostsBlocker/StashedHosts/stash2

echo "Restoring to stashed hosts..."
cp -a /etc/SystemHostsBlocker/StashedHosts/originalhosts /etc/hosts
echo "Restore completed. Fixing permissions..."
chmod 644 /etc/hosts
chown root:wheel /etc/hosts
echo "Done!"

echo "Running last security step..."
chown root:wheel /etc/SystemHostsBlocker/activator /etc/SystemHostsBlocker/enable /etc/SystemHostsBlocker/disable /etc/SystemHostsBlocker/ractivator /etc/SystemHostsBlocker/restore /etc/SystemHostsBlocker/stash /etc/SystemHostsBlocker/systemhosts /etc/SystemHostsBlocker/Sudo/sudoers
echo "All done!"

exit
