Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Renuka Apte | ce59d64 | 2012-02-02 16:09:23 -0800 | [diff] [blame^] | 3 | set -x |
| 4 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 5 | # Configurable nuggets |
Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 6 | GUEST_PASSWORD=${GUEST_PASSWORD:-secrete} |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 7 | STAGING_DIR=${STAGING_DIR:-stage} |
| 8 | DO_TGZ=${DO_TGZ:-1} |
| 9 | KERNEL_VERSION=3.0.0-12-virtual |
| 10 | |
| 11 | # Debootstrap base system |
| 12 | if [ ! -d $STAGING_DIR ]; then |
| 13 | apt-get install debootstrap |
| 14 | debootstrap --arch amd64 oneiric $STAGING_DIR http://us.archive.ubuntu.com/ubuntu/ |
| 15 | fi |
| 16 | |
| 17 | # Sources.list |
| 18 | cat <<EOF >$STAGING_DIR/etc/apt/sources.list |
| 19 | deb http://us.archive.ubuntu.com/ubuntu/ oneiric main restricted |
| 20 | deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric main restricted |
| 21 | deb http://us.archive.ubuntu.com/ubuntu/ oneiric-updates main restricted |
| 22 | deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric-updates main restricted |
| 23 | deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe |
| 24 | deb http://us.archive.ubuntu.com/ubuntu/ oneiric-updates universe |
| 25 | deb http://us.archive.ubuntu.com/ubuntu/ oneiric multiverse |
| 26 | deb http://us.archive.ubuntu.com/ubuntu/ oneiric-updates multiverse |
| 27 | EOF |
| 28 | |
| 29 | # Install basics |
| 30 | chroot $STAGING_DIR apt-get update |
| 31 | chroot $STAGING_DIR apt-get install -y linux-image-$KERNEL_VERSION |
| 32 | chroot $STAGING_DIR apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool |
| 33 | chroot $STAGING_DIR apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo |
| 34 | chroot $STAGING_DIR pip install xenapi |
| 35 | |
| 36 | # Install guest utilities |
| 37 | XEGUEST=xe-guest-utilities_5.6.100-651_amd64.deb |
| 38 | wget http://images.ansolabs.com/xen/$XEGUEST -O $XEGUEST |
| 39 | cp $XEGUEST $STAGING_DIR/root |
| 40 | chroot $STAGING_DIR dpkg -i /root/$XEGUEST |
| 41 | chroot $STAGING_DIR update-rc.d -f xe-linux-distribution remove |
| 42 | chroot $STAGING_DIR update-rc.d xe-linux-distribution defaults |
| 43 | |
| 44 | # Make a small cracklib dictionary, so that passwd still works, but we don't |
| 45 | # have the big dictionary. |
| 46 | mkdir -p $STAGING_DIR/usr/share/cracklib |
| 47 | echo a | chroot $STAGING_DIR cracklib-packer |
| 48 | |
| 49 | # Make /etc/shadow, and set the root password |
| 50 | chroot $STAGING_DIR "pwconv" |
Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 51 | echo "root:$GUEST_PASSWORD" | chroot $STAGING_DIR chpasswd |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 52 | |
| 53 | # Put the VPX into UTC. |
| 54 | rm -f $STAGING_DIR/etc/localtime |
| 55 | |
| 56 | # Add stack user |
| 57 | chroot $STAGING_DIR groupadd libvirtd |
| 58 | chroot $STAGING_DIR useradd stack -s /bin/bash -d /opt/stack -G libvirtd |
Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 59 | echo stack:$GUEST_PASSWORD | chroot $STAGING_DIR chpasswd |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 60 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $STAGING_DIR/etc/sudoers |
| 61 | |
| 62 | # Give ownership of /opt/stack to stack user |
| 63 | chroot $STAGING_DIR chown -R stack /opt/stack |
| 64 | |
| 65 | # Make our ip address hostnames look nice at the command prompt |
| 66 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/opt/stack/.bashrc |
| 67 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/root/.bashrc |
| 68 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/etc/profile |
| 69 | |
| 70 | function setup_vimrc { |
| 71 | if [ ! -e $1 ]; then |
| 72 | # Simple but usable vimrc |
| 73 | cat > $1 <<EOF |
| 74 | syntax on |
| 75 | se ts=4 |
| 76 | se expandtab |
| 77 | se shiftwidth=4 |
| 78 | EOF |
| 79 | fi |
| 80 | } |
| 81 | |
| 82 | # Setup simple .vimrcs |
| 83 | setup_vimrc $STAGING_DIR/root/.vimrc |
| 84 | setup_vimrc $STAGING_DIR/opt/stack/.vimrc |
| 85 | |
| 86 | if [ "$DO_TGZ" = "1" ]; then |
| 87 | # Compress |
| 88 | rm -f stage.tgz |
| 89 | tar cfz stage.tgz stage |
| 90 | fi |