#!/bin/bash # Workstation Autoconfiguration Script v1.0 by Simón A. Ruiz (simon.a.ruiz@gmail.com) # # This script is designed to be run the first time a newly re-imaged # workstation is booted up, which should be immediately following the boot # process. It is called by /etc/rc.local when appropriate. # It relies on information from http://nordx-server/workstations.csv to # determine what needs to be done. # LOGFILE=/home/administrator/scripts/autoconfig.log # First, let's determine where we are by searching for our MAC address # in the workstation information file, and pass that information into usable # variables. MAC=`ifconfig | grep -m 1 HWaddr | awk -F 'HWaddr ' '{ print $2 }'` wget http://nordx-server/workstations.csv CSVLINE=`grep $MAC workstations.csv` NEWNAME=`echo $CSVLINE | awk -F ',' '{ print $2 }'` CLASSROOM=`echo $CSVLINE | awk -F ',' '{ print $3 }'` WORKSTATION=`echo $CSVLINE | awk -F ',' '{ print $4 }'` rm workstations.csv echo "* We are $NEWNAME, located in $CLASSROOM, workstation number $WORKSTATION" >> $LOGFILE # Let's rename this workstation both for Linux and for Samba sed -e "s/nordx--image/$NEWNAME/" /etc/samba/smb.conf > /tmp/smb.conf mv /tmp/smb.conf /etc/samba/smb.conf echo "* Renamed Samba Hostname (/etc/samba/smb.conf)" >> $LOGFILE sed -e "s/nordx--image/$NEWNAME/" /etc/hostname > /tmp/hostname mv /tmp/hostname /etc/hostname sed -e "s/nordx--image/$NEWNAME/" /etc/hosts > /tmp/hosts mv /tmp/hosts /etc/hosts echo "* Renamed Local Hostname to $NEWNAME" >> $LOGFILE # Now, let's configure the printer (We already have one installed) based # on the classroom number. # # The optimal way of doing this would be to install the printer here, but # I was not able to figure out how to do that from the bash shell, so this is # the simplest solution I could come up with at the time. case $CLASSROOM in 605) lpadmin -x LaserJet-2420 ; echo "* LaserJet-2420 removed" >> $LOGFILE lpadmin -p LaserJet-P3005 -v socket://10.100.1.167:9100 ; echo "* LaserJet-P3005 assigned to socket://10.100.1.167:9100" >> $LOGFILE lpadmin -d LaserJet-P3005 ; echo "* LaserJet-P3005 set as default" >> $LOGFILE ;; 607) lpadmin -x LaserJet-2420 ; echo "* LaserJet-2420 removed" >> $LOGFILE lpadmin -p LaserJet-P3005 -v socket://10.100.1.166:9100 ; echo "* LaserJet-P3005 assigned to socket://10.100.1.166:9100" >> $LOGFILE lpadmin -d LaserJet-P3005 ; echo "* LaserJet-P3005 set as default" >> $LOGFILE ;; 608) lpadmin -x LaserJet-P3005 ; echo "* LaserJet-P3005 removed" >> $LOGFILE lpadmin -p LaserJet-2420 -v socket://10.100.1.147:9100 ; echo "* LaserJet-2420 assigned to socket://10.100.1.147:9100" >> $LOGFILE lpadmin -d LaserJet-2420 ; echo "* LaserJet-2420 set as default" >> $LOGFILE ;; 609) lpadmin -x LaserJet-P3005 ; echo "* LaserJet-P3005 removed" >> $LOGFILE lpadmin -p LaserJet-2420 -v socket://10.100.1.146:9100 ; echo "* LaserJet-2420 assigned to socket://10.100.1.146:9100" >> $LOGFILE lpadmin -d LaserJet-2420 ; echo "* LaserJet-2420 set as default" >> $LOGFILE ;; 610) lpadmin -x LaserJet-P3005 ; echo "* LaserJet-P3005 removed" >> $LOGFILE lpadmin -p LaserJet-2420 -v socket://10.100.1.145:9100 ; echo "* LaserJet-2420 assigned to socket://10.100.1.145:9100" >> $LOGFILE lpadmin -d LaserJet-2420 ; echo "* LaserJet-2420 set as default" >> $LOGFILE ;; 611) lpadmin -x LaserJet-P3005 ; echo "* LaserJet-P3005 removed" >> $LOGFILE lpadmin -p LaserJet-2420 -v socket://10.100.1.144:9100 ; echo "* LaserJet-2420 assigned to socket://10.100.1.144:9100" >> $LOGFILE lpadmin -d LaserJet-2420 ; echo "* LaserJet-2420 set as default" >> $LOGFILE ;; 612) lpadmin -x LaserJet-2420 ; echo "* LaserJet-2420 removed" >> $LOGFILE lpadmin -p LaserJet-P3005 -v socket://10.100.1.164:9100 ; echo "* LaserJet-P3005 assigned to socket://10.100.1.164:9100" >> $LOGFILE lpadmin -d LaserJet-P3005 ; echo "* LaserJet-P3005 set as default" >> $LOGFILE ;; 613) lpadmin -x LaserJet-2420 ; echo "* LaserJet-2420 removed" >> $LOGFILE lpadmin -p LaserJet-P3005 -v socket://10.100.1.163:9100 ; echo "* LaserJet-P3005 assigned to socket://10.100.1.163:9100" >> $LOGFILE lpadmin -d LaserJet-P3005 ; echo "* LaserJet-P3005 set as default" >> $LOGFILE ;; 616) lpadmin -x LaserJet-2420 ; echo "* LaserJet-2420 removed" >> $LOGFILE lpadmin -p LaserJet-P3005 -v socket://10.100.1.162:9100 ; echo "* LaserJet-P3005 assigned to socket://10.100.1.162:9100" >> $LOGFILE lpadmin -d LaserJet-P3005 ; echo "* LaserJet-P3005 set as default" >> $LOGFILE ;; lap) echo "As this is a laptop, we don't need to modify any printers" >> $LOGFILE ;; *) echo "There is no printer defined for this classroom" >> $LOGFILE ;; esac # Destroy the teacher account, unless we're at the teacher's workstation. # If we are at the teacher workstation, then someone will need to manually # setup iTALC here after we're done. if [ $WORKSTATION != 0 ] then deluser --remove-all-files teacher echo "* Removed the teacher account" >> $LOGFILE else echo "* We need to set up this teacher account" >> $LOGFILE fi # Synchronize the clock, and change the hardware clock to reflect the new time. ntpdate ntp.indiana.edu hwclock -w # And we're done configuring! echo "* Done!" >> $LOGFILE # Now let's shutdown, because the Imaging process usually starts at the end # of the day, and it's likely that noone's around to need us on anymore. shutdown -h now exit 0