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