#Clear screen on startup
clear
#Functions
NetCheck(){
    unset counter
    while [[ $counter -lt 3 && "$Net" = "false" ]]
    do
    sleep 5
    ping -q -c1 ictmaatwerk.com &>/dev/null && Net=true || Net=false
    counter=$(( $counter + 1 ))
    done
}

#Check for network
echo "Waiting for network"
ping -q -c1 google.com &>/dev/null && Net=true || Net=false
#If no network enter wait loop
NetCheck

#Check for manual retry for netwerk
while [[ "$Net" = "false" ]]; do
    read -p "Network could not be initialized, Try again (y/n) " yn
    case $yn in 
        [yY]* ) NetCheck;;
        [Nn]* ) break;;
        * ) echo invalid response;;
    esac
done

#Check if video and network are ok, else error out
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]] && [[ "$Net" = "true" ]]; then
    echo "Loading, please wait..."
    exec startx >/dev/null 2>&1
else
    echo "System could not be initialized, exited"
    sleep 10000
fi