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