Blame | 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 VIXcentos7LTS_VMcfg package## This script is called from# /etc/gdm/Init/:0################################################################################## 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: vixPassword: 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: auperaarc01 [Perth Based Development]auperaarc02 [Pulse]It is expected that dpkg_archive will be found at:/net/PackageServerName/export/devl/dpkg_archiveAdditional Notes:* Kedevelop 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#GdmBannerFile=/etc/dconf/db/gdm.d/01-banner-messagekdeScriptCfg=/.kde/share/config/configureVMif [ "$startupMode" = "install" ] ; thenln -s $0 /root/Desktop/configureVMrm -f /root/.vix/configcreateHelpTextrm -f $kdeScriptCfgexit 0elif [ "$startupMode" = "remove" ] ; thenrm -f /root/Desktop/configureVM*rm -rf /root/.vixrm -f $kdeScriptCfgrm -f $GdmBannerFileexit 0fi## Non Manual: Only run once#if [ -z "$startupMode" -a -f /root/.vix/config ]; then## Non Manual: After first time## Display the OS Type# Machine Name# IP Address## Allows users to determine the IP address to:# Simplify ssh access# Show when it does not have an IP address## Note: Under Centos we can't pop up a dialog at this point as it will stall the logon# process and prevent users from accessing the box via ssh## Under Centos we update the Greeter banner instead#IP=$(/sbin/ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{ print $2 }' )OS=$(hostnamectl | grep Operating | sed -e 's/.*: //')KERN=$(hostnamectl | grep Kernel| sed -e 's/.*: //')TEXT="Host Name: $(hostname)\\nOS: $OS\\nKernel: $KERN\\nIP Address: $IP"cat << EOF > $GdmBannerFile[org/gnome/login-screen]banner-message-enable=truedisable-user-list=truebanner-message-text='$TEXT'EOFdconf update# text="#OS Version: ${OS}#Kernel: ${KERN}#HostName: $(hostname)#IP address: $ipaddress##Continue to login"# # May create /.kde/share/config/configureVM ($kdeScriptCfg)# kdialog --msgbox "$text" --dontagain configureVM:noipaddressmsgexitfirm -f $kdeScriptCfg## 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='auperaarc02'[ -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_hostsrm -f /root/.svnfi## Set new machine name#echo $mname > /etc/hostnamehostname -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 /usr/lib/systemd/system/ypbind.overridefor ii in passwd shadow group ; dosed -i /etc/$ii -e "/^+/d"echo >> /etc/$ii '+'donesystemctl enable ypbindsystemctl start ypbindelseecho "Disable yp binding"for ii in passwd shadow group; dosed -i /etc/$ii -e "/^+/d"donesystemctl disable ypbindfi## 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 rebootsystemctl stop autofs## 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; then/usr/bin/python /usr/share/system-config-users/system-config-users.pyfi## 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"reboot --no-wall -fecho "Reboot failed. Command returned"fiecho "Script complete"