#!/bin/bash

echo "Running this script will backup your sudoers file and rewrite my own. Running the script ./ractivator or uninstalling will reverse this."

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/activator.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 "Enabling Activator root support using sudo..."
echo "Backing up old sudo file..."
cp -a /etc/sudoers /etc/SystemHostsBlocker/Sudo/origSudo
echo "Backed up old sudoers file..."
echo "Writing custom file..."

echo "Making scripts runnable..."
chmod u+x enable
chmod u+x disable
chmod u+x ractivator
chmod u+x stash
chmod u+x restore
echo "Done!"

cp -a /etc/SystemHostsBlocker/Sudo/sudoers /etc/sudoers
chmod 0440 /etc/sudoers
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!"
