Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/bin/bash################################################################################# This file is to be run by root# It is used to configure a new VM on first boot## Source is controlled in the VIXubuntu1404LTS_VMcfg package## This script is called from# /usr/share/lightdm/lightdm.conf.d/50-vix-hook.conf################################################################################## Log all outputmkdir -p /root/.vixexec 1>/root/.vix/vix.log 2>&1echo Starting $*mkdir -p /root/DesktopHelpFile="/root/Desktop/configureVM Help.txt"function createHelpText {cat > "$HelpFile" <<HelpDocInitial Machine SetupThis process will setup the VM.It will be performed once, but can be manually rerun via $0This text file can be found at: "$HelpFile"Use Information:Root Password: maple01Local User: UbuntuPassword: maple01Machine Name:This should be globally unique so as to avoid problems with IP addressassignment. The recommended name is based on:1) Your Desktop machine Name. ie AUPERAWS1232) The number of VMs that you already have createdie: AUPERAWS123VM01Configuration:Automount home driversIntended for a Virtual Machine based in Perth attached to the Perth Unixhome drives. Use outside of Perth may suffer performance delaysLocal HomeIntended for a VM not based in Perth, but aware of the Perth VIX NIS. Themachine will have a local home drive, but will use the Perth VIX NIS.A local home directory will be configured. The user will authenicate againstthe NIS, but use the local home drive.Stand Alone:Intended for a Virtual Machine that will not be attached to the Perth filesystem. This type of machine will require that the user set up anon-root user.Package Server:This is the name of the build system package server. It will be used to:1) Provide the location of JATS2) Provide dpkg_archiveExample: auperaarc01It is expected that dpkg_archive will be found at:/net/PackageServerName/export/devl/dpkg_archiveAdditional Notes:* Kdbg has been installed. This is a GUI interface to GDBHelpDoc}## Examine user commandline.# Expect one of# -install - Used by installer# -remove - Used by installer# -auto - Invoked by startup at boot# - User invocation#startupMode=Nofor ii in $*; do[ "$ii" = "-auto" ] && startupMode=[ "$ii" = "-install" ] && startupMode=install[ "$ii" = "-remove" ] && startupMode=removedone## Self install and removal# Normally run from the installer#if [ "$startupMode" = "install" ] ; thenln -s $0 /root/Desktop/configureVMrm -f /root/.vix/configcreateHelpTextexit 0elif [ "$startupMode" = "remove" ] ; thenrm -f /root/Desktop/configureVM*rm -rf /root/.vixexit 0fi## Non Manual: Only run once#[ -z "$startupMode" -a -f /root/.vix/config ] && exit## Running full script# Perform full logging to another log filemkdir -p /root/.vixexec 1>/root/.vix/vix_full.log 2>&1echo Starting $*envset -x## Create the Help Text# Place link to this script on the Desktop#[ -e /root/Desktop/configureVM ] || /root/Desktop/configureVMcreateHelpText## Extract information from the user##TITLE='First Time VM Configuration'## Display the Help Text#kdialog --title "$TITLE" --textbox "${HelpFile}" 800 800## Set defaults, before overiding with users last values#mname=$(cat /etc/hostname)mode='Automount home drives'pkgServer='auperaarc01'[ -f /root/.vix/config.data ] && source /root/.vix/config.dataok=falseprompt="Unique machine name\<pre>Suggested format: AUPERAWSxxxVMnn\<br>Where:\<br> AUPERA - Site prefix\<br> WSxxx - Your Workstation ID\<br> VM - Indicated a VM\<br> nn - VM Instance\</pre>Machine Name:"while ! $ok ; do[ -z "$mname" ] && mname=AUPERAWSxxxVMnnmname=$(kdialog --title "$TITLE" --inputbox "$prompt" "$mname")[[ $mname =~ ^[a-zA-Z][a-zA-Z0-9-]+$ ]] && ok=true[[ $mname =~ AUPERAWSx ]] && ok=false[[ $mname =~ VMnn ]] && ok=falsedoneok=falseprompt="<pre>Stand Alone VM: No NIS, Setup local user\<br>Local Home: Use NIS, Setup local home\<br>Automount home drives: Use NIS, Mount Unix Home Drive\</pre>Select configuration:"while ! $ok ; doumode=$(kdialog --title "$TITLE" --combobox "$prompt" \'Stand Alone VM' \'Local Home' \'Automount home drives' \--default "$mode" )[ -n "$umode" ] && ok=truedonemode="$umode"ok=falseutext=""prompt="The name of the build system package server\<br>Package Server:"while ! $ok ; do[ -z "$utext" ] && utext="$pkgServer"utext=$(kdialog --title "$TITLE" --inputbox "$prompt" "$utext")[[ "$utext" =~ ^[a-zA-Z][a-zA-Z0-9_-]+$ ]] && ok=truedonepkgServer="$utext"erase=1if [ -n "$startupMode" ]; thenkdialog --title "$TITLE" --yesno \"This utility is being manually run.<br>\Do you want to force the script to be run on the next reboot"erase=$?fi## Save config for next time#echo $mnameecho $modeecho $pkgServermkdir -p /root/.vixcat > /root/.vix/config.data <<hereDatamname="$mname"mode="$mode"pkgServer="$pkgServer"hereData################################################################################## Perform the initialisation#echo "--------------------------------"echo "Data collected. Configure system"# Extend the pathPATH="/sbin:$PATH"# Machine-specific, so remove in case this system is going to be# cloned. These will be regenerated on the first boot.if [ -z "$startupMode" ] ; thenrm -f /etc/udev/rules.d/70-persistent-cd.rulesrm -f /etc/udev/rules.d/70-persistent-net.rules# Potentially sensitive.rm -f /root/.ssh/known_hostssed -i /etc/apt/apt.conf -e 's~http://.*@proxy~http://username:password@proxy~'fi## Set new machine name#echo $mname > /etc/hostnamesed -i /etc/hosts -e "s~^127\.0\.1\.1.*~127.0.1.1\t$mname~"hostname -b -F /etc/hostname## Set the required Mode#autoHome=falseperthNis=falseaddUser=falseif [ "$mode" = "Stand Alone VM" ] ; thenautoHome=falseperthNis=falseaddUser=trueelif [ "$mode" = "Local Home" ] ; thenautoHome=falseperthNis=trueelseautoHome=trueperthNis=truefi## Configure NIS#echo "Configure NIS"if $perthNis; thenecho "Enable yp binding"rm -f /etc/init/ypbind.override[ -f /etc/defaultdomain.saved ] && mv /etc/defaultdomain.saved /etc/defaultdomainstart ypbindfor ii in passwd shadow group ; dosed -i /etc/$ii -e "/^+/d"echo >> /etc/$ii '+'doneelseecho "Disable yp binding"stop ypbindecho 'manual' > /etc/init/ypbind.override[ -f /etc/defaultdomain ] && mv /etc/defaultdomain /etc/defaultdomain.savedfor ii in passwd shadow group; dosed -i /etc/$ii -e "/^+/d"donefi## Configure auto mounting of Home Drives#echo "Configure Automounter"VIXAUTOHOME=/etc/auto.master.d/vix.home.autofsif $autoHome; thenecho "Setup automount of /home"if [ -f ${VIXAUTOHOME}.disabled ] ; thenmv ${VIXAUTOHOME}.disabled ${VIXAUTOHOME}fielseecho "Stop automount of /home"if [ -f ${VIXAUTOHOME} ] ; thenmv ${VIXAUTOHOME} ${VIXAUTOHOME}.disabledfifi## Stop auto mounter so that it will not interfere with the# creation of user home directories## Note: This does not appear to stop the automounter# May not be an issue as we are about to reboot/etc/init.d/autofs stop## Create local user if need be# Note: There is no need to create a local home directory for local users# as Ubuntu appears to do this on the fly.#echo "Configure Local User"if $addUser; thenkuser "--title=Configure local user" "--caption=Don't forget the passwd"fi## Configure the package server#echo "Configure Package Server"sed -i /etc/profile.d/jats.sh -e "s~^\(GBE_DPKG=/net\)/\([^/]*\)/\(.*\)~\1/$pkgServer/\3~"## Flag - configuration done# This should stop the auto script from running again#if [ -z "$startupMode" ]; thenecho "Flag - don't run again"mkdir -p /root/.vixtouch /root/.vix/configfiif [ "$erase" -eq "0" ] ; thenecho "Erase config details. Force script to run on next reboot"rm -f /root/.vix/configfi## Reboot the system# If manually invoked then give the user the option of aborting the boot#ktype=yesno[ -z "$startupMode" ] && ktype=msgboxkdialog --title "$TITLE" --$ktype "The system will now reboot in order for the changes to take effect"if [ $? -ne 1 ]; thenecho "Reboot the system"rebootecho "Reboot failed. Command returned"fiecho "Script complete"