Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 3 | # This script is run on an Ubuntu VM. |
| 4 | # This script is inserted into the VM by prepare_guest_template.sh |
| 5 | # and is run when that VM boots. |
| 6 | # It customizes a fresh Ubuntu install, so it is ready |
| 7 | # to run stack.sh |
| 8 | # |
| 9 | # This includes installing the XenServer tools, |
| 10 | # creating the user called "stack", |
| 11 | # and shuts down the VM to signal the script has completed |
| 12 | |
Renuka Apte | ce59d64 | 2012-02-02 16:09:23 -0800 | [diff] [blame] | 13 | set -x |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 14 | # Echo commands |
| 15 | set -o xtrace |
Renuka Apte | ce59d64 | 2012-02-02 16:09:23 -0800 | [diff] [blame] | 16 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 17 | # Configurable nuggets |
Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 18 | GUEST_PASSWORD=${GUEST_PASSWORD:-secrete} |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 19 | STAGING_DIR=${STAGING_DIR:-stage} |
| 20 | DO_TGZ=${DO_TGZ:-1} |
John Garbutt | b6c8714 | 2012-08-02 12:34:03 +0100 | [diff] [blame] | 21 | XS_TOOLS_PATH=${XS_TOOLS_PATH:-"/root/xs-tools.deb"} |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 22 | STACK_USER=${STACK_USER:-stack} |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 23 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 24 | # Install basics |
| 25 | chroot $STAGING_DIR apt-get update |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 26 | chroot $STAGING_DIR apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool |
| 27 | chroot $STAGING_DIR apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo |
| 28 | chroot $STAGING_DIR pip install xenapi |
| 29 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 30 | # Install XenServer guest utilities |
John Garbutt | b6c8714 | 2012-08-02 12:34:03 +0100 | [diff] [blame] | 31 | cp $XS_TOOLS_PATH ${STAGING_DIR}${XS_TOOLS_PATH} |
| 32 | chroot $STAGING_DIR dpkg -i $XS_TOOLS_PATH |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 33 | chroot $STAGING_DIR update-rc.d -f xe-linux-distribution remove |
| 34 | chroot $STAGING_DIR update-rc.d xe-linux-distribution defaults |
| 35 | |
| 36 | # Make a small cracklib dictionary, so that passwd still works, but we don't |
| 37 | # have the big dictionary. |
| 38 | mkdir -p $STAGING_DIR/usr/share/cracklib |
| 39 | echo a | chroot $STAGING_DIR cracklib-packer |
| 40 | |
| 41 | # Make /etc/shadow, and set the root password |
| 42 | chroot $STAGING_DIR "pwconv" |
Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 43 | echo "root:$GUEST_PASSWORD" | chroot $STAGING_DIR chpasswd |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 44 | |
| 45 | # Put the VPX into UTC. |
| 46 | rm -f $STAGING_DIR/etc/localtime |
| 47 | |
| 48 | # Add stack user |
| 49 | chroot $STAGING_DIR groupadd libvirtd |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 50 | chroot $STAGING_DIR useradd $STACK_USER -s /bin/bash -d /opt/stack -G libvirtd |
| 51 | echo $STACK_USER:$GUEST_PASSWORD | chroot $STAGING_DIR chpasswd |
| 52 | echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> $STAGING_DIR/etc/sudoers |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 53 | |
| 54 | # Give ownership of /opt/stack to stack user |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 55 | chroot $STAGING_DIR chown -R $STACK_USER /opt/stack |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 56 | |
| 57 | # Make our ip address hostnames look nice at the command prompt |
| 58 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/opt/stack/.bashrc |
| 59 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/root/.bashrc |
| 60 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/etc/profile |
| 61 | |
| 62 | function setup_vimrc { |
| 63 | if [ ! -e $1 ]; then |
| 64 | # Simple but usable vimrc |
| 65 | cat > $1 <<EOF |
| 66 | syntax on |
| 67 | se ts=4 |
| 68 | se expandtab |
| 69 | se shiftwidth=4 |
| 70 | EOF |
| 71 | fi |
| 72 | } |
| 73 | |
| 74 | # Setup simple .vimrcs |
| 75 | setup_vimrc $STAGING_DIR/root/.vimrc |
| 76 | setup_vimrc $STAGING_DIR/opt/stack/.vimrc |
| 77 | |
| 78 | if [ "$DO_TGZ" = "1" ]; then |
| 79 | # Compress |
| 80 | rm -f stage.tgz |
| 81 | tar cfz stage.tgz stage |
| 82 | fi |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 83 | |
| 84 | # remove self from local.rc |
| 85 | # so this script is not run again |
| 86 | rm -rf /etc/rc.local |
| 87 | mv /etc/rc.local.preparebackup /etc/rc.local |
| 88 | cp $STAGING_DIR/etc/rc.local $STAGING_DIR/etc/rc.local.backup |
| 89 | |
| 90 | # shutdown to notify we are done |
| 91 | shutdown -h now |