blob: 0e112263e269d9bb01e7f1463d7b3f0e59feae0d [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
Mate Lakat0b3804b2013-05-07 16:58:17 +010013set -o errexit
14set -o nounset
John Garbuttdaadf742012-04-27 18:28:28 +010015set -o xtrace
Renuka Aptece59d642012-02-02 16:09:23 -080016
Anthony Youngb62b4ca2011-10-26 22:29:08 -070017# Configurable nuggets
Mate Lakat0b3804b2013-05-07 16:58:17 +010018GUEST_PASSWORD="$1"
19XS_TOOLS_PATH="$2"
20STACK_USER="$3"
Anthony Youngb62b4ca2011-10-26 22:29:08 -070021
Anthony Youngb62b4ca2011-10-26 22:29:08 -070022# Install basics
Mate Lakat0b3804b2013-05-07 16:58:17 +010023apt-get update
24apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool
25apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo
26pip install xenapi
Anthony Youngb62b4ca2011-10-26 22:29:08 -070027
John Garbuttdaadf742012-04-27 18:28:28 +010028# Install XenServer guest utilities
Mate Lakat0b3804b2013-05-07 16:58:17 +010029dpkg -i $XS_TOOLS_PATH
30update-rc.d -f xe-linux-distribution remove
31update-rc.d xe-linux-distribution defaults
Anthony Youngb62b4ca2011-10-26 22:29:08 -070032
33# Make a small cracklib dictionary, so that passwd still works, but we don't
34# have the big dictionary.
Mate Lakat0b3804b2013-05-07 16:58:17 +010035mkdir -p /usr/share/cracklib
36echo a | cracklib-packer
Anthony Youngb62b4ca2011-10-26 22:29:08 -070037
38# Make /etc/shadow, and set the root password
Mate Lakat0b3804b2013-05-07 16:58:17 +010039pwconv
40echo "root:$GUEST_PASSWORD" | chpasswd
Anthony Youngb62b4ca2011-10-26 22:29:08 -070041
42# Put the VPX into UTC.
Mate Lakat0b3804b2013-05-07 16:58:17 +010043rm -f /etc/localtime
Anthony Youngb62b4ca2011-10-26 22:29:08 -070044
45# Add stack user
Mate Lakat0b3804b2013-05-07 16:58:17 +010046groupadd libvirtd
47useradd $STACK_USER -s /bin/bash -d /opt/stack -G libvirtd
48echo $STACK_USER:$GUEST_PASSWORD | chpasswd
49echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Anthony Youngb62b4ca2011-10-26 22:29:08 -070050
51# Give ownership of /opt/stack to stack user
Mate Lakat0b3804b2013-05-07 16:58:17 +010052chown -R $STACK_USER /opt/stack
Anthony Youngb62b4ca2011-10-26 22:29:08 -070053
54# Make our ip address hostnames look nice at the command prompt
Mate Lakat0b3804b2013-05-07 16:58:17 +010055echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> /opt/stack/.bashrc
56echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> /root/.bashrc
57echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> /etc/profile
Anthony Youngb62b4ca2011-10-26 22:29:08 -070058
59function setup_vimrc {
60 if [ ! -e $1 ]; then
61 # Simple but usable vimrc
62 cat > $1 <<EOF
63syntax on
64se ts=4
65se expandtab
66se shiftwidth=4
67EOF
68 fi
69}
70
71# Setup simple .vimrcs
Mate Lakat0b3804b2013-05-07 16:58:17 +010072setup_vimrc /root/.vimrc
73setup_vimrc /opt/stack/.vimrc
John Garbuttdaadf742012-04-27 18:28:28 +010074
75# remove self from local.rc
76# so this script is not run again
77rm -rf /etc/rc.local
Mate Lakat0b3804b2013-05-07 16:58:17 +010078
79# Restore rc.local file
80cp /etc/rc.local.preparebackup /etc/rc.local
John Garbuttdaadf742012-04-27 18:28:28 +010081
82# shutdown to notify we are done
83shutdown -h now