diff --git a/Makefile b/Makefile index 0feebd8..1e95e42 100644 --- a/Makefile +++ b/Makefile @@ -192,6 +192,7 @@ install-hooks: -cd ${prefix}/usr/lib/xen-tools/ && ln -s karmic.d precise.d -cd ${prefix}/usr/lib/xen-tools/ && ln -s karmic.d quantal.d cp hooks/common.sh ${prefix}/usr/lib/xen-tools + cp -r hooks/common ${prefix}/usr/lib/xen-tools # diff --git a/NEWS b/NEWS index 9468487..5a35f8b 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ xen-tools 4.3 (released [TODO]) ================================ +New Features and Major Changes +------------------------------ + +* Massive code deduplication in hooks directory + New Options ----------- diff --git a/debian/changelog b/debian/changelog index 14aff86..579d5f7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -25,6 +25,7 @@ xen-tools (4.3~dev-1) UNRELEASED; urgency=low - Fixes call to non-existent function logPrint (Closes: #673335) - Also disable initctl in the chroot, not only start-stop-daemon (LP: #997063; Thanks xstasi!) + - Massive code deduplication in hooks directory * Add dependency on openssh-client for ssh-keygen (Closes: #649108) * Use dh_auto_test for build time tests and add according build-dependencies on devscripts and libfile-slurp-perl. diff --git a/hooks/centos-4/10-disable-tls b/hooks/centos-4/10-disable-tls deleted file mode 100755 index a80edd6..0000000 --- a/hooks/centos-4/10-disable-tls +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 - - -# -# Don't touch TLS on 64 bit platforms. -# -if [ "`uname -m`" = "x86_64" ]; then - logMessage "Ignoring TLS since we're a 64 bit host." - exit -fi - - -# -# Disable TLS and create an empty directory in its place -# -mv ${prefix}/lib/tls ${prefix}/lib/tls.disabled -mkdir ${prefix}/lib/tls - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/centos-4/10-disable-tls b/hooks/centos-4/10-disable-tls new file mode 120000 index 0000000..9ae8088 --- /dev/null +++ b/hooks/centos-4/10-disable-tls @@ -0,0 +1 @@ +../common/10-disable-tls \ No newline at end of file diff --git a/hooks/centos-4/15-setup-arch b/hooks/centos-4/15-setup-arch deleted file mode 100755 index 569d572..0000000 --- a/hooks/centos-4/15-setup-arch +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -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 - - -# -# Record arch, if present. -# -if [ -d $prefix/etc/rpm ]; then - - logMessage Found /etc/rpm - - # - # If i386 then record this - # - if [ "$arch" = "i386" ]; then - echo "i386-fedora-linux-gnu" >> $prefix/etc/rpm/platform - fi -else - - logMessage Failed to find /etc/rpm - -fi - -# -# Log our finish -# -logMessage Script $0 finished - diff --git a/hooks/centos-4/15-setup-arch b/hooks/centos-4/15-setup-arch new file mode 120000 index 0000000..0ecc42a --- /dev/null +++ b/hooks/centos-4/15-setup-arch @@ -0,0 +1 @@ +../common/15-disable-hwclock \ No newline at end of file diff --git a/hooks/centos-4/35-setup-users b/hooks/centos-4/35-setup-users deleted file mode 100755 index 1f80c58..0000000 --- a/hooks/centos-4/35-setup-users +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/perl -w -# -# This script attempts to copy all user accounts from the host to -# the guest. It does this by copying all user accounts which are not -# already present. -# -# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' -# command line we don't do this. -# -# Steve -# -- -# http://www.steve.org.uk/ - - -use strict; -use Env; - - -my $prefix = shift; - -die "Prefix must be given" unless defined( $prefix ); -die "Prefix must be a directory" unless ( -d $prefix ); - - -# -# Exit unless the 'accounts' variable is set. -# -exit unless ( $ENV{'accounts'} ); - -# -# Make sure we have $prefix/etc -# -die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); - - -# -# Read all accounts from the installed /etc/passwd on the guest. -# -my %present; -if ( -e $prefix . "/etc/passwd" ) -{ - %present = readAccounts( $prefix . "/etc/passwd" ); -} - - -# -# Now read the accounts on the host. -# -my %host = readAccounts( "/etc/passwd" ); - - -# -# For each account not present on new installation then add it -# -foreach my $account ( sort keys( %host ) ) -{ - if ( ! $present{ $account } ) - { - print "Adding: $account\n"; - addAccount( $account ); - - # - # Find any groups the user is member of on the host - # and add them on the guest system - # - addGroups( $account ); - } -} - - - -# -# Read the accounts which are already present on the guest image. -# -sub readAccounts -{ - my ( $file ) = ( @_ ); - - - my %found; - - open( EXISTING, "<", $file ); - foreach my $line ( ) - { - # - # Record the userid + username - # - if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) - { - my $user = $1; - my $pass = $2; - my $uid = $3; - - $found{$user} = 1; - } - } - close( EXISTING ); - - return( %found ); -} - - - - -# -# Add the passwd + shadow accounts for the given user. -# -sub addAccount -{ - my ( $user ) = ( @_ ); - - # - # passwd file. - # - open( PASSWD, "<", "/etc/passwd" ); - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/passwd" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( PASSWD ); - - - # - # shadow file. - # - open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/shadow" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( SHADOW ); -} - - - -# -# Find the groups a user is member of on the host, and add them to -# those groups on the new guest. -# -sub addGroups -{ - my( $username ) = ( @_ ); - - # - # Get the groups. - # - my $groups = `groups $username`; - # split off the usernmame. - if ( $groups =~ /^([^:]+):(.*)/ ) - { - $groups = $2; - print "User: $username is member of the groups: $groups\n"; - } - - foreach my $g ( split( / /, $groups ) ) - { - # Make sure the group exists. - system( "chroot $prefix /usr/sbin/addgroup $g" ); - - # add the user to it. - system( "chroot $prefix /usr/sbin/adduser $username $g" ); - } -} diff --git a/hooks/centos-4/35-setup-users b/hooks/centos-4/35-setup-users new file mode 120000 index 0000000..d9bff4c --- /dev/null +++ b/hooks/centos-4/35-setup-users @@ -0,0 +1 @@ +../common/35-setup-users \ No newline at end of file diff --git a/hooks/centos-4/55-create-dev b/hooks/centos-4/55-create-dev deleted file mode 100755 index 89577ce..0000000 --- a/hooks/centos-4/55-create-dev +++ /dev/null @@ -1,53 +0,0 @@ -#!/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 - - - -# -# Early termination if we have a couple of common devices present -# should speed up installs which use --copy/--tar -# -if ( test `ls -1 ${prefix}/dev | wc -l` -gt 10 ); then - logMessage "Terminating because there appear to be files in /dev already" - exit -fi - - -# -# Make the device nodes. -# -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV console' -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV null' -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV zero' - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/centos-4/55-create-dev b/hooks/centos-4/55-create-dev new file mode 120000 index 0000000..1f725c9 --- /dev/null +++ b/hooks/centos-4/55-create-dev @@ -0,0 +1 @@ +../common/55-create-dev \ No newline at end of file diff --git a/hooks/centos-4/65-copy-user-files b/hooks/centos-4/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/centos-4/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/centos-4/65-copy-user-files b/hooks/centos-4/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/centos-4/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/centos-4/75-fixup-securetty b/hooks/centos-4/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/centos-4/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/centos-4/75-fixup-securetty b/hooks/centos-4/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/centos-4/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/centos-5/10-disable-tls b/hooks/centos-5/10-disable-tls deleted file mode 100755 index a80edd6..0000000 --- a/hooks/centos-5/10-disable-tls +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 - - -# -# Don't touch TLS on 64 bit platforms. -# -if [ "`uname -m`" = "x86_64" ]; then - logMessage "Ignoring TLS since we're a 64 bit host." - exit -fi - - -# -# Disable TLS and create an empty directory in its place -# -mv ${prefix}/lib/tls ${prefix}/lib/tls.disabled -mkdir ${prefix}/lib/tls - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/centos-5/10-disable-tls b/hooks/centos-5/10-disable-tls new file mode 120000 index 0000000..9ae8088 --- /dev/null +++ b/hooks/centos-5/10-disable-tls @@ -0,0 +1 @@ +../common/10-disable-tls \ No newline at end of file diff --git a/hooks/centos-5/15-setup-arch b/hooks/centos-5/15-setup-arch deleted file mode 100755 index 569d572..0000000 --- a/hooks/centos-5/15-setup-arch +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -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 - - -# -# Record arch, if present. -# -if [ -d $prefix/etc/rpm ]; then - - logMessage Found /etc/rpm - - # - # If i386 then record this - # - if [ "$arch" = "i386" ]; then - echo "i386-fedora-linux-gnu" >> $prefix/etc/rpm/platform - fi -else - - logMessage Failed to find /etc/rpm - -fi - -# -# Log our finish -# -logMessage Script $0 finished - diff --git a/hooks/centos-5/15-setup-arch b/hooks/centos-5/15-setup-arch new file mode 120000 index 0000000..0ecc42a --- /dev/null +++ b/hooks/centos-5/15-setup-arch @@ -0,0 +1 @@ +../common/15-disable-hwclock \ No newline at end of file diff --git a/hooks/centos-5/35-setup-users b/hooks/centos-5/35-setup-users deleted file mode 100755 index 1f80c58..0000000 --- a/hooks/centos-5/35-setup-users +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/perl -w -# -# This script attempts to copy all user accounts from the host to -# the guest. It does this by copying all user accounts which are not -# already present. -# -# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' -# command line we don't do this. -# -# Steve -# -- -# http://www.steve.org.uk/ - - -use strict; -use Env; - - -my $prefix = shift; - -die "Prefix must be given" unless defined( $prefix ); -die "Prefix must be a directory" unless ( -d $prefix ); - - -# -# Exit unless the 'accounts' variable is set. -# -exit unless ( $ENV{'accounts'} ); - -# -# Make sure we have $prefix/etc -# -die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); - - -# -# Read all accounts from the installed /etc/passwd on the guest. -# -my %present; -if ( -e $prefix . "/etc/passwd" ) -{ - %present = readAccounts( $prefix . "/etc/passwd" ); -} - - -# -# Now read the accounts on the host. -# -my %host = readAccounts( "/etc/passwd" ); - - -# -# For each account not present on new installation then add it -# -foreach my $account ( sort keys( %host ) ) -{ - if ( ! $present{ $account } ) - { - print "Adding: $account\n"; - addAccount( $account ); - - # - # Find any groups the user is member of on the host - # and add them on the guest system - # - addGroups( $account ); - } -} - - - -# -# Read the accounts which are already present on the guest image. -# -sub readAccounts -{ - my ( $file ) = ( @_ ); - - - my %found; - - open( EXISTING, "<", $file ); - foreach my $line ( ) - { - # - # Record the userid + username - # - if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) - { - my $user = $1; - my $pass = $2; - my $uid = $3; - - $found{$user} = 1; - } - } - close( EXISTING ); - - return( %found ); -} - - - - -# -# Add the passwd + shadow accounts for the given user. -# -sub addAccount -{ - my ( $user ) = ( @_ ); - - # - # passwd file. - # - open( PASSWD, "<", "/etc/passwd" ); - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/passwd" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( PASSWD ); - - - # - # shadow file. - # - open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/shadow" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( SHADOW ); -} - - - -# -# Find the groups a user is member of on the host, and add them to -# those groups on the new guest. -# -sub addGroups -{ - my( $username ) = ( @_ ); - - # - # Get the groups. - # - my $groups = `groups $username`; - # split off the usernmame. - if ( $groups =~ /^([^:]+):(.*)/ ) - { - $groups = $2; - print "User: $username is member of the groups: $groups\n"; - } - - foreach my $g ( split( / /, $groups ) ) - { - # Make sure the group exists. - system( "chroot $prefix /usr/sbin/addgroup $g" ); - - # add the user to it. - system( "chroot $prefix /usr/sbin/adduser $username $g" ); - } -} diff --git a/hooks/centos-5/35-setup-users b/hooks/centos-5/35-setup-users new file mode 120000 index 0000000..d9bff4c --- /dev/null +++ b/hooks/centos-5/35-setup-users @@ -0,0 +1 @@ +../common/35-setup-users \ No newline at end of file diff --git a/hooks/centos-5/55-create-dev b/hooks/centos-5/55-create-dev deleted file mode 100755 index 89577ce..0000000 --- a/hooks/centos-5/55-create-dev +++ /dev/null @@ -1,53 +0,0 @@ -#!/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 - - - -# -# Early termination if we have a couple of common devices present -# should speed up installs which use --copy/--tar -# -if ( test `ls -1 ${prefix}/dev | wc -l` -gt 10 ); then - logMessage "Terminating because there appear to be files in /dev already" - exit -fi - - -# -# Make the device nodes. -# -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV console' -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV null' -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV zero' - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/centos-5/55-create-dev b/hooks/centos-5/55-create-dev new file mode 120000 index 0000000..1f725c9 --- /dev/null +++ b/hooks/centos-5/55-create-dev @@ -0,0 +1 @@ +../common/55-create-dev \ No newline at end of file diff --git a/hooks/centos-5/65-copy-user-files b/hooks/centos-5/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/centos-5/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/centos-5/65-copy-user-files b/hooks/centos-5/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/centos-5/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/centos-5/75-fixup-securetty b/hooks/centos-5/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/centos-5/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/centos-5/75-fixup-securetty b/hooks/centos-5/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/centos-5/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/common/01-disable-daemons b/hooks/common/01-disable-daemons new file mode 100755 index 0000000..d12d7bd --- /dev/null +++ b/hooks/common/01-disable-daemons @@ -0,0 +1,54 @@ +#!/bin/sh +# +# This script ensures that daemons will not be started inside our +# chroot() installation. +# +# 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 a directory. +# +if [ ! -d "${prefix}/usr/sbin" ]; then + + mkdir -p "${prefix}/usr/sbin" + + logMessage "created missing directory: ${prefix}/usr/sbin" +fi + + +# +# Add the script. +# +echo '#!/bin/sh' > ${prefix}/usr/sbin/policy-rc.d +echo 'exit 101' >> ${prefix}/usr/sbin/policy-rc.d +chmod 755 ${prefix}/usr/sbin/policy-rc.d + + + +# +# Log our finish +# +logMessage Script $0 finished. + diff --git a/hooks/common/05-shadowconfig-on b/hooks/common/05-shadowconfig-on new file mode 100755 index 0000000..e5bcbb4 --- /dev/null +++ b/hooks/common/05-shadowconfig-on @@ -0,0 +1,45 @@ +#!/bin/sh +# +# This script enforces the use of a shadow password file. +# +# 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 + + +# +# Enable the shadow passwords if the command is found. +# +if [ -x ${prefix}/sbin/shadowconfig ]; then + + chroot ${prefix} /sbin/shadowconfig on +else + + logMessage "/sbin/shadowconfig not found. skipping." +fi + + +# +# Log our finish +# +logMessage Script $0 finished. + diff --git a/hooks/common/10-disable-tls b/hooks/common/10-disable-tls new file mode 100755 index 0000000..a80edd6 --- /dev/null +++ b/hooks/common/10-disable-tls @@ -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 + + +# +# Don't touch TLS on 64 bit platforms. +# +if [ "`uname -m`" = "x86_64" ]; then + logMessage "Ignoring TLS since we're a 64 bit host." + exit +fi + + +# +# Disable TLS and create an empty directory in its place +# +mv ${prefix}/lib/tls ${prefix}/lib/tls.disabled +mkdir ${prefix}/lib/tls + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/common/15-disable-hwclock b/hooks/common/15-disable-hwclock new file mode 100755 index 0000000..74556ac --- /dev/null +++ b/hooks/common/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 /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. +# +chroot ${prefix} /usr/sbin/update-rc.d -f hwclock.sh remove + +# +# Log our finish +# +logMessage Script $0 finished. + diff --git a/hooks/common/15-setup-arch b/hooks/common/15-setup-arch new file mode 100755 index 0000000..569d572 --- /dev/null +++ b/hooks/common/15-setup-arch @@ -0,0 +1,44 @@ +#!/bin/sh + +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 + + +# +# Record arch, if present. +# +if [ -d $prefix/etc/rpm ]; then + + logMessage Found /etc/rpm + + # + # If i386 then record this + # + if [ "$arch" = "i386" ]; then + echo "i386-fedora-linux-gnu" >> $prefix/etc/rpm/platform + fi +else + + logMessage Failed to find /etc/rpm + +fi + +# +# Log our finish +# +logMessage Script $0 finished + diff --git a/hooks/common/20-setup-apt b/hooks/common/20-setup-apt new file mode 100755 index 0000000..5833c47 --- /dev/null +++ b/hooks/common/20-setup-apt @@ -0,0 +1,90 @@ +#!/bin/sh +# +# This script sets up the /etc/apt/sources.list for APT. +# +# Steve +# -- +# + + + + +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 + + +# +# Attempt to auto-magically detect the use of a Proxy for apt-get, and +# replicate that setup in our new guest via apt-config dump and save +# the setting to the proxy guess file. +# +if [ ${apt_proxy} ]; then + echo "Acquire::http::Proxy \"${apt_proxy}\";" > ${prefix}/etc/apt/apt.conf.d/01proxy +else + logMessage The use of a proxy detected. + apt-config dump | grep -i Acquire::HTTP::Proxy > ${prefix}/etc/apt/apt.conf.d/01proxy +fi + + +# +# Setup the sources.list file for new installations of Ubuntu GNU/Linux. +# +cat < ${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 + + +# +# Now fixup TLS on non-64bit systems. +# +if [ "`uname -m`" = "x86_64" ]; then + + logMessage "Ignoring TLS since we're a 64 bit host." + +else + + logMessage "Installing libc6-xen" + installDebianPackage ${prefix} libc6-xen +fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/common/25-generate-locale b/hooks/common/25-generate-locale new file mode 100755 index 0000000..ca2b099 --- /dev/null +++ b/hooks/common/25-generate-locale @@ -0,0 +1,40 @@ +#!/bin/sh +# +# This script generates a default en_US.UTF-8 locale. +# +# Ward +# -- + + + +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 the English language pack. +# +# NOTE: Failure to support your favourite language is *not* a bug. +# +installDebianPackage ${prefix} language-pack-en + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/common/35-setup-users b/hooks/common/35-setup-users new file mode 100755 index 0000000..1f80c58 --- /dev/null +++ b/hooks/common/35-setup-users @@ -0,0 +1,181 @@ +#!/usr/bin/perl -w +# +# This script attempts to copy all user accounts from the host to +# the guest. It does this by copying all user accounts which are not +# already present. +# +# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' +# command line we don't do this. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +use strict; +use Env; + + +my $prefix = shift; + +die "Prefix must be given" unless defined( $prefix ); +die "Prefix must be a directory" unless ( -d $prefix ); + + +# +# Exit unless the 'accounts' variable is set. +# +exit unless ( $ENV{'accounts'} ); + +# +# Make sure we have $prefix/etc +# +die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); + + +# +# Read all accounts from the installed /etc/passwd on the guest. +# +my %present; +if ( -e $prefix . "/etc/passwd" ) +{ + %present = readAccounts( $prefix . "/etc/passwd" ); +} + + +# +# Now read the accounts on the host. +# +my %host = readAccounts( "/etc/passwd" ); + + +# +# For each account not present on new installation then add it +# +foreach my $account ( sort keys( %host ) ) +{ + if ( ! $present{ $account } ) + { + print "Adding: $account\n"; + addAccount( $account ); + + # + # Find any groups the user is member of on the host + # and add them on the guest system + # + addGroups( $account ); + } +} + + + +# +# Read the accounts which are already present on the guest image. +# +sub readAccounts +{ + my ( $file ) = ( @_ ); + + + my %found; + + open( EXISTING, "<", $file ); + foreach my $line ( ) + { + # + # Record the userid + username + # + if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) + { + my $user = $1; + my $pass = $2; + my $uid = $3; + + $found{$user} = 1; + } + } + close( EXISTING ); + + return( %found ); +} + + + + +# +# Add the passwd + shadow accounts for the given user. +# +sub addAccount +{ + my ( $user ) = ( @_ ); + + # + # passwd file. + # + open( PASSWD, "<", "/etc/passwd" ); + foreach my $line ( ) + { + chomp( $line ); + if ( $line =~ /^\Q$user\E:/ ) + { + # + # Add the line + # + open( OUTY, ">>", $prefix . "/etc/passwd" ); + print OUTY $line . "\n"; + close( OUTY ); + } + } + close( PASSWD ); + + + # + # shadow file. + # + open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; + foreach my $line ( ) + { + chomp( $line ); + if ( $line =~ /^\Q$user\E:/ ) + { + # + # Add the line + # + open( OUTY, ">>", $prefix . "/etc/shadow" ); + print OUTY $line . "\n"; + close( OUTY ); + } + } + close( SHADOW ); +} + + + +# +# Find the groups a user is member of on the host, and add them to +# those groups on the new guest. +# +sub addGroups +{ + my( $username ) = ( @_ ); + + # + # Get the groups. + # + my $groups = `groups $username`; + # split off the usernmame. + if ( $groups =~ /^([^:]+):(.*)/ ) + { + $groups = $2; + print "User: $username is member of the groups: $groups\n"; + } + + foreach my $g ( split( / /, $groups ) ) + { + # Make sure the group exists. + system( "chroot $prefix /usr/sbin/addgroup $g" ); + + # add the user to it. + system( "chroot $prefix /usr/sbin/adduser $username $g" ); + } +} diff --git a/hooks/common/50-setup-hostname b/hooks/common/50-setup-hostname new file mode 100755 index 0000000..5c89336 --- /dev/null +++ b/hooks/common/50-setup-hostname @@ -0,0 +1,141 @@ +#!/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 + +# +# Determine the FQDN and Hostname +# +GUEST_FQDN=${hostname} +GUEST_HOSTNAME=`echo $GUEST_FQDN | awk -F'.' '{print $1}'` + +# +# Setup the mailname + hostname files. +# +echo $GUEST_HOSTNAME > ${prefix}/etc/hostname +echo $GUEST_FQDN > ${prefix}/etc/mailname + + +# +# Fixup the /etc/hosts file upon the new image for +# machines with static IPs +# +if [ -z "${copyhosts}" ]; then + # + # Copy localhost + # + cat > ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts < ${prefix}/etc/hosts + + # New entry. + if [ -z "${dhcp}" ]; then + cat >> ${prefix}/etc/hosts <> ${prefix}/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 $GUEST_FQDN /etc/hosts > /dev/null ) ; then + + logMessage Host already has IP address for the host $GUEST_FQDN. + + else + if [ -z "${nohosts}" ]; then + + logMessage Adding $GUEST_FQDN and $GUEST_HOSTNAME to /etc/hosts on the host + echo "${ip1} $GUEST_FQDN $GUEST_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 -s HUP `cat /var/run/dnsmasq.pid` + fi + fi + fi + fi +fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/common/55-create-dev b/hooks/common/55-create-dev new file mode 100755 index 0000000..89577ce --- /dev/null +++ b/hooks/common/55-create-dev @@ -0,0 +1,53 @@ +#!/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 + + + +# +# Early termination if we have a couple of common devices present +# should speed up installs which use --copy/--tar +# +if ( test `ls -1 ${prefix}/dev | wc -l` -gt 10 ); then + logMessage "Terminating because there appear to be files in /dev already" + exit +fi + + +# +# Make the device nodes. +# +chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV console' +chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV null' +chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV zero' + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/common/60-copy-host-files b/hooks/common/60-copy-host-files new file mode 100755 index 0000000..8da3b93 --- /dev/null +++ b/hooks/common/60-copy-host-files @@ -0,0 +1,37 @@ +#!/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 "required" files from our host. +# +cp /etc/timezone ${prefix}/etc +cp /etc/localtime ${prefix}/etc + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/common/65-copy-user-files b/hooks/common/65-copy-user-files new file mode 100755 index 0000000..a34fe94 --- /dev/null +++ b/hooks/common/65-copy-user-files @@ -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 diff --git a/hooks/common/75-fixup-securetty b/hooks/common/75-fixup-securetty new file mode 100755 index 0000000..58ab907 --- /dev/null +++ b/hooks/common/75-fixup-securetty @@ -0,0 +1,62 @@ +#!/bin/sh +# +# This script ensures /etc/securetty upon the new guests has the new +# Xen console devices in it +# +# 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 + +# +# If the file doesn't exist exit early. +# +if [ ! -e ${prefix}/etc/securetty ]; then + logMessage /etc/securetty not found. + exit +fi + + +# +# Do both the devices. +# +for i in xvc0 hvc0 ; do + + # + # Only append if not presnt. + # + if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then + + logMessage Host already has $i entry + + else + + echo $i >> ${prefix}/etc/securetty + fi + +done + + +# +# Log our finish +# +logMessage Script $0 finished. + diff --git a/hooks/common/99-clean-image b/hooks/common/99-clean-image new file mode 100755 index 0000000..d36d438 --- /dev/null +++ b/hooks/common/99-clean-image @@ -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 diff --git a/hooks/common/99-enable-daemons b/hooks/common/99-enable-daemons new file mode 100755 index 0000000..c1eb25a --- /dev/null +++ b/hooks/common/99-enable-daemons @@ -0,0 +1,45 @@ +#!/bin/sh +# +# This script removes the file which prevents daemons from running. +# +# 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 + + +# +# Remove the script if present. +# +if [ -x "${prefix}/usr/sbin/policy-rc.d" ]; then + + rm -f "${prefix}/usr/sbin/policy-rc.d" + + logMessage "Removed: ${prefix}/usr/sbin/policy-rc.d" + +fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/dapper/01-disable-daemons b/hooks/dapper/01-disable-daemons deleted file mode 100755 index d12d7bd..0000000 --- a/hooks/dapper/01-disable-daemons +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# -# This script ensures that daemons will not be started inside our -# chroot() installation. -# -# 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 a directory. -# -if [ ! -d "${prefix}/usr/sbin" ]; then - - mkdir -p "${prefix}/usr/sbin" - - logMessage "created missing directory: ${prefix}/usr/sbin" -fi - - -# -# Add the script. -# -echo '#!/bin/sh' > ${prefix}/usr/sbin/policy-rc.d -echo 'exit 101' >> ${prefix}/usr/sbin/policy-rc.d -chmod 755 ${prefix}/usr/sbin/policy-rc.d - - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/dapper/01-disable-daemons b/hooks/dapper/01-disable-daemons new file mode 120000 index 0000000..44e36b0 --- /dev/null +++ b/hooks/dapper/01-disable-daemons @@ -0,0 +1 @@ +../common/01-disable-daemons \ No newline at end of file diff --git a/hooks/dapper/05-shadowconfig-on b/hooks/dapper/05-shadowconfig-on deleted file mode 100755 index e5bcbb4..0000000 --- a/hooks/dapper/05-shadowconfig-on +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script enforces the use of a shadow password file. -# -# 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 - - -# -# Enable the shadow passwords if the command is found. -# -if [ -x ${prefix}/sbin/shadowconfig ]; then - - chroot ${prefix} /sbin/shadowconfig on -else - - logMessage "/sbin/shadowconfig not found. skipping." -fi - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/dapper/05-shadowconfig-on b/hooks/dapper/05-shadowconfig-on new file mode 120000 index 0000000..d165812 --- /dev/null +++ b/hooks/dapper/05-shadowconfig-on @@ -0,0 +1 @@ +../common/05-shadowconfig-on \ No newline at end of file diff --git a/hooks/dapper/15-disable-hwclock b/hooks/dapper/15-disable-hwclock deleted file mode 100755 index 74556ac..0000000 --- a/hooks/dapper/15-disable-hwclock +++ /dev/null @@ -1,38 +0,0 @@ -#!/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. -# -chroot ${prefix} /usr/sbin/update-rc.d -f hwclock.sh remove - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/dapper/15-disable-hwclock b/hooks/dapper/15-disable-hwclock new file mode 120000 index 0000000..0ecc42a --- /dev/null +++ b/hooks/dapper/15-disable-hwclock @@ -0,0 +1 @@ +../common/15-disable-hwclock \ No newline at end of file diff --git a/hooks/dapper/25-generate-locale b/hooks/dapper/25-generate-locale deleted file mode 100755 index ca2b099..0000000 --- a/hooks/dapper/25-generate-locale +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# -# This script generates a default en_US.UTF-8 locale. -# -# Ward -# -- - - - -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 the English language pack. -# -# NOTE: Failure to support your favourite language is *not* a bug. -# -installDebianPackage ${prefix} language-pack-en - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/dapper/25-generate-locale b/hooks/dapper/25-generate-locale new file mode 120000 index 0000000..91644b2 --- /dev/null +++ b/hooks/dapper/25-generate-locale @@ -0,0 +1 @@ +../common/25-generate-locale \ No newline at end of file diff --git a/hooks/dapper/35-setup-users b/hooks/dapper/35-setup-users deleted file mode 100755 index 1f80c58..0000000 --- a/hooks/dapper/35-setup-users +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/perl -w -# -# This script attempts to copy all user accounts from the host to -# the guest. It does this by copying all user accounts which are not -# already present. -# -# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' -# command line we don't do this. -# -# Steve -# -- -# http://www.steve.org.uk/ - - -use strict; -use Env; - - -my $prefix = shift; - -die "Prefix must be given" unless defined( $prefix ); -die "Prefix must be a directory" unless ( -d $prefix ); - - -# -# Exit unless the 'accounts' variable is set. -# -exit unless ( $ENV{'accounts'} ); - -# -# Make sure we have $prefix/etc -# -die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); - - -# -# Read all accounts from the installed /etc/passwd on the guest. -# -my %present; -if ( -e $prefix . "/etc/passwd" ) -{ - %present = readAccounts( $prefix . "/etc/passwd" ); -} - - -# -# Now read the accounts on the host. -# -my %host = readAccounts( "/etc/passwd" ); - - -# -# For each account not present on new installation then add it -# -foreach my $account ( sort keys( %host ) ) -{ - if ( ! $present{ $account } ) - { - print "Adding: $account\n"; - addAccount( $account ); - - # - # Find any groups the user is member of on the host - # and add them on the guest system - # - addGroups( $account ); - } -} - - - -# -# Read the accounts which are already present on the guest image. -# -sub readAccounts -{ - my ( $file ) = ( @_ ); - - - my %found; - - open( EXISTING, "<", $file ); - foreach my $line ( ) - { - # - # Record the userid + username - # - if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) - { - my $user = $1; - my $pass = $2; - my $uid = $3; - - $found{$user} = 1; - } - } - close( EXISTING ); - - return( %found ); -} - - - - -# -# Add the passwd + shadow accounts for the given user. -# -sub addAccount -{ - my ( $user ) = ( @_ ); - - # - # passwd file. - # - open( PASSWD, "<", "/etc/passwd" ); - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/passwd" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( PASSWD ); - - - # - # shadow file. - # - open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/shadow" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( SHADOW ); -} - - - -# -# Find the groups a user is member of on the host, and add them to -# those groups on the new guest. -# -sub addGroups -{ - my( $username ) = ( @_ ); - - # - # Get the groups. - # - my $groups = `groups $username`; - # split off the usernmame. - if ( $groups =~ /^([^:]+):(.*)/ ) - { - $groups = $2; - print "User: $username is member of the groups: $groups\n"; - } - - foreach my $g ( split( / /, $groups ) ) - { - # Make sure the group exists. - system( "chroot $prefix /usr/sbin/addgroup $g" ); - - # add the user to it. - system( "chroot $prefix /usr/sbin/adduser $username $g" ); - } -} diff --git a/hooks/dapper/35-setup-users b/hooks/dapper/35-setup-users new file mode 120000 index 0000000..d9bff4c --- /dev/null +++ b/hooks/dapper/35-setup-users @@ -0,0 +1 @@ +../common/35-setup-users \ No newline at end of file diff --git a/hooks/dapper/50-setup-hostname b/hooks/dapper/50-setup-hostname deleted file mode 100755 index 5c89336..0000000 --- a/hooks/dapper/50-setup-hostname +++ /dev/null @@ -1,141 +0,0 @@ -#!/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 - -# -# Determine the FQDN and Hostname -# -GUEST_FQDN=${hostname} -GUEST_HOSTNAME=`echo $GUEST_FQDN | awk -F'.' '{print $1}'` - -# -# Setup the mailname + hostname files. -# -echo $GUEST_HOSTNAME > ${prefix}/etc/hostname -echo $GUEST_FQDN > ${prefix}/etc/mailname - - -# -# Fixup the /etc/hosts file upon the new image for -# machines with static IPs -# -if [ -z "${copyhosts}" ]; then - # - # Copy localhost - # - cat > ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts < ${prefix}/etc/hosts - - # New entry. - if [ -z "${dhcp}" ]; then - cat >> ${prefix}/etc/hosts <> ${prefix}/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 $GUEST_FQDN /etc/hosts > /dev/null ) ; then - - logMessage Host already has IP address for the host $GUEST_FQDN. - - else - if [ -z "${nohosts}" ]; then - - logMessage Adding $GUEST_FQDN and $GUEST_HOSTNAME to /etc/hosts on the host - echo "${ip1} $GUEST_FQDN $GUEST_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 -s HUP `cat /var/run/dnsmasq.pid` - fi - fi - fi - fi -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/dapper/50-setup-hostname b/hooks/dapper/50-setup-hostname new file mode 120000 index 0000000..509952f --- /dev/null +++ b/hooks/dapper/50-setup-hostname @@ -0,0 +1 @@ +../common/50-setup-hostname \ No newline at end of file diff --git a/hooks/dapper/60-copy-host-files b/hooks/dapper/60-copy-host-files deleted file mode 100755 index 8da3b93..0000000 --- a/hooks/dapper/60-copy-host-files +++ /dev/null @@ -1,37 +0,0 @@ -#!/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 "required" files from our host. -# -cp /etc/timezone ${prefix}/etc -cp /etc/localtime ${prefix}/etc - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/dapper/60-copy-host-files b/hooks/dapper/60-copy-host-files new file mode 120000 index 0000000..0990ad8 --- /dev/null +++ b/hooks/dapper/60-copy-host-files @@ -0,0 +1 @@ +../common/60-copy-host-files \ No newline at end of file diff --git a/hooks/dapper/65-copy-user-files b/hooks/dapper/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/dapper/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/dapper/65-copy-user-files b/hooks/dapper/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/dapper/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/dapper/75-fixup-securetty b/hooks/dapper/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/dapper/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/dapper/75-fixup-securetty b/hooks/dapper/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/dapper/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/dapper/99-clean-image b/hooks/dapper/99-clean-image deleted file mode 100755 index d36d438..0000000 --- a/hooks/dapper/99-clean-image +++ /dev/null @@ -1,38 +0,0 @@ -#!/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 diff --git a/hooks/dapper/99-clean-image b/hooks/dapper/99-clean-image new file mode 120000 index 0000000..f850fb0 --- /dev/null +++ b/hooks/dapper/99-clean-image @@ -0,0 +1 @@ +../common/99-clean-image \ No newline at end of file diff --git a/hooks/dapper/99-enable-daemons b/hooks/dapper/99-enable-daemons deleted file mode 100755 index c1eb25a..0000000 --- a/hooks/dapper/99-enable-daemons +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script removes the file which prevents daemons from running. -# -# 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 - - -# -# Remove the script if present. -# -if [ -x "${prefix}/usr/sbin/policy-rc.d" ]; then - - rm -f "${prefix}/usr/sbin/policy-rc.d" - - logMessage "Removed: ${prefix}/usr/sbin/policy-rc.d" - -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/dapper/99-enable-daemons b/hooks/dapper/99-enable-daemons new file mode 120000 index 0000000..ada8e1f --- /dev/null +++ b/hooks/dapper/99-enable-daemons @@ -0,0 +1 @@ +../common/99-enable-daemons \ No newline at end of file diff --git a/hooks/debian/01-disable-daemons b/hooks/debian/01-disable-daemons deleted file mode 100755 index d12d7bd..0000000 --- a/hooks/debian/01-disable-daemons +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# -# This script ensures that daemons will not be started inside our -# chroot() installation. -# -# 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 a directory. -# -if [ ! -d "${prefix}/usr/sbin" ]; then - - mkdir -p "${prefix}/usr/sbin" - - logMessage "created missing directory: ${prefix}/usr/sbin" -fi - - -# -# Add the script. -# -echo '#!/bin/sh' > ${prefix}/usr/sbin/policy-rc.d -echo 'exit 101' >> ${prefix}/usr/sbin/policy-rc.d -chmod 755 ${prefix}/usr/sbin/policy-rc.d - - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/debian/01-disable-daemons b/hooks/debian/01-disable-daemons new file mode 120000 index 0000000..44e36b0 --- /dev/null +++ b/hooks/debian/01-disable-daemons @@ -0,0 +1 @@ +../common/01-disable-daemons \ No newline at end of file diff --git a/hooks/debian/05-shadowconfig-on b/hooks/debian/05-shadowconfig-on deleted file mode 100755 index e5bcbb4..0000000 --- a/hooks/debian/05-shadowconfig-on +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script enforces the use of a shadow password file. -# -# 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 - - -# -# Enable the shadow passwords if the command is found. -# -if [ -x ${prefix}/sbin/shadowconfig ]; then - - chroot ${prefix} /sbin/shadowconfig on -else - - logMessage "/sbin/shadowconfig not found. skipping." -fi - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/debian/05-shadowconfig-on b/hooks/debian/05-shadowconfig-on new file mode 120000 index 0000000..d165812 --- /dev/null +++ b/hooks/debian/05-shadowconfig-on @@ -0,0 +1 @@ +../common/05-shadowconfig-on \ No newline at end of file diff --git a/hooks/debian/15-disable-hwclock b/hooks/debian/15-disable-hwclock deleted file mode 100755 index 74556ac..0000000 --- a/hooks/debian/15-disable-hwclock +++ /dev/null @@ -1,38 +0,0 @@ -#!/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. -# -chroot ${prefix} /usr/sbin/update-rc.d -f hwclock.sh remove - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/debian/15-disable-hwclock b/hooks/debian/15-disable-hwclock new file mode 120000 index 0000000..0ecc42a --- /dev/null +++ b/hooks/debian/15-disable-hwclock @@ -0,0 +1 @@ +../common/15-disable-hwclock \ No newline at end of file diff --git a/hooks/debian/35-setup-users b/hooks/debian/35-setup-users deleted file mode 100755 index 1f80c58..0000000 --- a/hooks/debian/35-setup-users +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/perl -w -# -# This script attempts to copy all user accounts from the host to -# the guest. It does this by copying all user accounts which are not -# already present. -# -# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' -# command line we don't do this. -# -# Steve -# -- -# http://www.steve.org.uk/ - - -use strict; -use Env; - - -my $prefix = shift; - -die "Prefix must be given" unless defined( $prefix ); -die "Prefix must be a directory" unless ( -d $prefix ); - - -# -# Exit unless the 'accounts' variable is set. -# -exit unless ( $ENV{'accounts'} ); - -# -# Make sure we have $prefix/etc -# -die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); - - -# -# Read all accounts from the installed /etc/passwd on the guest. -# -my %present; -if ( -e $prefix . "/etc/passwd" ) -{ - %present = readAccounts( $prefix . "/etc/passwd" ); -} - - -# -# Now read the accounts on the host. -# -my %host = readAccounts( "/etc/passwd" ); - - -# -# For each account not present on new installation then add it -# -foreach my $account ( sort keys( %host ) ) -{ - if ( ! $present{ $account } ) - { - print "Adding: $account\n"; - addAccount( $account ); - - # - # Find any groups the user is member of on the host - # and add them on the guest system - # - addGroups( $account ); - } -} - - - -# -# Read the accounts which are already present on the guest image. -# -sub readAccounts -{ - my ( $file ) = ( @_ ); - - - my %found; - - open( EXISTING, "<", $file ); - foreach my $line ( ) - { - # - # Record the userid + username - # - if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) - { - my $user = $1; - my $pass = $2; - my $uid = $3; - - $found{$user} = 1; - } - } - close( EXISTING ); - - return( %found ); -} - - - - -# -# Add the passwd + shadow accounts for the given user. -# -sub addAccount -{ - my ( $user ) = ( @_ ); - - # - # passwd file. - # - open( PASSWD, "<", "/etc/passwd" ); - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/passwd" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( PASSWD ); - - - # - # shadow file. - # - open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/shadow" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( SHADOW ); -} - - - -# -# Find the groups a user is member of on the host, and add them to -# those groups on the new guest. -# -sub addGroups -{ - my( $username ) = ( @_ ); - - # - # Get the groups. - # - my $groups = `groups $username`; - # split off the usernmame. - if ( $groups =~ /^([^:]+):(.*)/ ) - { - $groups = $2; - print "User: $username is member of the groups: $groups\n"; - } - - foreach my $g ( split( / /, $groups ) ) - { - # Make sure the group exists. - system( "chroot $prefix /usr/sbin/addgroup $g" ); - - # add the user to it. - system( "chroot $prefix /usr/sbin/adduser $username $g" ); - } -} diff --git a/hooks/debian/35-setup-users b/hooks/debian/35-setup-users new file mode 120000 index 0000000..d9bff4c --- /dev/null +++ b/hooks/debian/35-setup-users @@ -0,0 +1 @@ +../common/35-setup-users \ No newline at end of file diff --git a/hooks/debian/50-setup-hostname b/hooks/debian/50-setup-hostname deleted file mode 100755 index 5c89336..0000000 --- a/hooks/debian/50-setup-hostname +++ /dev/null @@ -1,141 +0,0 @@ -#!/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 - -# -# Determine the FQDN and Hostname -# -GUEST_FQDN=${hostname} -GUEST_HOSTNAME=`echo $GUEST_FQDN | awk -F'.' '{print $1}'` - -# -# Setup the mailname + hostname files. -# -echo $GUEST_HOSTNAME > ${prefix}/etc/hostname -echo $GUEST_FQDN > ${prefix}/etc/mailname - - -# -# Fixup the /etc/hosts file upon the new image for -# machines with static IPs -# -if [ -z "${copyhosts}" ]; then - # - # Copy localhost - # - cat > ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts < ${prefix}/etc/hosts - - # New entry. - if [ -z "${dhcp}" ]; then - cat >> ${prefix}/etc/hosts <> ${prefix}/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 $GUEST_FQDN /etc/hosts > /dev/null ) ; then - - logMessage Host already has IP address for the host $GUEST_FQDN. - - else - if [ -z "${nohosts}" ]; then - - logMessage Adding $GUEST_FQDN and $GUEST_HOSTNAME to /etc/hosts on the host - echo "${ip1} $GUEST_FQDN $GUEST_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 -s HUP `cat /var/run/dnsmasq.pid` - fi - fi - fi - fi -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/debian/50-setup-hostname b/hooks/debian/50-setup-hostname new file mode 120000 index 0000000..509952f --- /dev/null +++ b/hooks/debian/50-setup-hostname @@ -0,0 +1 @@ +../common/50-setup-hostname \ No newline at end of file diff --git a/hooks/debian/60-copy-host-files b/hooks/debian/60-copy-host-files deleted file mode 100755 index 8da3b93..0000000 --- a/hooks/debian/60-copy-host-files +++ /dev/null @@ -1,37 +0,0 @@ -#!/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 "required" files from our host. -# -cp /etc/timezone ${prefix}/etc -cp /etc/localtime ${prefix}/etc - - -# -# 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 120000 index 0000000..0990ad8 --- /dev/null +++ b/hooks/debian/60-copy-host-files @@ -0,0 +1 @@ +../common/60-copy-host-files \ No newline at end of file diff --git a/hooks/debian/65-copy-user-files b/hooks/debian/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/debian/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/debian/65-copy-user-files b/hooks/debian/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/debian/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/debian/75-fixup-securetty b/hooks/debian/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/debian/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/debian/75-fixup-securetty b/hooks/debian/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/debian/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/debian/99-clean-image b/hooks/debian/99-clean-image deleted file mode 100755 index d36d438..0000000 --- a/hooks/debian/99-clean-image +++ /dev/null @@ -1,38 +0,0 @@ -#!/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 diff --git a/hooks/debian/99-clean-image b/hooks/debian/99-clean-image new file mode 120000 index 0000000..f850fb0 --- /dev/null +++ b/hooks/debian/99-clean-image @@ -0,0 +1 @@ +../common/99-clean-image \ No newline at end of file diff --git a/hooks/debian/99-enable-daemons b/hooks/debian/99-enable-daemons deleted file mode 100755 index c1eb25a..0000000 --- a/hooks/debian/99-enable-daemons +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script removes the file which prevents daemons from running. -# -# 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 - - -# -# Remove the script if present. -# -if [ -x "${prefix}/usr/sbin/policy-rc.d" ]; then - - rm -f "${prefix}/usr/sbin/policy-rc.d" - - logMessage "Removed: ${prefix}/usr/sbin/policy-rc.d" - -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/debian/99-enable-daemons b/hooks/debian/99-enable-daemons new file mode 120000 index 0000000..ada8e1f --- /dev/null +++ b/hooks/debian/99-enable-daemons @@ -0,0 +1 @@ +../common/99-enable-daemons \ No newline at end of file diff --git a/hooks/edgy/01-disable-daemons b/hooks/edgy/01-disable-daemons deleted file mode 100755 index d12d7bd..0000000 --- a/hooks/edgy/01-disable-daemons +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# -# This script ensures that daemons will not be started inside our -# chroot() installation. -# -# 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 a directory. -# -if [ ! -d "${prefix}/usr/sbin" ]; then - - mkdir -p "${prefix}/usr/sbin" - - logMessage "created missing directory: ${prefix}/usr/sbin" -fi - - -# -# Add the script. -# -echo '#!/bin/sh' > ${prefix}/usr/sbin/policy-rc.d -echo 'exit 101' >> ${prefix}/usr/sbin/policy-rc.d -chmod 755 ${prefix}/usr/sbin/policy-rc.d - - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/edgy/01-disable-daemons b/hooks/edgy/01-disable-daemons new file mode 120000 index 0000000..44e36b0 --- /dev/null +++ b/hooks/edgy/01-disable-daemons @@ -0,0 +1 @@ +../common/01-disable-daemons \ No newline at end of file diff --git a/hooks/edgy/05-shadowconfig-on b/hooks/edgy/05-shadowconfig-on deleted file mode 100755 index e5bcbb4..0000000 --- a/hooks/edgy/05-shadowconfig-on +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script enforces the use of a shadow password file. -# -# 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 - - -# -# Enable the shadow passwords if the command is found. -# -if [ -x ${prefix}/sbin/shadowconfig ]; then - - chroot ${prefix} /sbin/shadowconfig on -else - - logMessage "/sbin/shadowconfig not found. skipping." -fi - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/edgy/05-shadowconfig-on b/hooks/edgy/05-shadowconfig-on new file mode 120000 index 0000000..d165812 --- /dev/null +++ b/hooks/edgy/05-shadowconfig-on @@ -0,0 +1 @@ +../common/05-shadowconfig-on \ No newline at end of file diff --git a/hooks/edgy/15-disable-hwclock b/hooks/edgy/15-disable-hwclock deleted file mode 100755 index 74556ac..0000000 --- a/hooks/edgy/15-disable-hwclock +++ /dev/null @@ -1,38 +0,0 @@ -#!/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. -# -chroot ${prefix} /usr/sbin/update-rc.d -f hwclock.sh remove - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/edgy/15-disable-hwclock b/hooks/edgy/15-disable-hwclock new file mode 120000 index 0000000..0ecc42a --- /dev/null +++ b/hooks/edgy/15-disable-hwclock @@ -0,0 +1 @@ +../common/15-disable-hwclock \ No newline at end of file diff --git a/hooks/edgy/20-setup-apt b/hooks/edgy/20-setup-apt deleted file mode 100755 index 5833c47..0000000 --- a/hooks/edgy/20-setup-apt +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/sh -# -# This script sets up the /etc/apt/sources.list for APT. -# -# Steve -# -- -# - - - - -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 - - -# -# Attempt to auto-magically detect the use of a Proxy for apt-get, and -# replicate that setup in our new guest via apt-config dump and save -# the setting to the proxy guess file. -# -if [ ${apt_proxy} ]; then - echo "Acquire::http::Proxy \"${apt_proxy}\";" > ${prefix}/etc/apt/apt.conf.d/01proxy -else - logMessage The use of a proxy detected. - apt-config dump | grep -i Acquire::HTTP::Proxy > ${prefix}/etc/apt/apt.conf.d/01proxy -fi - - -# -# Setup the sources.list file for new installations of Ubuntu GNU/Linux. -# -cat < ${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 - - -# -# Now fixup TLS on non-64bit systems. -# -if [ "`uname -m`" = "x86_64" ]; then - - logMessage "Ignoring TLS since we're a 64 bit host." - -else - - logMessage "Installing libc6-xen" - installDebianPackage ${prefix} libc6-xen -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/edgy/20-setup-apt b/hooks/edgy/20-setup-apt new file mode 120000 index 0000000..a2bb0b9 --- /dev/null +++ b/hooks/edgy/20-setup-apt @@ -0,0 +1 @@ +../common/20-setup-apt \ No newline at end of file diff --git a/hooks/edgy/25-generate-locale b/hooks/edgy/25-generate-locale deleted file mode 100755 index ca2b099..0000000 --- a/hooks/edgy/25-generate-locale +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# -# This script generates a default en_US.UTF-8 locale. -# -# Ward -# -- - - - -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 the English language pack. -# -# NOTE: Failure to support your favourite language is *not* a bug. -# -installDebianPackage ${prefix} language-pack-en - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/edgy/25-generate-locale b/hooks/edgy/25-generate-locale new file mode 120000 index 0000000..91644b2 --- /dev/null +++ b/hooks/edgy/25-generate-locale @@ -0,0 +1 @@ +../common/25-generate-locale \ No newline at end of file diff --git a/hooks/edgy/35-setup-users b/hooks/edgy/35-setup-users deleted file mode 100755 index 1f80c58..0000000 --- a/hooks/edgy/35-setup-users +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/perl -w -# -# This script attempts to copy all user accounts from the host to -# the guest. It does this by copying all user accounts which are not -# already present. -# -# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' -# command line we don't do this. -# -# Steve -# -- -# http://www.steve.org.uk/ - - -use strict; -use Env; - - -my $prefix = shift; - -die "Prefix must be given" unless defined( $prefix ); -die "Prefix must be a directory" unless ( -d $prefix ); - - -# -# Exit unless the 'accounts' variable is set. -# -exit unless ( $ENV{'accounts'} ); - -# -# Make sure we have $prefix/etc -# -die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); - - -# -# Read all accounts from the installed /etc/passwd on the guest. -# -my %present; -if ( -e $prefix . "/etc/passwd" ) -{ - %present = readAccounts( $prefix . "/etc/passwd" ); -} - - -# -# Now read the accounts on the host. -# -my %host = readAccounts( "/etc/passwd" ); - - -# -# For each account not present on new installation then add it -# -foreach my $account ( sort keys( %host ) ) -{ - if ( ! $present{ $account } ) - { - print "Adding: $account\n"; - addAccount( $account ); - - # - # Find any groups the user is member of on the host - # and add them on the guest system - # - addGroups( $account ); - } -} - - - -# -# Read the accounts which are already present on the guest image. -# -sub readAccounts -{ - my ( $file ) = ( @_ ); - - - my %found; - - open( EXISTING, "<", $file ); - foreach my $line ( ) - { - # - # Record the userid + username - # - if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) - { - my $user = $1; - my $pass = $2; - my $uid = $3; - - $found{$user} = 1; - } - } - close( EXISTING ); - - return( %found ); -} - - - - -# -# Add the passwd + shadow accounts for the given user. -# -sub addAccount -{ - my ( $user ) = ( @_ ); - - # - # passwd file. - # - open( PASSWD, "<", "/etc/passwd" ); - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/passwd" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( PASSWD ); - - - # - # shadow file. - # - open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/shadow" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( SHADOW ); -} - - - -# -# Find the groups a user is member of on the host, and add them to -# those groups on the new guest. -# -sub addGroups -{ - my( $username ) = ( @_ ); - - # - # Get the groups. - # - my $groups = `groups $username`; - # split off the usernmame. - if ( $groups =~ /^([^:]+):(.*)/ ) - { - $groups = $2; - print "User: $username is member of the groups: $groups\n"; - } - - foreach my $g ( split( / /, $groups ) ) - { - # Make sure the group exists. - system( "chroot $prefix /usr/sbin/addgroup $g" ); - - # add the user to it. - system( "chroot $prefix /usr/sbin/adduser $username $g" ); - } -} diff --git a/hooks/edgy/35-setup-users b/hooks/edgy/35-setup-users new file mode 120000 index 0000000..d9bff4c --- /dev/null +++ b/hooks/edgy/35-setup-users @@ -0,0 +1 @@ +../common/35-setup-users \ No newline at end of file diff --git a/hooks/edgy/50-setup-hostname b/hooks/edgy/50-setup-hostname deleted file mode 100755 index 5c89336..0000000 --- a/hooks/edgy/50-setup-hostname +++ /dev/null @@ -1,141 +0,0 @@ -#!/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 - -# -# Determine the FQDN and Hostname -# -GUEST_FQDN=${hostname} -GUEST_HOSTNAME=`echo $GUEST_FQDN | awk -F'.' '{print $1}'` - -# -# Setup the mailname + hostname files. -# -echo $GUEST_HOSTNAME > ${prefix}/etc/hostname -echo $GUEST_FQDN > ${prefix}/etc/mailname - - -# -# Fixup the /etc/hosts file upon the new image for -# machines with static IPs -# -if [ -z "${copyhosts}" ]; then - # - # Copy localhost - # - cat > ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts < ${prefix}/etc/hosts - - # New entry. - if [ -z "${dhcp}" ]; then - cat >> ${prefix}/etc/hosts <> ${prefix}/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 $GUEST_FQDN /etc/hosts > /dev/null ) ; then - - logMessage Host already has IP address for the host $GUEST_FQDN. - - else - if [ -z "${nohosts}" ]; then - - logMessage Adding $GUEST_FQDN and $GUEST_HOSTNAME to /etc/hosts on the host - echo "${ip1} $GUEST_FQDN $GUEST_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 -s HUP `cat /var/run/dnsmasq.pid` - fi - fi - fi - fi -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/edgy/50-setup-hostname b/hooks/edgy/50-setup-hostname new file mode 120000 index 0000000..509952f --- /dev/null +++ b/hooks/edgy/50-setup-hostname @@ -0,0 +1 @@ +../common/50-setup-hostname \ No newline at end of file diff --git a/hooks/edgy/60-copy-host-files b/hooks/edgy/60-copy-host-files deleted file mode 100755 index 8da3b93..0000000 --- a/hooks/edgy/60-copy-host-files +++ /dev/null @@ -1,37 +0,0 @@ -#!/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 "required" files from our host. -# -cp /etc/timezone ${prefix}/etc -cp /etc/localtime ${prefix}/etc - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/edgy/60-copy-host-files b/hooks/edgy/60-copy-host-files new file mode 120000 index 0000000..0990ad8 --- /dev/null +++ b/hooks/edgy/60-copy-host-files @@ -0,0 +1 @@ +../common/60-copy-host-files \ No newline at end of file diff --git a/hooks/edgy/65-copy-user-files b/hooks/edgy/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/edgy/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/edgy/65-copy-user-files b/hooks/edgy/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/edgy/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/edgy/75-fixup-securetty b/hooks/edgy/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/edgy/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/edgy/75-fixup-securetty b/hooks/edgy/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/edgy/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/edgy/99-clean-image b/hooks/edgy/99-clean-image deleted file mode 100755 index d36d438..0000000 --- a/hooks/edgy/99-clean-image +++ /dev/null @@ -1,38 +0,0 @@ -#!/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 diff --git a/hooks/edgy/99-clean-image b/hooks/edgy/99-clean-image new file mode 120000 index 0000000..f850fb0 --- /dev/null +++ b/hooks/edgy/99-clean-image @@ -0,0 +1 @@ +../common/99-clean-image \ No newline at end of file diff --git a/hooks/edgy/99-enable-daemons b/hooks/edgy/99-enable-daemons deleted file mode 100755 index c1eb25a..0000000 --- a/hooks/edgy/99-enable-daemons +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script removes the file which prevents daemons from running. -# -# 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 - - -# -# Remove the script if present. -# -if [ -x "${prefix}/usr/sbin/policy-rc.d" ]; then - - rm -f "${prefix}/usr/sbin/policy-rc.d" - - logMessage "Removed: ${prefix}/usr/sbin/policy-rc.d" - -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/edgy/99-enable-daemons b/hooks/edgy/99-enable-daemons new file mode 120000 index 0000000..ada8e1f --- /dev/null +++ b/hooks/edgy/99-enable-daemons @@ -0,0 +1 @@ +../common/99-enable-daemons \ No newline at end of file diff --git a/hooks/fedora-core-6/10-disable-tls b/hooks/fedora-core-6/10-disable-tls deleted file mode 100755 index a80edd6..0000000 --- a/hooks/fedora-core-6/10-disable-tls +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 - - -# -# Don't touch TLS on 64 bit platforms. -# -if [ "`uname -m`" = "x86_64" ]; then - logMessage "Ignoring TLS since we're a 64 bit host." - exit -fi - - -# -# Disable TLS and create an empty directory in its place -# -mv ${prefix}/lib/tls ${prefix}/lib/tls.disabled -mkdir ${prefix}/lib/tls - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/fedora-core-6/10-disable-tls b/hooks/fedora-core-6/10-disable-tls new file mode 120000 index 0000000..9ae8088 --- /dev/null +++ b/hooks/fedora-core-6/10-disable-tls @@ -0,0 +1 @@ +../common/10-disable-tls \ No newline at end of file diff --git a/hooks/fedora-core-6/15-setup-arch b/hooks/fedora-core-6/15-setup-arch deleted file mode 100755 index 569d572..0000000 --- a/hooks/fedora-core-6/15-setup-arch +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -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 - - -# -# Record arch, if present. -# -if [ -d $prefix/etc/rpm ]; then - - logMessage Found /etc/rpm - - # - # If i386 then record this - # - if [ "$arch" = "i386" ]; then - echo "i386-fedora-linux-gnu" >> $prefix/etc/rpm/platform - fi -else - - logMessage Failed to find /etc/rpm - -fi - -# -# Log our finish -# -logMessage Script $0 finished - diff --git a/hooks/fedora-core-6/15-setup-arch b/hooks/fedora-core-6/15-setup-arch new file mode 120000 index 0000000..0ecc42a --- /dev/null +++ b/hooks/fedora-core-6/15-setup-arch @@ -0,0 +1 @@ +../common/15-disable-hwclock \ No newline at end of file diff --git a/hooks/fedora-core-6/55-create-dev b/hooks/fedora-core-6/55-create-dev deleted file mode 100755 index 89577ce..0000000 --- a/hooks/fedora-core-6/55-create-dev +++ /dev/null @@ -1,53 +0,0 @@ -#!/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 - - - -# -# Early termination if we have a couple of common devices present -# should speed up installs which use --copy/--tar -# -if ( test `ls -1 ${prefix}/dev | wc -l` -gt 10 ); then - logMessage "Terminating because there appear to be files in /dev already" - exit -fi - - -# -# Make the device nodes. -# -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV console' -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV null' -chroot ${prefix} /bin/sh -c 'cd /dev && ./MAKEDEV zero' - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/fedora-core-6/55-create-dev b/hooks/fedora-core-6/55-create-dev new file mode 120000 index 0000000..1f725c9 --- /dev/null +++ b/hooks/fedora-core-6/55-create-dev @@ -0,0 +1 @@ +../common/55-create-dev \ No newline at end of file diff --git a/hooks/fedora-core-6/65-copy-user-files b/hooks/fedora-core-6/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/fedora-core-6/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/fedora-core-6/65-copy-user-files b/hooks/fedora-core-6/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/fedora-core-6/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/fedora-core-6/75-fixup-securetty b/hooks/fedora-core-6/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/fedora-core-6/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/fedora-core-6/75-fixup-securetty b/hooks/fedora-core-6/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/fedora-core-6/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/gentoo/35-setup-users b/hooks/gentoo/35-setup-users deleted file mode 100755 index 1f80c58..0000000 --- a/hooks/gentoo/35-setup-users +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/perl -w -# -# This script attempts to copy all user accounts from the host to -# the guest. It does this by copying all user accounts which are not -# already present. -# -# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' -# command line we don't do this. -# -# Steve -# -- -# http://www.steve.org.uk/ - - -use strict; -use Env; - - -my $prefix = shift; - -die "Prefix must be given" unless defined( $prefix ); -die "Prefix must be a directory" unless ( -d $prefix ); - - -# -# Exit unless the 'accounts' variable is set. -# -exit unless ( $ENV{'accounts'} ); - -# -# Make sure we have $prefix/etc -# -die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); - - -# -# Read all accounts from the installed /etc/passwd on the guest. -# -my %present; -if ( -e $prefix . "/etc/passwd" ) -{ - %present = readAccounts( $prefix . "/etc/passwd" ); -} - - -# -# Now read the accounts on the host. -# -my %host = readAccounts( "/etc/passwd" ); - - -# -# For each account not present on new installation then add it -# -foreach my $account ( sort keys( %host ) ) -{ - if ( ! $present{ $account } ) - { - print "Adding: $account\n"; - addAccount( $account ); - - # - # Find any groups the user is member of on the host - # and add them on the guest system - # - addGroups( $account ); - } -} - - - -# -# Read the accounts which are already present on the guest image. -# -sub readAccounts -{ - my ( $file ) = ( @_ ); - - - my %found; - - open( EXISTING, "<", $file ); - foreach my $line ( ) - { - # - # Record the userid + username - # - if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) - { - my $user = $1; - my $pass = $2; - my $uid = $3; - - $found{$user} = 1; - } - } - close( EXISTING ); - - return( %found ); -} - - - - -# -# Add the passwd + shadow accounts for the given user. -# -sub addAccount -{ - my ( $user ) = ( @_ ); - - # - # passwd file. - # - open( PASSWD, "<", "/etc/passwd" ); - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/passwd" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( PASSWD ); - - - # - # shadow file. - # - open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/shadow" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( SHADOW ); -} - - - -# -# Find the groups a user is member of on the host, and add them to -# those groups on the new guest. -# -sub addGroups -{ - my( $username ) = ( @_ ); - - # - # Get the groups. - # - my $groups = `groups $username`; - # split off the usernmame. - if ( $groups =~ /^([^:]+):(.*)/ ) - { - $groups = $2; - print "User: $username is member of the groups: $groups\n"; - } - - foreach my $g ( split( / /, $groups ) ) - { - # Make sure the group exists. - system( "chroot $prefix /usr/sbin/addgroup $g" ); - - # add the user to it. - system( "chroot $prefix /usr/sbin/adduser $username $g" ); - } -} diff --git a/hooks/gentoo/35-setup-users b/hooks/gentoo/35-setup-users new file mode 120000 index 0000000..d9bff4c --- /dev/null +++ b/hooks/gentoo/35-setup-users @@ -0,0 +1 @@ +../common/35-setup-users \ No newline at end of file diff --git a/hooks/gentoo/65-copy-user-files b/hooks/gentoo/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/gentoo/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/gentoo/65-copy-user-files b/hooks/gentoo/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/gentoo/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/gentoo/75-fixup-securetty b/hooks/gentoo/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/gentoo/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/gentoo/75-fixup-securetty b/hooks/gentoo/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/gentoo/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/intrepid/01-disable-daemons b/hooks/intrepid/01-disable-daemons deleted file mode 100755 index d12d7bd..0000000 --- a/hooks/intrepid/01-disable-daemons +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# -# This script ensures that daemons will not be started inside our -# chroot() installation. -# -# 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 a directory. -# -if [ ! -d "${prefix}/usr/sbin" ]; then - - mkdir -p "${prefix}/usr/sbin" - - logMessage "created missing directory: ${prefix}/usr/sbin" -fi - - -# -# Add the script. -# -echo '#!/bin/sh' > ${prefix}/usr/sbin/policy-rc.d -echo 'exit 101' >> ${prefix}/usr/sbin/policy-rc.d -chmod 755 ${prefix}/usr/sbin/policy-rc.d - - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/intrepid/01-disable-daemons b/hooks/intrepid/01-disable-daemons new file mode 120000 index 0000000..44e36b0 --- /dev/null +++ b/hooks/intrepid/01-disable-daemons @@ -0,0 +1 @@ +../common/01-disable-daemons \ No newline at end of file diff --git a/hooks/intrepid/05-shadowconfig-on b/hooks/intrepid/05-shadowconfig-on deleted file mode 100755 index e5bcbb4..0000000 --- a/hooks/intrepid/05-shadowconfig-on +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script enforces the use of a shadow password file. -# -# 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 - - -# -# Enable the shadow passwords if the command is found. -# -if [ -x ${prefix}/sbin/shadowconfig ]; then - - chroot ${prefix} /sbin/shadowconfig on -else - - logMessage "/sbin/shadowconfig not found. skipping." -fi - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/intrepid/05-shadowconfig-on b/hooks/intrepid/05-shadowconfig-on new file mode 120000 index 0000000..d165812 --- /dev/null +++ b/hooks/intrepid/05-shadowconfig-on @@ -0,0 +1 @@ +../common/05-shadowconfig-on \ No newline at end of file diff --git a/hooks/intrepid/15-disable-hwclock b/hooks/intrepid/15-disable-hwclock deleted file mode 100755 index 74556ac..0000000 --- a/hooks/intrepid/15-disable-hwclock +++ /dev/null @@ -1,38 +0,0 @@ -#!/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. -# -chroot ${prefix} /usr/sbin/update-rc.d -f hwclock.sh remove - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/intrepid/15-disable-hwclock b/hooks/intrepid/15-disable-hwclock new file mode 120000 index 0000000..0ecc42a --- /dev/null +++ b/hooks/intrepid/15-disable-hwclock @@ -0,0 +1 @@ +../common/15-disable-hwclock \ No newline at end of file diff --git a/hooks/intrepid/20-setup-apt b/hooks/intrepid/20-setup-apt deleted file mode 100755 index 5833c47..0000000 --- a/hooks/intrepid/20-setup-apt +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/sh -# -# This script sets up the /etc/apt/sources.list for APT. -# -# Steve -# -- -# - - - - -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 - - -# -# Attempt to auto-magically detect the use of a Proxy for apt-get, and -# replicate that setup in our new guest via apt-config dump and save -# the setting to the proxy guess file. -# -if [ ${apt_proxy} ]; then - echo "Acquire::http::Proxy \"${apt_proxy}\";" > ${prefix}/etc/apt/apt.conf.d/01proxy -else - logMessage The use of a proxy detected. - apt-config dump | grep -i Acquire::HTTP::Proxy > ${prefix}/etc/apt/apt.conf.d/01proxy -fi - - -# -# Setup the sources.list file for new installations of Ubuntu GNU/Linux. -# -cat < ${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 - - -# -# Now fixup TLS on non-64bit systems. -# -if [ "`uname -m`" = "x86_64" ]; then - - logMessage "Ignoring TLS since we're a 64 bit host." - -else - - logMessage "Installing libc6-xen" - installDebianPackage ${prefix} libc6-xen -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/intrepid/20-setup-apt b/hooks/intrepid/20-setup-apt new file mode 120000 index 0000000..a2bb0b9 --- /dev/null +++ b/hooks/intrepid/20-setup-apt @@ -0,0 +1 @@ +../common/20-setup-apt \ No newline at end of file diff --git a/hooks/intrepid/25-generate-locale b/hooks/intrepid/25-generate-locale deleted file mode 100755 index ca2b099..0000000 --- a/hooks/intrepid/25-generate-locale +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# -# This script generates a default en_US.UTF-8 locale. -# -# Ward -# -- - - - -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 the English language pack. -# -# NOTE: Failure to support your favourite language is *not* a bug. -# -installDebianPackage ${prefix} language-pack-en - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/intrepid/25-generate-locale b/hooks/intrepid/25-generate-locale new file mode 120000 index 0000000..91644b2 --- /dev/null +++ b/hooks/intrepid/25-generate-locale @@ -0,0 +1 @@ +../common/25-generate-locale \ No newline at end of file diff --git a/hooks/intrepid/35-setup-users b/hooks/intrepid/35-setup-users deleted file mode 100755 index 1f80c58..0000000 --- a/hooks/intrepid/35-setup-users +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/perl -w -# -# This script attempts to copy all user accounts from the host to -# the guest. It does this by copying all user accounts which are not -# already present. -# -# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' -# command line we don't do this. -# -# Steve -# -- -# http://www.steve.org.uk/ - - -use strict; -use Env; - - -my $prefix = shift; - -die "Prefix must be given" unless defined( $prefix ); -die "Prefix must be a directory" unless ( -d $prefix ); - - -# -# Exit unless the 'accounts' variable is set. -# -exit unless ( $ENV{'accounts'} ); - -# -# Make sure we have $prefix/etc -# -die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); - - -# -# Read all accounts from the installed /etc/passwd on the guest. -# -my %present; -if ( -e $prefix . "/etc/passwd" ) -{ - %present = readAccounts( $prefix . "/etc/passwd" ); -} - - -# -# Now read the accounts on the host. -# -my %host = readAccounts( "/etc/passwd" ); - - -# -# For each account not present on new installation then add it -# -foreach my $account ( sort keys( %host ) ) -{ - if ( ! $present{ $account } ) - { - print "Adding: $account\n"; - addAccount( $account ); - - # - # Find any groups the user is member of on the host - # and add them on the guest system - # - addGroups( $account ); - } -} - - - -# -# Read the accounts which are already present on the guest image. -# -sub readAccounts -{ - my ( $file ) = ( @_ ); - - - my %found; - - open( EXISTING, "<", $file ); - foreach my $line ( ) - { - # - # Record the userid + username - # - if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) - { - my $user = $1; - my $pass = $2; - my $uid = $3; - - $found{$user} = 1; - } - } - close( EXISTING ); - - return( %found ); -} - - - - -# -# Add the passwd + shadow accounts for the given user. -# -sub addAccount -{ - my ( $user ) = ( @_ ); - - # - # passwd file. - # - open( PASSWD, "<", "/etc/passwd" ); - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/passwd" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( PASSWD ); - - - # - # shadow file. - # - open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/shadow" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( SHADOW ); -} - - - -# -# Find the groups a user is member of on the host, and add them to -# those groups on the new guest. -# -sub addGroups -{ - my( $username ) = ( @_ ); - - # - # Get the groups. - # - my $groups = `groups $username`; - # split off the usernmame. - if ( $groups =~ /^([^:]+):(.*)/ ) - { - $groups = $2; - print "User: $username is member of the groups: $groups\n"; - } - - foreach my $g ( split( / /, $groups ) ) - { - # Make sure the group exists. - system( "chroot $prefix /usr/sbin/addgroup $g" ); - - # add the user to it. - system( "chroot $prefix /usr/sbin/adduser $username $g" ); - } -} diff --git a/hooks/intrepid/35-setup-users b/hooks/intrepid/35-setup-users new file mode 120000 index 0000000..d9bff4c --- /dev/null +++ b/hooks/intrepid/35-setup-users @@ -0,0 +1 @@ +../common/35-setup-users \ No newline at end of file diff --git a/hooks/intrepid/50-setup-hostname b/hooks/intrepid/50-setup-hostname deleted file mode 100755 index 5c89336..0000000 --- a/hooks/intrepid/50-setup-hostname +++ /dev/null @@ -1,141 +0,0 @@ -#!/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 - -# -# Determine the FQDN and Hostname -# -GUEST_FQDN=${hostname} -GUEST_HOSTNAME=`echo $GUEST_FQDN | awk -F'.' '{print $1}'` - -# -# Setup the mailname + hostname files. -# -echo $GUEST_HOSTNAME > ${prefix}/etc/hostname -echo $GUEST_FQDN > ${prefix}/etc/mailname - - -# -# Fixup the /etc/hosts file upon the new image for -# machines with static IPs -# -if [ -z "${copyhosts}" ]; then - # - # Copy localhost - # - cat > ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts < ${prefix}/etc/hosts - - # New entry. - if [ -z "${dhcp}" ]; then - cat >> ${prefix}/etc/hosts <> ${prefix}/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 $GUEST_FQDN /etc/hosts > /dev/null ) ; then - - logMessage Host already has IP address for the host $GUEST_FQDN. - - else - if [ -z "${nohosts}" ]; then - - logMessage Adding $GUEST_FQDN and $GUEST_HOSTNAME to /etc/hosts on the host - echo "${ip1} $GUEST_FQDN $GUEST_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 -s HUP `cat /var/run/dnsmasq.pid` - fi - fi - fi - fi -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/intrepid/50-setup-hostname b/hooks/intrepid/50-setup-hostname new file mode 120000 index 0000000..509952f --- /dev/null +++ b/hooks/intrepid/50-setup-hostname @@ -0,0 +1 @@ +../common/50-setup-hostname \ No newline at end of file diff --git a/hooks/intrepid/60-copy-host-files b/hooks/intrepid/60-copy-host-files deleted file mode 100755 index 8da3b93..0000000 --- a/hooks/intrepid/60-copy-host-files +++ /dev/null @@ -1,37 +0,0 @@ -#!/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 "required" files from our host. -# -cp /etc/timezone ${prefix}/etc -cp /etc/localtime ${prefix}/etc - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/intrepid/60-copy-host-files b/hooks/intrepid/60-copy-host-files new file mode 120000 index 0000000..0990ad8 --- /dev/null +++ b/hooks/intrepid/60-copy-host-files @@ -0,0 +1 @@ +../common/60-copy-host-files \ No newline at end of file diff --git a/hooks/intrepid/65-copy-user-files b/hooks/intrepid/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/intrepid/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/intrepid/65-copy-user-files b/hooks/intrepid/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/intrepid/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/intrepid/75-fixup-securetty b/hooks/intrepid/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/intrepid/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/intrepid/75-fixup-securetty b/hooks/intrepid/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/intrepid/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/intrepid/99-clean-image b/hooks/intrepid/99-clean-image deleted file mode 100755 index d36d438..0000000 --- a/hooks/intrepid/99-clean-image +++ /dev/null @@ -1,38 +0,0 @@ -#!/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 diff --git a/hooks/intrepid/99-clean-image b/hooks/intrepid/99-clean-image new file mode 120000 index 0000000..f850fb0 --- /dev/null +++ b/hooks/intrepid/99-clean-image @@ -0,0 +1 @@ +../common/99-clean-image \ No newline at end of file diff --git a/hooks/intrepid/99-enable-daemons b/hooks/intrepid/99-enable-daemons deleted file mode 100755 index c1eb25a..0000000 --- a/hooks/intrepid/99-enable-daemons +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script removes the file which prevents daemons from running. -# -# 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 - - -# -# Remove the script if present. -# -if [ -x "${prefix}/usr/sbin/policy-rc.d" ]; then - - rm -f "${prefix}/usr/sbin/policy-rc.d" - - logMessage "Removed: ${prefix}/usr/sbin/policy-rc.d" - -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/intrepid/99-enable-daemons b/hooks/intrepid/99-enable-daemons new file mode 120000 index 0000000..ada8e1f --- /dev/null +++ b/hooks/intrepid/99-enable-daemons @@ -0,0 +1 @@ +../common/99-enable-daemons \ No newline at end of file diff --git a/hooks/karmic/01-disable-daemons b/hooks/karmic/01-disable-daemons deleted file mode 100755 index d12d7bd..0000000 --- a/hooks/karmic/01-disable-daemons +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# -# This script ensures that daemons will not be started inside our -# chroot() installation. -# -# 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 a directory. -# -if [ ! -d "${prefix}/usr/sbin" ]; then - - mkdir -p "${prefix}/usr/sbin" - - logMessage "created missing directory: ${prefix}/usr/sbin" -fi - - -# -# Add the script. -# -echo '#!/bin/sh' > ${prefix}/usr/sbin/policy-rc.d -echo 'exit 101' >> ${prefix}/usr/sbin/policy-rc.d -chmod 755 ${prefix}/usr/sbin/policy-rc.d - - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/karmic/01-disable-daemons b/hooks/karmic/01-disable-daemons new file mode 120000 index 0000000..44e36b0 --- /dev/null +++ b/hooks/karmic/01-disable-daemons @@ -0,0 +1 @@ +../common/01-disable-daemons \ No newline at end of file diff --git a/hooks/karmic/05-shadowconfig-on b/hooks/karmic/05-shadowconfig-on deleted file mode 100755 index e5bcbb4..0000000 --- a/hooks/karmic/05-shadowconfig-on +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script enforces the use of a shadow password file. -# -# 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 - - -# -# Enable the shadow passwords if the command is found. -# -if [ -x ${prefix}/sbin/shadowconfig ]; then - - chroot ${prefix} /sbin/shadowconfig on -else - - logMessage "/sbin/shadowconfig not found. skipping." -fi - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/karmic/05-shadowconfig-on b/hooks/karmic/05-shadowconfig-on new file mode 120000 index 0000000..d165812 --- /dev/null +++ b/hooks/karmic/05-shadowconfig-on @@ -0,0 +1 @@ +../common/05-shadowconfig-on \ No newline at end of file diff --git a/hooks/karmic/15-disable-hwclock b/hooks/karmic/15-disable-hwclock deleted file mode 100755 index 74556ac..0000000 --- a/hooks/karmic/15-disable-hwclock +++ /dev/null @@ -1,38 +0,0 @@ -#!/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. -# -chroot ${prefix} /usr/sbin/update-rc.d -f hwclock.sh remove - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/karmic/15-disable-hwclock b/hooks/karmic/15-disable-hwclock new file mode 120000 index 0000000..0ecc42a --- /dev/null +++ b/hooks/karmic/15-disable-hwclock @@ -0,0 +1 @@ +../common/15-disable-hwclock \ No newline at end of file diff --git a/hooks/karmic/20-setup-apt b/hooks/karmic/20-setup-apt deleted file mode 100755 index 5833c47..0000000 --- a/hooks/karmic/20-setup-apt +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/sh -# -# This script sets up the /etc/apt/sources.list for APT. -# -# Steve -# -- -# - - - - -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 - - -# -# Attempt to auto-magically detect the use of a Proxy for apt-get, and -# replicate that setup in our new guest via apt-config dump and save -# the setting to the proxy guess file. -# -if [ ${apt_proxy} ]; then - echo "Acquire::http::Proxy \"${apt_proxy}\";" > ${prefix}/etc/apt/apt.conf.d/01proxy -else - logMessage The use of a proxy detected. - apt-config dump | grep -i Acquire::HTTP::Proxy > ${prefix}/etc/apt/apt.conf.d/01proxy -fi - - -# -# Setup the sources.list file for new installations of Ubuntu GNU/Linux. -# -cat < ${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 - - -# -# Now fixup TLS on non-64bit systems. -# -if [ "`uname -m`" = "x86_64" ]; then - - logMessage "Ignoring TLS since we're a 64 bit host." - -else - - logMessage "Installing libc6-xen" - installDebianPackage ${prefix} libc6-xen -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/karmic/20-setup-apt b/hooks/karmic/20-setup-apt new file mode 120000 index 0000000..a2bb0b9 --- /dev/null +++ b/hooks/karmic/20-setup-apt @@ -0,0 +1 @@ +../common/20-setup-apt \ No newline at end of file diff --git a/hooks/karmic/25-generate-locale b/hooks/karmic/25-generate-locale deleted file mode 100755 index ca2b099..0000000 --- a/hooks/karmic/25-generate-locale +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# -# This script generates a default en_US.UTF-8 locale. -# -# Ward -# -- - - - -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 the English language pack. -# -# NOTE: Failure to support your favourite language is *not* a bug. -# -installDebianPackage ${prefix} language-pack-en - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/karmic/25-generate-locale b/hooks/karmic/25-generate-locale new file mode 120000 index 0000000..91644b2 --- /dev/null +++ b/hooks/karmic/25-generate-locale @@ -0,0 +1 @@ +../common/25-generate-locale \ No newline at end of file diff --git a/hooks/karmic/35-setup-users b/hooks/karmic/35-setup-users deleted file mode 100755 index 1f80c58..0000000 --- a/hooks/karmic/35-setup-users +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/perl -w -# -# This script attempts to copy all user accounts from the host to -# the guest. It does this by copying all user accounts which are not -# already present. -# -# NOTE: Unless '--accounts' was specified upon the 'xen-create-image' -# command line we don't do this. -# -# Steve -# -- -# http://www.steve.org.uk/ - - -use strict; -use Env; - - -my $prefix = shift; - -die "Prefix must be given" unless defined( $prefix ); -die "Prefix must be a directory" unless ( -d $prefix ); - - -# -# Exit unless the 'accounts' variable is set. -# -exit unless ( $ENV{'accounts'} ); - -# -# Make sure we have $prefix/etc -# -die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" ); - - -# -# Read all accounts from the installed /etc/passwd on the guest. -# -my %present; -if ( -e $prefix . "/etc/passwd" ) -{ - %present = readAccounts( $prefix . "/etc/passwd" ); -} - - -# -# Now read the accounts on the host. -# -my %host = readAccounts( "/etc/passwd" ); - - -# -# For each account not present on new installation then add it -# -foreach my $account ( sort keys( %host ) ) -{ - if ( ! $present{ $account } ) - { - print "Adding: $account\n"; - addAccount( $account ); - - # - # Find any groups the user is member of on the host - # and add them on the guest system - # - addGroups( $account ); - } -} - - - -# -# Read the accounts which are already present on the guest image. -# -sub readAccounts -{ - my ( $file ) = ( @_ ); - - - my %found; - - open( EXISTING, "<", $file ); - foreach my $line ( ) - { - # - # Record the userid + username - # - if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ ) - { - my $user = $1; - my $pass = $2; - my $uid = $3; - - $found{$user} = 1; - } - } - close( EXISTING ); - - return( %found ); -} - - - - -# -# Add the passwd + shadow accounts for the given user. -# -sub addAccount -{ - my ( $user ) = ( @_ ); - - # - # passwd file. - # - open( PASSWD, "<", "/etc/passwd" ); - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/passwd" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( PASSWD ); - - - # - # shadow file. - # - open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!"; - foreach my $line ( ) - { - chomp( $line ); - if ( $line =~ /^\Q$user\E:/ ) - { - # - # Add the line - # - open( OUTY, ">>", $prefix . "/etc/shadow" ); - print OUTY $line . "\n"; - close( OUTY ); - } - } - close( SHADOW ); -} - - - -# -# Find the groups a user is member of on the host, and add them to -# those groups on the new guest. -# -sub addGroups -{ - my( $username ) = ( @_ ); - - # - # Get the groups. - # - my $groups = `groups $username`; - # split off the usernmame. - if ( $groups =~ /^([^:]+):(.*)/ ) - { - $groups = $2; - print "User: $username is member of the groups: $groups\n"; - } - - foreach my $g ( split( / /, $groups ) ) - { - # Make sure the group exists. - system( "chroot $prefix /usr/sbin/addgroup $g" ); - - # add the user to it. - system( "chroot $prefix /usr/sbin/adduser $username $g" ); - } -} diff --git a/hooks/karmic/35-setup-users b/hooks/karmic/35-setup-users new file mode 120000 index 0000000..d9bff4c --- /dev/null +++ b/hooks/karmic/35-setup-users @@ -0,0 +1 @@ +../common/35-setup-users \ No newline at end of file diff --git a/hooks/karmic/50-setup-hostname b/hooks/karmic/50-setup-hostname deleted file mode 100755 index 5c89336..0000000 --- a/hooks/karmic/50-setup-hostname +++ /dev/null @@ -1,141 +0,0 @@ -#!/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 - -# -# Determine the FQDN and Hostname -# -GUEST_FQDN=${hostname} -GUEST_HOSTNAME=`echo $GUEST_FQDN | awk -F'.' '{print $1}'` - -# -# Setup the mailname + hostname files. -# -echo $GUEST_HOSTNAME > ${prefix}/etc/hostname -echo $GUEST_FQDN > ${prefix}/etc/mailname - - -# -# Fixup the /etc/hosts file upon the new image for -# machines with static IPs -# -if [ -z "${copyhosts}" ]; then - # - # Copy localhost - # - cat > ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts <> ${prefix}/etc/hosts < ${prefix}/etc/hosts - - # New entry. - if [ -z "${dhcp}" ]; then - cat >> ${prefix}/etc/hosts <> ${prefix}/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 $GUEST_FQDN /etc/hosts > /dev/null ) ; then - - logMessage Host already has IP address for the host $GUEST_FQDN. - - else - if [ -z "${nohosts}" ]; then - - logMessage Adding $GUEST_FQDN and $GUEST_HOSTNAME to /etc/hosts on the host - echo "${ip1} $GUEST_FQDN $GUEST_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 -s HUP `cat /var/run/dnsmasq.pid` - fi - fi - fi - fi -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/karmic/50-setup-hostname b/hooks/karmic/50-setup-hostname new file mode 120000 index 0000000..509952f --- /dev/null +++ b/hooks/karmic/50-setup-hostname @@ -0,0 +1 @@ +../common/50-setup-hostname \ No newline at end of file diff --git a/hooks/karmic/60-copy-host-files b/hooks/karmic/60-copy-host-files deleted file mode 100755 index 8da3b93..0000000 --- a/hooks/karmic/60-copy-host-files +++ /dev/null @@ -1,37 +0,0 @@ -#!/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 "required" files from our host. -# -cp /etc/timezone ${prefix}/etc -cp /etc/localtime ${prefix}/etc - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/karmic/60-copy-host-files b/hooks/karmic/60-copy-host-files new file mode 120000 index 0000000..0990ad8 --- /dev/null +++ b/hooks/karmic/60-copy-host-files @@ -0,0 +1 @@ +../common/60-copy-host-files \ No newline at end of file diff --git a/hooks/karmic/65-copy-user-files b/hooks/karmic/65-copy-user-files deleted file mode 100755 index a34fe94..0000000 --- a/hooks/karmic/65-copy-user-files +++ /dev/null @@ -1,49 +0,0 @@ -#!/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 diff --git a/hooks/karmic/65-copy-user-files b/hooks/karmic/65-copy-user-files new file mode 120000 index 0000000..afde6e2 --- /dev/null +++ b/hooks/karmic/65-copy-user-files @@ -0,0 +1 @@ +../common/65-copy-user-files \ No newline at end of file diff --git a/hooks/karmic/75-fixup-securetty b/hooks/karmic/75-fixup-securetty deleted file mode 100755 index 58ab907..0000000 --- a/hooks/karmic/75-fixup-securetty +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# -# This script ensures /etc/securetty upon the new guests has the new -# Xen console devices in it -# -# 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 - -# -# If the file doesn't exist exit early. -# -if [ ! -e ${prefix}/etc/securetty ]; then - logMessage /etc/securetty not found. - exit -fi - - -# -# Do both the devices. -# -for i in xvc0 hvc0 ; do - - # - # Only append if not presnt. - # - if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then - - logMessage Host already has $i entry - - else - - echo $i >> ${prefix}/etc/securetty - fi - -done - - -# -# Log our finish -# -logMessage Script $0 finished. - diff --git a/hooks/karmic/75-fixup-securetty b/hooks/karmic/75-fixup-securetty new file mode 120000 index 0000000..e793d9e --- /dev/null +++ b/hooks/karmic/75-fixup-securetty @@ -0,0 +1 @@ +../common/75-fixup-securetty \ No newline at end of file diff --git a/hooks/karmic/99-clean-image b/hooks/karmic/99-clean-image deleted file mode 100755 index d36d438..0000000 --- a/hooks/karmic/99-clean-image +++ /dev/null @@ -1,38 +0,0 @@ -#!/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 diff --git a/hooks/karmic/99-clean-image b/hooks/karmic/99-clean-image new file mode 120000 index 0000000..f850fb0 --- /dev/null +++ b/hooks/karmic/99-clean-image @@ -0,0 +1 @@ +../common/99-clean-image \ No newline at end of file diff --git a/hooks/karmic/99-enable-daemons b/hooks/karmic/99-enable-daemons deleted file mode 100755 index c1eb25a..0000000 --- a/hooks/karmic/99-enable-daemons +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# -# This script removes the file which prevents daemons from running. -# -# 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 - - -# -# Remove the script if present. -# -if [ -x "${prefix}/usr/sbin/policy-rc.d" ]; then - - rm -f "${prefix}/usr/sbin/policy-rc.d" - - logMessage "Removed: ${prefix}/usr/sbin/policy-rc.d" - -fi - - -# -# Log our finish -# -logMessage Script $0 finished diff --git a/hooks/karmic/99-enable-daemons b/hooks/karmic/99-enable-daemons new file mode 120000 index 0000000..ada8e1f --- /dev/null +++ b/hooks/karmic/99-enable-daemons @@ -0,0 +1 @@ +../common/99-enable-daemons \ No newline at end of file diff --git a/t/hook-hostname.t b/t/hook-hostname.t index 6d3ae65..808bc64 100755 --- a/t/hook-hostname.t +++ b/t/hook-hostname.t @@ -22,6 +22,7 @@ use File::Temp; foreach my $dir ( glob( "hooks/*" ) ) { next if ( $dir =~ /CVS/i ); + next if ( $dir =~ /common/i ); next if ( ! -d $dir ); if ( $dir =~ /hooks\/(.*)/ ) diff --git a/t/hook-inittab.t b/t/hook-inittab.t index 9ac9df4..bb07285 100755 --- a/t/hook-inittab.t +++ b/t/hook-inittab.t @@ -27,6 +27,7 @@ ok( -e "/etc/inittab", "/etc/inittab exists." ); foreach my $dir ( glob( "hooks/*" ) ) { next if ( $dir =~ /CVS/i ); + next if ( $dir =~ /common/i ); next if ( ! -d $dir ); if ( $dir =~ /hooks\/(.*)/ ) diff --git a/t/hooks.t b/t/hooks.t index adaba11..41d3ec9 100755 --- a/t/hooks.t +++ b/t/hooks.t @@ -18,6 +18,7 @@ use Test::More qw( no_plan ); foreach my $dir ( glob( "hooks/*" ) ) { next if ( $dir =~ /CVS/i ); + next if ( $dir =~ /common/i ); next if ( ! -d $dir ); if ( $dir =~ /hooks\/(.*)/ ) diff --git a/t/plugin-checks.t b/t/plugin-checks.t index a9c4781..f82d13a 100755 --- a/t/plugin-checks.t +++ b/t/plugin-checks.t @@ -20,6 +20,7 @@ use Test::More qw( no_plan ); foreach my $dir ( glob( "hooks/*" ) ) { next if ( $dir =~ /CVS/i ); + next if ( $dir =~ /common/i ); next if ( ! -d $dir ); if ( $dir =~ /hooks\/(.*)/ )