blob: 4aa4554f8f1374e72d9ccb220e9d9df32571a95d [file] [log] [blame]
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001#!/bin/bash
2
John Garbuttdaadf742012-04-27 18:28:28 +01003# 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 Aptece59d642012-02-02 16:09:23 -080013set -x
John Garbuttdaadf742012-04-27 18:28:28 +010014# Echo commands
15set -o xtrace
Renuka Aptece59d642012-02-02 16:09:23 -080016
Anthony Youngb62b4ca2011-10-26 22:29:08 -070017# Configurable nuggets
Anthony Young3eb8f592011-10-26 23:11:52 -070018GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
Anthony Youngb62b4ca2011-10-26 22:29:08 -070019STAGING_DIR=${STAGING_DIR:-stage}
20DO_TGZ=${DO_TGZ:-1}
John Garbuttb6c87142012-08-02 12:34:03 +010021XS_TOOLS_PATH=${XS_TOOLS_PATH:-"/root/xs-tools.deb"}
Anthony Youngb62b4ca2011-10-26 22:29:08 -070022
Anthony Youngb62b4ca2011-10-26 22:29:08 -070023# Install basics
24chroot $STAGING_DIR apt-get update
Anthony Youngb62b4ca2011-10-26 22:29:08 -070025chroot $STAGING_DIR apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool
26chroot $STAGING_DIR apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo
27chroot $STAGING_DIR pip install xenapi
28
John Garbuttdaadf742012-04-27 18:28:28 +010029# Install XenServer guest utilities
John Garbuttb6c87142012-08-02 12:34:03 +010030cp $XS_TOOLS_PATH ${STAGING_DIR}${XS_TOOLS_PATH}
31chroot $STAGING_DIR dpkg -i $XS_TOOLS_PATH
Anthony Youngb62b4ca2011-10-26 22:29:08 -070032chroot $STAGING_DIR update-rc.d -f xe-linux-distribution remove
33chroot $STAGING_DIR update-rc.d xe-linux-distribution defaults
34
35# Make a small cracklib dictionary, so that passwd still works, but we don't
36# have the big dictionary.
37mkdir -p $STAGING_DIR/usr/share/cracklib
38echo a | chroot $STAGING_DIR cracklib-packer
39
40# Make /etc/shadow, and set the root password
41chroot $STAGING_DIR "pwconv"
Anthony Young3eb8f592011-10-26 23:11:52 -070042echo "root:$GUEST_PASSWORD" | chroot $STAGING_DIR chpasswd
Anthony Youngb62b4ca2011-10-26 22:29:08 -070043
44# Put the VPX into UTC.
45rm -f $STAGING_DIR/etc/localtime
46
47# Add stack user
48chroot $STAGING_DIR groupadd libvirtd
49chroot $STAGING_DIR useradd stack -s /bin/bash -d /opt/stack -G libvirtd
Anthony Young3eb8f592011-10-26 23:11:52 -070050echo stack:$GUEST_PASSWORD | chroot $STAGING_DIR chpasswd
Anthony Youngb62b4ca2011-10-26 22:29:08 -070051echo "stack ALL=(ALL) NOPASSWD: ALL" >> $STAGING_DIR/etc/sudoers
52
53# Give ownership of /opt/stack to stack user
54chroot $STAGING_DIR chown -R stack /opt/stack
55
56# Make our ip address hostnames look nice at the command prompt
57echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/opt/stack/.bashrc
58echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/root/.bashrc
59echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/etc/profile
60
61function setup_vimrc {
62 if [ ! -e $1 ]; then
63 # Simple but usable vimrc
64 cat > $1 <<EOF
65syntax on
66se ts=4
67se expandtab
68se shiftwidth=4
69EOF
70 fi
71}
72
73# Setup simple .vimrcs
74setup_vimrc $STAGING_DIR/root/.vimrc
75setup_vimrc $STAGING_DIR/opt/stack/.vimrc
76
77if [ "$DO_TGZ" = "1" ]; then
78 # Compress
79 rm -f stage.tgz
80 tar cfz stage.tgz stage
81fi
John Garbuttdaadf742012-04-27 18:28:28 +010082
83# remove self from local.rc
84# so this script is not run again
85rm -rf /etc/rc.local
86mv /etc/rc.local.preparebackup /etc/rc.local
87cp $STAGING_DIR/etc/rc.local $STAGING_DIR/etc/rc.local.backup
88
89# shutdown to notify we are done
90shutdown -h now