2011-10-26 22:29:08 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-04-27 18:28:28 +01:00
|
|
|
# This script is run on an Ubuntu VM.
|
|
|
|
# This script is inserted into the VM by prepare_guest_template.sh
|
|
|
|
# and is run when that VM boots.
|
|
|
|
# It customizes a fresh Ubuntu install, so it is ready
|
|
|
|
# to run stack.sh
|
|
|
|
#
|
|
|
|
# This includes installing the XenServer tools,
|
|
|
|
# creating the user called "stack",
|
|
|
|
# and shuts down the VM to signal the script has completed
|
|
|
|
|
2013-05-07 16:58:17 +01:00
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
2012-04-27 18:28:28 +01:00
|
|
|
set -o xtrace
|
2012-02-02 16:09:23 -08:00
|
|
|
|
2011-10-26 22:29:08 -07:00
|
|
|
# Configurable nuggets
|
2013-05-07 16:58:17 +01:00
|
|
|
GUEST_PASSWORD="$1"
|
|
|
|
XS_TOOLS_PATH="$2"
|
|
|
|
STACK_USER="$3"
|
2011-10-26 22:29:08 -07:00
|
|
|
|
|
|
|
# Install basics
|
2013-05-07 16:58:17 +01:00
|
|
|
apt-get update
|
|
|
|
apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool
|
2013-07-12 17:11:07 +01:00
|
|
|
apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo python-netaddr
|
2013-05-07 16:58:17 +01:00
|
|
|
pip install xenapi
|
2011-10-26 22:29:08 -07:00
|
|
|
|
2012-04-27 18:28:28 +01:00
|
|
|
# Install XenServer guest utilities
|
2013-05-07 16:58:17 +01:00
|
|
|
dpkg -i $XS_TOOLS_PATH
|
|
|
|
update-rc.d -f xe-linux-distribution remove
|
|
|
|
update-rc.d xe-linux-distribution defaults
|
2011-10-26 22:29:08 -07:00
|
|
|
|
|
|
|
# Make a small cracklib dictionary, so that passwd still works, but we don't
|
|
|
|
# have the big dictionary.
|
2013-05-07 16:58:17 +01:00
|
|
|
mkdir -p /usr/share/cracklib
|
|
|
|
echo a | cracklib-packer
|
2011-10-26 22:29:08 -07:00
|
|
|
|
|
|
|
# Make /etc/shadow, and set the root password
|
2013-05-07 16:58:17 +01:00
|
|
|
pwconv
|
|
|
|
echo "root:$GUEST_PASSWORD" | chpasswd
|
2011-10-26 22:29:08 -07:00
|
|
|
|
|
|
|
# Put the VPX into UTC.
|
2013-05-07 16:58:17 +01:00
|
|
|
rm -f /etc/localtime
|
2011-10-26 22:29:08 -07:00
|
|
|
|
|
|
|
# Add stack user
|
2013-05-07 16:58:17 +01:00
|
|
|
groupadd libvirtd
|
|
|
|
useradd $STACK_USER -s /bin/bash -d /opt/stack -G libvirtd
|
|
|
|
echo $STACK_USER:$GUEST_PASSWORD | chpasswd
|
|
|
|
echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
2011-10-26 22:29:08 -07:00
|
|
|
|
2013-08-29 11:52:20 +01:00
|
|
|
# Add an udev rule, so that new block devices could be written by stack user
|
|
|
|
cat > /etc/udev/rules.d/50-openstack-blockdev.rules << EOF
|
|
|
|
KERNEL=="xvd[b-z]", GROUP="$STACK_USER", MODE="0660"
|
|
|
|
EOF
|
|
|
|
|
2011-10-26 22:29:08 -07:00
|
|
|
# Give ownership of /opt/stack to stack user
|
2013-05-07 16:58:17 +01:00
|
|
|
chown -R $STACK_USER /opt/stack
|
2011-10-26 22:29:08 -07:00
|
|
|
|
|
|
|
function setup_vimrc {
|
|
|
|
if [ ! -e $1 ]; then
|
|
|
|
# Simple but usable vimrc
|
|
|
|
cat > $1 <<EOF
|
|
|
|
syntax on
|
|
|
|
se ts=4
|
|
|
|
se expandtab
|
|
|
|
se shiftwidth=4
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Setup simple .vimrcs
|
2013-05-07 16:58:17 +01:00
|
|
|
setup_vimrc /root/.vimrc
|
|
|
|
setup_vimrc /opt/stack/.vimrc
|
2012-04-27 18:28:28 +01:00
|
|
|
|
|
|
|
# remove self from local.rc
|
|
|
|
# so this script is not run again
|
|
|
|
rm -rf /etc/rc.local
|
2013-05-07 16:58:17 +01:00
|
|
|
|
|
|
|
# Restore rc.local file
|
|
|
|
cp /etc/rc.local.preparebackup /etc/rc.local
|
2012-04-27 18:28:28 +01:00
|
|
|
|
|
|
|
# shutdown to notify we are done
|
|
|
|
shutdown -h now
|