#/bin/bash
#Clear the screen, reads easier
clear

#Check if ncpmount exists.
if test ! -e /usr/bin/ncpmount
	then echo "ncpmount isn't found, check if it exists in /usr/bin/ncpmount"
else
	echo "ncpmount exist"
fi

#Check if ncpmount is executable.
if test ! -x /usr/bin/ncpmount 
	then echo "ncpmount isn't executable" 
	echo "login as root and enter the next command"
	echo "chmod 4755 /usr/bin/ncpmount" 
	echo "Script will be exited"
	exit
else
	echo "ncpmount is executable, so we will continue"
fi

#Ask questions
		echo "Enter the name of the server, the folder that will be created will have the same name"
	read NWSVR
		echo "Enter the IP Address, example 192.169.1.1"
	read NWIP
		echo "Enter your full loginname, begin with a leading period, example .jdoe.test.name"
	read NWUSER
echo "Please check for errors"
sleep 3


#Clean screen again
clear
echo Your servername is $NWSVR
echo The IP address of your server is $NWIP
echo Your username is $NWUSER

#Let the user check the answers

agreed=
    while [ -z "$agreed" ]; do
        echo
        echo "Is the entered information correct? [yes or no]"
        read reply leftover
        case $reply in
            y* | Y* | j* | J* )
                agreed=1
                echo "Next we will try to make a connection"
		;; 
            n* | N*)
                echo "Please restart ";
                exit 1
                ;;
        esac
done
#Check if directory exists
if [ -d ~/$NWSVR ]
	then echo "Folder $NWSVR exists, we will use this folder" 
else
mkdir ~/$NWSVR
	echo "Folder doesn't exist, but we made one"
fi

#Here we go, cross your fingers
ncpmount -S $NWSVR -A $NWIP -U $NWUSER -m ~/$NWSVR

ls ~/$NWSVR

