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