1
0
mirror of synced 2026-05-01 14:16:09 +00:00

2006-06-18 17:44:07 by steve

Added support for ubuntu, so far only the --dist=dapper works, but the
 sources list is setup correctly and everything else is setup as well
 as Debian is.
This commit is contained in:
steve
2006-06-18 17:44:08 +00:00
parent 413a9be150
commit f8cc7067c2
14 changed files with 860 additions and 1 deletions

49
hooks/ubuntu/10-disable-tls Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/sh
#
# This script disables TLS on the new image.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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

40
hooks/ubuntu/15-disable-hwclock Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/sh
#
# This script disables the hardware clock.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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.

35
hooks/ubuntu/20-setup-apt Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/sh
#
# This script sets up the /etc/apt/sources.list for APT.
#
# Steve
# --
# $Id: 20-setup-apt,v 1.1 2006-06-18 17:44:08 steve Exp $
prefix=$1
cat <<E_O_APT > ${prefix}/etc/apt/sources.list
#
# /etc/apt/sources.list
#
#
# ${dist}
#
deb ${mirror} ${dist} main restricted universe multiverse
deb-src ${mirror} ${dist} main restricted universe
deb ${mirror} ${dist}-updates main restricted universe multiverse
deb-src ${mirror} ${dist}-updates main restricted universe
deb http://security.ubuntu.com/ubuntu ${dist}-security main restricted universe
deb-src http://security.ubuntu.com/ubuntu ${dist}-security main restricted universe
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

41
hooks/ubuntu/30-fix-inittab Executable file
View File

@@ -0,0 +1,41 @@
#!/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 /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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

136
hooks/ubuntu/40-setup-networking Executable file
View File

@@ -0,0 +1,136 @@
#!/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 /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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 <<E_O_DHCP > ${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 <<E_O_STATIC >${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`
logMessage Adding etho:${interface}
cat <<E_O_STATIC >>${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

93
hooks/ubuntu/50-setup-hostname Executable file
View File

@@ -0,0 +1,93 @@
#!/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 /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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 ] ; then
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

40
hooks/ubuntu/55-create-dev Executable file
View File

@@ -0,0 +1,40 @@
#!/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 /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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

153
hooks/ubuntu/60-copy-host-files Executable file
View File

@@ -0,0 +1,153 @@
#!/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/resolv.conf",
);
foreach my $file ( @files )
{
$ENV{'verbose'} && print "Copying from host -> guest: $file\n";
File::Copy::copy( $file, $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" ) )
{
$ENV{'verbose'} && print "Copying from host -> guest: /etc/sudoers\n";
File::Copy::copy( "/etc/sudoers", $prefix . "/etc" );
chmod( 0440, $prefix. "/etc/sudoers" );
$ENV{'verbose'} && print "Installing sudo, since it is on the host.\n";
`DEBIAN_FRONTEND=noninteractive chroot ${prefix} /usr/bin/apt-get --yes --force-yes install sudo`;
}
#
# If the user is specifying the --passwd flag then don't do anything else.
#
if ( $ENV{'passwd'} )
{
exit 0;
}
#
# Otherwise we want to copy all non-system accounts from the files:
#
# /etc/passwd + /etc/shadow
#
open( ORIG, "<", "/etc/passwd" )
or die "Failed to open /etc/passwd - $!";
open( NEW, ">>", $prefix . "/etc/passwd" )
or die "Failed to open $prefix/etc/passwd - $!";
#
# Here we store the user accounts we've copied over so that we
# can copy the shadow lines too.
#
my %copied;
#
# Read the lines from the /etc/passwd on the host.
#
foreach my $line ( <ORIG> )
{
chomp( $line );
#
# Split up line.
#
if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ )
{
my $user = $1;
my $pass = $2;
my $uid = $3;
#
# A non-system account.
#
if ( ( $uid >= 1000 ) &&
( $user ne "nobody" ) )
{
$ENV{'verbose'} && print "Adding '$user' to /etc/passwd on guest\n";
print NEW $line . "\n";
#
# Save the username we copied, so we can append the /etc/shadow
# lines too.
#
$copied{ $user } = 1;
}
}
}
close( NEW );
close( ORIG );
#
# Patchup /etc/shadow on the new image, to ensure that it has the
# lines for each user we copied.
#
foreach my $username ( keys %copied )
{
#
# Open the shadow files.
#
open( ORIG, "<", "/etc/shadow" )
or die "Failed to open /etc/shadow - $!";
open( NEW, ">>", $prefix . "/etc/shadow" )
or die "Failed to open $prefix/etc/shadow - $!";
#
# Now look for a line matching the user in the host file.
#
foreach my $line ( <ORIG> )
{
chomp( $line );
if ( $line =~ /^$username:/ )
{
$ENV{'verbose'} && print "Added line to /etc/shadow for user '$username'\n";
print NEW $line . "\n";
}
}
close( ORIG );
close( NEW );
}

49
hooks/ubuntu/65-copy-user-files Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/sh
#
# Copy files from a 'skel' directory, if present, into the
# new images
#
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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

48
hooks/ubuntu/70-install-ssh Executable file
View File

@@ -0,0 +1,48 @@
#!/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 /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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

51
hooks/ubuntu/80-install-modules Executable file
View File

@@ -0,0 +1,51 @@
#!/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
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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

83
hooks/ubuntu/90-make-fstab Executable file
View File

@@ -0,0 +1,83 @@
#!/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 /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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 <<E_O_FSTAB > ${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

38
hooks/ubuntu/99-clean-image Executable file
View File

@@ -0,0 +1,38 @@
#!/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 /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/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