Rev 5273 | 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 VIXubuntu1204LTS_VMcfg package## This script is called from# /etc/kde4/kdm/Xsetup#################################################################################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: 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## 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'luser=""[ -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"if [ "$mode" = "Local Home" ] ; thenok=falseprompt="Local Home with NIS support has been selected\<br>Enter the name of a NIS user and a local home\directory will be created\<br>Cancel to skip this operation"while ! $ok ; doutext=$(kdialog --title "$TITLE" --inputbox "$prompt" "$luser")[[ -z "$utext" ]] && ok=true[[ -n "$utext" && "$utext" =~ ^[a-zA-Z][a-zA-Z0-9_]+$ ]] && ok=truedoneluser="$utext"fiok=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=if [ -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"luser="$luser"hereData################################################################################## Perform the initialisation# 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#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#if $autoHome; thenecho "Setup automount of /home"sed -i /etc/auto.master -e 's~^#/home~/home~'reload autofselseecho "Stop automount of /home"sed -i /etc/auto.master -e 's~^/home~#/home~'restart autofsfi## Create local user if need be#if $addUser; thenkuserfiif [ -n "$luser" ] ; thenuserPath="/home/$luser"if [ ! -d "$userPath" ] ; thenmkdir -p "$userPath"chmod 0777 "$userPath"fifi## Configure the package server# Update the jats.sh for this machine# Update the JATS symlink#jbin="/usr/local/bin/jats"sed -i /etc/profile.d/jats.sh -e "s~^\(GBE_DPKG=/net\)/\([^/]*\)/\(.*\)~\1/$pkgServer/\3~"if [ -L "$jbin" ] ; thennewLink=$(readlink "$jbin" | sed -e "s~\(/net\)/\([^/]*\)/\(.*\)~\1/$pkgServer/\3~")echo $newLinkrm -f "$jbin"ln -s "$newLink" "$jbin"elif [ ! -e "$jbin" ] ; thenln -s /net/$pkgServer/export/devl/core_devl2/TOOLS/jats.sh "$jbin"fi## 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 ] ; thenrm -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 ]; thenrebootfi