diff --git a/hooks/debian/10-disable-tls b/hooks/debian/10-disable-tls new file mode 100755 index 0000000..7ee040f --- /dev/null +++ b/hooks/debian/10-disable-tls @@ -0,0 +1,47 @@ +#!/bin/sh +# +# This script disables TLS on the new image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + + +# +# Disable TLS and create an empty directory in its place +# +mv ${prefix}/lib/tls ${prefix}/lib/tls.disabled +mkdir ${prefix}/lib/tls + + +# +# For sid + etch systems install libc6-xen +# +case "${dist}" in + etch|sid) + installDebianPackage ${prefix} libc6-xen + ;; +esac + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/15-disable-hwclock b/hooks/debian/15-disable-hwclock new file mode 100755 index 0000000..e608bac --- /dev/null +++ b/hooks/debian/15-disable-hwclock @@ -0,0 +1,38 @@ +#!/bin/sh +# +# This script disables the hardware clock. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Disable the startup scripts from all runlevels. +# +chmod -x ${prefix}/etc/init.d/hwclock.sh +chmod -x ${prefix}/etc/init.d/hwclockfirst.sh + + + +# +# Log our finish +# +logMessage Script $0 finished. \ No newline at end of file diff --git a/hooks/debian/20-setup-apt b/hooks/debian/20-setup-apt new file mode 100755 index 0000000..350d36d --- /dev/null +++ b/hooks/debian/20-setup-apt @@ -0,0 +1,62 @@ +#!/bin/sh +# +# This script sets up the /etc/apt/sources.list for APT. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Setup the sources.list file for new installations of Debian GNU/Linux. +# +cat < ${prefix}/etc/apt/sources.list +# +# /etc/apt/sources.list +# + + +# +# ${dist} +# +deb ${mirror} ${dist} main contrib non-free +deb-src ${mirror} ${dist} main contrib non-free + +# +# Security updates +# +deb http://security.debian.org/ stable/updates main contrib non-free +deb-src http://security.debian.org/ stable/updates main contrib non-free + + +E_O_APT + + + +# +# Now that the sources have been setup make sure the system is up to date. +# +chroot ${prefix} /usr/bin/apt-get update + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/30-fix-inittab b/hooks/debian/30-fix-inittab new file mode 100755 index 0000000..98ca9c3 --- /dev/null +++ b/hooks/debian/30-fix-inittab @@ -0,0 +1,39 @@ +#!/bin/sh +# +# This script does two things: +# +# 1. Sets the console type for the first terminal to 'console'. +# 2. Comments out all virtual terminals which aren't on the first console. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Do the transformation. +# +sed -i -e 's/tty[0-9]$/console/g' -e 's/^\([2-6].*:respawn*\)/#\1/' -e 's/^T/#\t/' ${prefix}/etc/inittab + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/40-setup-networking b/hooks/debian/40-setup-networking new file mode 100755 index 0000000..aea57e6 --- /dev/null +++ b/hooks/debian/40-setup-networking @@ -0,0 +1,132 @@ +#!/bin/sh +# +# This script sets up the /etc/network/interface file for the new +# image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Make sure we have an /etc/network directory. +# +mkdir -p ${prefix}/etc/network + + +# +# A function to setup DHCP for our new image. +# +function setupDynamicNetworking +{ + # + # The host is using DHCP. + # + cat < ${prefix}/etc/network/interfaces +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +# The loopback network interface +auto lo +iface lo inet loopback + +# The primary network interface +auto eth0 +iface eth0 inet dhcp +# post-up ethtool -K eth0 tx off + +# +# The commented out line above will disable TCP checksumming which +# might resolve problems for some users. It is disabled by default +# +E_O_DHCP +} + + + +# +# A function to setup static IP addresses for our new image. +# +function setupStaticNetworking +{ + # + # We have a static IP address + # + cat <${prefix}/etc/network/interfaces +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +# The loopback network interface +auto lo +iface lo inet loopback + +# The primary network interface +auto eth0 +iface eth0 inet static + address ${ip1} + gateway ${gateway} + netmask ${netmask} + # post-up ethtool -K eth0 tx off + +# +# The commented out line above will disable TCP checksumming which +# might resolve problems for some users. It is disabled by default +# +E_O_STATIC + + interface=1 + count=2 + + while [ "${count}" -le "${ip_count}" ]; do + + value=\$ip${count} + value=`eval echo $value` + + cat <>${prefix}/etc/network/interfaces +auto eth0:${interface} +iface eth0:${interface} inet static + address ${value} + netmask ${netmask} + # post-up ethtool -K eth0 tx off +E_O_STATIC + count=`expr $count + 1` + interface=`expr $interface + 1` + done +} + + + + +# +# Call the relevant function +# +if [[ -z "${dhcp}" ]]; then + logMessage "Setting up static networking" + setupStaticNetworking + +else + logMessage "Setting up DHCP networking" + setupDynamicNetworking +fi + + +# +# Log our finish +# +logMessage Script $0 finished \ No newline at end of file diff --git a/hooks/debian/50-setup-hostname b/hooks/debian/50-setup-hostname new file mode 100755 index 0000000..c5433ec --- /dev/null +++ b/hooks/debian/50-setup-hostname @@ -0,0 +1,91 @@ +#!/bin/sh +# +# This script places the new systems hostname into a couple of files within +# the new image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Setup the mailname + hostname files. +# +echo ${hostname} > ${prefix}/etc/hostname +echo ${hostname} > ${prefix}/etc/mailname + + +# +# Fixup the /etc/hosts file upon the new image for +# machines with static IPs +# +if [[ -z "${dhcp}" ]]; then + + # Non-IPv6 stuff. + grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts + + # New entry. + echo "${ip1} ${hostname}" >> ${prefix}/etc/hosts + echo " " >> ${prefix}/etc/hosts + + # IPv6 stuff. + grep '\(::\|IPv6\)' /etc/hosts >> ${prefix}/etc/hosts +fi + + +# +# Allow the host system to know the IP address of our new guest. +# +if [[ -z "${dhcp}" ]]; then + + if ( grep ${hostname} /etc/hosts > /dev/null ) ; then + + logMessage Host already has IP address for the host ${hostname}. + + else + + logMessage Adding ${hostname} to /etc/hosts on the host + + echo "${ip1} ${hostname}" >> /etc/hosts + + # + # If we've updated the /etc/hosts file on the host machine + # and there is an installation of dnsmasq installed then + # reload it. + # + # This will let the local LAN clients lookup the new address. + # + if [ -x /usr/sbin/dnsmasq ] ; + if [ -e /var/run/dnsmasq.pid ]; then + + logMessage Allowing DNSMasq to restart. + + kill -HUP `cat /var/run/dnsmasq.pid` + fi + fi + fi +fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/55-create-dev b/hooks/debian/55-create-dev new file mode 100755 index 0000000..bcfa993 --- /dev/null +++ b/hooks/debian/55-create-dev @@ -0,0 +1,38 @@ +#!/bin/sh +# +# This script ensures that the new guest images have a nicely +# populated /dev directory. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Make the device nodes. +# +cd ${prefix}/dev +./MAKEDEV generic + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/60-copy-host-files b/hooks/debian/60-copy-host-files new file mode 100755 index 0000000..1bd59d3 --- /dev/null +++ b/hooks/debian/60-copy-host-files @@ -0,0 +1,101 @@ +#!/usr/bin/perl -w +# +# This script copies "essential" files from the host to the new +# system. +# +# At the same time it tries to copy all non-system accounts from +# the host system into the new guest unless the root password is +# being setup with --passwd. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +use strict; +use Env; +use File::Copy; + + +my $prefix = shift; + +die "Prefix must be given" unless defined( $prefix ); +die "Prefix must be a directory" unless ( -d $prefix ); + + +# +# Make sure we have $prefix/etc +# +die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); + + +# +# Copy some files literally. +# +my @files = ( "/etc/hosts", + "/etc/resolv.conf", + "/etc/gshadow", + "/etc/group" + ); + +foreach my $file ( @files ) +{ + File::Copy::copy( $file, $prefix . "/etc/" ); +} + + +# +# Only copy the /etc/shadow file if --passwd is *not* specified. +# +if ( !$ENV{'passwd'} ) +{ + File::Copy::copy( "/etc/shadow", $prefix . "/etc/" ); +} + + + +# +# If sudo is installed upon the host then install it upon the guest, +# with the same setup. +# +if ( ( -e "/etc/sudoers" ) && ( -x $prefix . "/usr/bin/apt-get" ) ) +{ + File::Copy::copy( "/etc/sudoers", $prefix . "/etc" ); + chmod( 0440, $prefix. "/etc/sudoers" ); + + `DEBIAN_FRONTEND=noninteractive chroot ${prefix} /usr/bin/apt-get --yes --force-yes install sudo`; +} + + + +# +# Now modify the password file *unless* the "--passwd" option +# was given. +# +if ( ! $ENV{'passwd'} ) +{ + open( ORIG, "<", "/etc/passwd" ) + or die "Failed to open /etc/passwd - $!"; + open( NEW, ">>", $prefix . "/etc/passwd" ) + or die "Failed to open $prefix/etc/passwd - $!"; + + foreach my $line ( ) + { + chomp( $line ); + if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) + { + my $user = $1; + my $pass = $2; + my $uid = $3; + + if ( ( $uid >= 1000 ) && + ( $user ne "nobody" ) ) + { + print NEW $line . "\n"; + } + } + } + + close( NEW ); + close( ORIG ); +} diff --git a/hooks/debian/65-copy-user-files b/hooks/debian/65-copy-user-files new file mode 100755 index 0000000..94c3d8e --- /dev/null +++ b/hooks/debian/65-copy-user-files @@ -0,0 +1,47 @@ +#!/bin/sh +# +# Copy files from a 'skel' directory, if present, into the +# new images +# + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Copy everything from the skel directory into the new instance +# if that directory exists. +# +if [ -d /etc/xen-tools/skel ]; then + + logMessage Copying files from /etc/xen-tools/skel + + (cd /etc/xen-tools/skel; tar -cf - . ) | (cd ${prefix}/; tar -xpf -) + + logMessage Finished + +else + + logMessage skel directory, /etc/xen-tools/skell, not present ignoring. + +fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/70-install-ssh b/hooks/debian/70-install-ssh new file mode 100755 index 0000000..a341df5 --- /dev/null +++ b/hooks/debian/70-install-ssh @@ -0,0 +1,45 @@ +#!/bin/sh +# +# This script installs OpenSSH upon the new system. It must make sure +# that the server is not running before it exits - otherwise the temporary +# mounted directory will not be unmountable. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Install ssh +# +installDebianPackage ${prefix} ssh + + +# +# Make sure sshd isn't running, this will cause our unmounting of the +# disk image to fail.. +# +chroot ${prefix} /etc/init.d/ssh stop + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/80-install-modules b/hooks/debian/80-install-modules new file mode 100755 index 0000000..7e7b41d --- /dev/null +++ b/hooks/debian/80-install-modules @@ -0,0 +1,50 @@ +#!/bin/sh +# +# Install modules from the host system into the new image, and +# ensure that 'module-init-tools' is setup. +# +# This is most likely required if you're using a custom kernel +# for your Xen system. But even if it isn't required it can't +# really do anything bad; just waste a bit of space. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 +dist=$2 + + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Copy the modules from the host to the new system - we should only +# really copy the *correct* modules, but we don't know what they are. +# +mkdir -p ${prefix}/lib/modules +cp -R /lib/modules/*/ ${prefix}/lib/modules + +# +# Install the module-init-tools package. +# +installDebianPackage ${prefix} module-init-tools + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/90-make-fstab b/hooks/debian/90-make-fstab new file mode 100755 index 0000000..eb9f194 --- /dev/null +++ b/hooks/debian/90-make-fstab @@ -0,0 +1,81 @@ +#!/bin/sh +# +# This script is responsible for setting up /etc/fstab upon the +# new instance. +# +# This should be a simple job, but it is complicated by some of the +# differences between filesystems - some root filesystems will require +# the installation of new packages, and we have to handle that here. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Options to mount the root filesystem with, we need to have +# different options for xfs. +# +# The default option works for ext2, ext3, and reiserfs. +# +options="errors=remount-ro" + +case "${fs}" in + xfs) + options="defaults" + ;; +esac + + +# +# Make sure we use ide style device names if required +# +device=sda +if [ "${ide}" ]; then + device=hda +fi + +# +# Now we have the options we can create the fstab. +# +cat < ${prefix}/etc/fstab +/dev/${device}1 / ${fs} ${options} 0 1 +/dev/${device}2 none swap sw 0 0 +proc /proc proc defaults 0 0 +E_O_FSTAB + + +# +# Finally we can install any required packages for the given root +# filesystem +# +case "${fs}" in + xfs) + installDebianPackage ${prefix} xfsprogs + ;; + reiserfs) + installDebianPackage ${prefix} reiserfsprogs + ;; +esac + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/debian/99-clean-image b/hooks/debian/99-clean-image new file mode 100755 index 0000000..aac7b59 --- /dev/null +++ b/hooks/debian/99-clean-image @@ -0,0 +1,36 @@ +#!/bin/sh +# +# This script cleans the newly created image's apt-get archive. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e ../common.sh ]; then + . ../common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Clean the APT package cache for Debian GNU/Linux. +# +chroot ${prefix} /usr/bin/apt-get clean + + +# +# Log our finish +# +logMessage Script $0 finished