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