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 | |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 13 | set -o errexit |
| 14 | set -o nounset |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 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 |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 18 | GUEST_PASSWORD="$1" |
| 19 | XS_TOOLS_PATH="$2" |
| 20 | STACK_USER="$3" |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 21 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 22 | # Install basics |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 23 | apt-get update |
| 24 | apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool |
Mate Lakat | f34cb85 | 2013-07-12 17:11:07 +0100 | [diff] [blame] | 25 | apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo python-netaddr |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 26 | pip install xenapi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 27 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 28 | # Install XenServer guest utilities |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 29 | dpkg -i $XS_TOOLS_PATH |
| 30 | update-rc.d -f xe-linux-distribution remove |
| 31 | update-rc.d xe-linux-distribution defaults |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 32 | |
| 33 | # Make a small cracklib dictionary, so that passwd still works, but we don't |
| 34 | # have the big dictionary. |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 35 | mkdir -p /usr/share/cracklib |
| 36 | echo a | cracklib-packer |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 37 | |
| 38 | # Make /etc/shadow, and set the root password |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 39 | pwconv |
| 40 | echo "root:$GUEST_PASSWORD" | chpasswd |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 41 | |
| 42 | # Put the VPX into UTC. |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 43 | rm -f /etc/localtime |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 44 | |
| 45 | # Add stack user |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 46 | groupadd libvirtd |
| 47 | useradd $STACK_USER -s /bin/bash -d /opt/stack -G libvirtd |
| 48 | echo $STACK_USER:$GUEST_PASSWORD | chpasswd |
| 49 | echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 50 | |
Mate Lakat | b1dc9bd | 2013-08-29 11:52:20 +0100 | [diff] [blame] | 51 | # Add an udev rule, so that new block devices could be written by stack user |
| 52 | cat > /etc/udev/rules.d/50-openstack-blockdev.rules << EOF |
| 53 | KERNEL=="xvd[b-z]", GROUP="$STACK_USER", MODE="0660" |
| 54 | EOF |
| 55 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 56 | # Give ownership of /opt/stack to stack user |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 57 | chown -R $STACK_USER /opt/stack |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 58 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 59 | function setup_vimrc { |
| 60 | if [ ! -e $1 ]; then |
| 61 | # Simple but usable vimrc |
| 62 | cat > $1 <<EOF |
| 63 | syntax on |
| 64 | se ts=4 |
| 65 | se expandtab |
| 66 | se shiftwidth=4 |
| 67 | EOF |
| 68 | fi |
| 69 | } |
| 70 | |
| 71 | # Setup simple .vimrcs |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 72 | setup_vimrc /root/.vimrc |
| 73 | setup_vimrc /opt/stack/.vimrc |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 74 | |
| 75 | # remove self from local.rc |
| 76 | # so this script is not run again |
| 77 | rm -rf /etc/rc.local |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 78 | |
| 79 | # Restore rc.local file |
| 80 | cp /etc/rc.local.preparebackup /etc/rc.local |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 81 | |
| 82 | # shutdown to notify we are done |
| 83 | shutdown -h now |