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