Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristopolous/d3211dfb395bbb922fee14665dd941cb to your computer and use it in GitHub Desktop.
Save kristopolous/d3211dfb395bbb922fee14665dd941cb to your computer and use it in GitHub Desktop.
#/bin/bash
# /etc/init.d/xdm: Login Procedure for Bob480
# Edited Sept-2001; Contact Author: cjm@ucdavis.edu
n=$1
n=$n"."
[ $n == "stop." ] && exit
moveon=0
set PATH="/bin:/usr/bin:/sbin"
############# ISIP - Test Validity of IP Address
# $1 - IP Address
function isip() {
ifs="."
[ $# -ne "4" ] && echo "Not a valid IP address." && return 0
[ $1 -gt "255" ] && echo "First 8-bit is invalid." && return 0
[ $2 -gt "255" ] && echo "Second 8-bit is invalid." && return 0
[ $3 -gt "255" ] && echo "Third 8-bit is invalid." && return 0
[ $4 -gt "255" ] && echo "Fourth 8-bit is invalid." && return 0
}
############# GETANSWER - Get User Input
function getanswer() {
echo -n ">> "
read answer
if [ $answer == "[Qq]uit" ]; then
echo "Quitting and starting login daemon."
exit 0
fi
}
############# MANUAL CONF - Manual Configuration
function manualconf() {
cat << EOF
If you are on a local network then I can try to configure myself automagically,
although it may take about 5 to 10 minutes and I may not succeed. Would you
like to try to auto configure
EOF
getanswer
case $answer in
quit) exit 0
;;
y|Y|yes|Yes|YES) autoconf
;;
*) true
;;
esac
cat << EOF
What method of connecting to the remote host would you like to use?
1. VNC
2. Query
3. Broadcast
EOF
getanswer
method=$answer
case $method in
1|Vnc|VNC) method="vnc"
;;
2|Query|QUERY) method="query"
;;
3|Broadcast|BROADCAST) method="broadcast"
;;
*) echo "Invalid Selection"
;;
esac
echo "ifconfig -a shows the following devices:"
ifconfig -a
echo "Which device would you like to use"
getanswer
device=$answer
while [ $moveon -ne "1" ]; do
echo "Enter Remote IP Address"
getanswer
moveon = `isip answer`
done
moveon=0
while [ $moveon -ne "1" ]; do
echo "Enter Local IP Address"
getanswer
moveon = `isip answer`
done
moveon=0
ifconfig $device $local
ip=` route -n | tail -1 | awk ' { print $2 } '`
num=`ping -c 4 $ip | wc -l`
}
################## AUTO CONF
function autoconf() {
echo "This is just a stub now...automatic configuration is not programmed yet."
}
function defaultconf() {
findvalue remote && remote=findvar;
findvalue local && local=findvar;
findvalue device && device=findvar;
findvalue gateway && gateway=findvar;
findvalue netmask && netmask=findvar;
echo "Setting local IP address to "$local" on "$device"."
ifconfig $device $local netmask $netmask
echo "Setting gateway to "$gateway"."
route delete default eth0
route add default $gateway
}
function remoteip() {
echo "Verifying remote IP address..."
num=`ping -c 5 $remote | wc -l`
if [ $num -ne "9" ]; then
echo "There was an error contacting the remote IP address."
while [ $moveon -ne "1" ]; do
echo "Enter Remote IP Address"
getanswer
moveon=`isip $answer`
done
fi
}
remoteip
function findvalue() {
findvar=`cat /etc/remoteinfo | grep -v "#" | grep $1 | awk ' { print $2 } '`
}
function gwtest() {
echo "Verifying Gateway..."
while [ $num -ne "9" ]; do
echo -n "Gateway isn't working."
while [ $moveon -ne "1" ]; do
echo "Please enter gateway address"
getanswer
moveon=`isip $answer`
done
moveon=0
route delete gw eth0
route add default gw $ip
ip=`route -n | tail -1 | awk ' { print $2 } '`
num=`ping -c 4 $ip | wc -l`
done
}
cat << EOF
What would you like to do?
1. Connect Remotely
2. Login
EOF
getanswer
[ $answer == "2" ] && exit 0
cat /etc/remoteinfo
echo -n "Use these values"
getanswer
case $answer in
y|Y|yes|Yes|YES) defaultconf
;;
n|N|no|No|NO) echo hi;manualconf
;;
*) echo "I couldn't figure out your answer so I will quit the program and give you a login screen."
exit 0
;;
esac
gwtest
cat << EOF
Remote IP = $remote
Local IP = $local
Device = $device
Gateway = $gateway
Netmask = $netmask
All configuration complete.
Would you like to write the information to /etc/remoteinfo
EOF
getanswer
case $answer in
y|Y|yes|Yes|YES) cat /etc/remoteinfo | grep # > /tmp/remote
cat >> /tmp/remote << EOF
remote=$remote
local=$local
device=$device
gateway=$gateway
netmask=$netmask
EOF
mv /tmp/remote /etc/remoteinfo
;;
*)
;;
esac
echo "Would you like to continue"
getanswer
case $answer in
y|Y|yes|YES|Yes)
;;
*) exit 0
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment