1
0
mirror of synced 2026-01-17 08:32:49 +00:00

2006-06-09 10:30:37 by steve

Added to the repository.  These are almost straight copies of the
 previous hook scripts except they are now Debian-specific.

  They also each log their start and finish and optional information
 via the use of the ../common.sh file.

  No major changes anticipated.
This commit is contained in:
steve 2006-06-09 10:30:37 +00:00
parent dd424464f5
commit efa1df08de
13 changed files with 807 additions and 0 deletions

47
hooks/debian/10-disable-tls Executable file
View File

@ -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

38
hooks/debian/15-disable-hwclock Executable file
View File

@ -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.

62
hooks/debian/20-setup-apt Executable file
View File

@ -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 <<E_O_APT > ${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

39
hooks/debian/30-fix-inittab Executable file
View File

@ -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

132
hooks/debian/40-setup-networking Executable file
View File

@ -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 <<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`
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

91
hooks/debian/50-setup-hostname Executable file
View File

@ -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

38
hooks/debian/55-create-dev Executable file
View File

@ -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

101
hooks/debian/60-copy-host-files Executable file
View File

@ -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 ( <ORIG> )
{
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 );
}

47
hooks/debian/65-copy-user-files Executable file
View File

@ -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

45
hooks/debian/70-install-ssh Executable file
View File

@ -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

50
hooks/debian/80-install-modules Executable file
View File

@ -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

81
hooks/debian/90-make-fstab Executable file
View File

@ -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 <<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

36
hooks/debian/99-clean-image Executable file
View File

@ -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