#!/bin/sh

##########################################################################
#   Script description:
#       Common admin tasks
#       
#   History:
#   Date        Name        Modification
#   2016-01-01  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0\n"
    exit 1
}


##########################################################################
#   Function description:
#       Pause until user presses return
##########################################################################

pause()
{
    local junk
    
    printf "Press return to continue..."
    read junk
}


##########################################################################
#   Main
##########################################################################

if [ $# != 0 ]; then
    usage
fi

# Prevent user from running a Trojan as root in the case their account
# was compromised
absolute="$(which $0)"
# Don't count on -e being set at this point
if ! auto-file-secure "$absolute"; then
    exit 1
fi

if ! auto-root-check $0; then
    printf "Root "
    # exec quotes '$absolute --flag', causing usage error
    # Assigning to cmd works around the problem
    cmd="$absolute $@"
    exec su -m root -c "$cmd"
fi

while true
do
    clear
    auto-admin-banner
    cat << EOM

1.. Restart network
2.. Configure a simple network interface (not LAGG)
3.. Configure LAGG WiFi failover (switch to Ethernet when plugged in)
4.. Configure a basic firewall
Q.. Quit

EOM

    printf "Selection? "
    read resp
    case 0$resp in
    01)
	printf "This will temporarily break all network connections.\n"
	printf "Proceed? y/[n] "
	read proceed
	if [ 0"$proceed" = 0y ]; then
	    auto-network-restart
	    pause
	fi
	;;

    02)
	auto-network-config
	;;

    03)
	auto-wifi-failover
	pause
	;;
    
    04)
	auto-firewall-setup
	pause
	;;
    
    0q)
	break
	;;
    esac
done
