diff --git a/hooks/centos-4/10-disable-tls b/hooks/centos-4/10-disable-tls new file mode 100755 index 0000000..a80edd6 --- /dev/null +++ b/hooks/centos-4/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/centos-4/20-setup-yum b/hooks/centos-4/20-setup-yum new file mode 100755 index 0000000..b3a41ea --- /dev/null +++ b/hooks/centos-4/20-setup-yum @@ -0,0 +1,56 @@ +#!/bin/sh +# +# This script sets up the Yum for CentOS4. +# +# 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 + + +# +# DNS is probably required to run "yum update". +# +cp /etc/resolv.conf ${prefix}/etc + + +# +# Transform yum so that it works. +# +#perl -pi.bak -e 's/enabled=0/enabled=1/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/gpgcheck=1/gpgcheck=0/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/^\#baseurl/baseurl/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/^mirrorlist/#mirrorlist/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/\$releasever/4/g' ${prefix}/etc/yum.repos.d/*.repo + +# +# Update yum +# +chroot ${prefix} /usr/bin/yum update + +# +# Log our finish +# +logMessage Script $0 finished + + + + diff --git a/hooks/centos-4/30-disable-gettys b/hooks/centos-4/30-disable-gettys new file mode 100755 index 0000000..e822819 --- /dev/null +++ b/hooks/centos-4/30-disable-gettys @@ -0,0 +1,40 @@ +#!/bin/sh +# +# This script comments out all virtual terminals which aren't on the +# first console - that must remain so that 'xm console ...' works +# correctly. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Do the transformation. +# +sed -i -e 's/^\([2-6].*:respawn*\)/#\1/' -e 's/^T/#\t/' ${prefix}/etc/inittab + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-4/35-setup-users b/hooks/centos-4/35-setup-users new file mode 100755 index 0000000..1f80c58 --- /dev/null +++ b/hooks/centos-4/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/centos-4/40-setup-networking b/hooks/centos-4/40-setup-networking new file mode 100755 index 0000000..02f59c4 --- /dev/null +++ b/hooks/centos-4/40-setup-networking @@ -0,0 +1,98 @@ +#!/bin/sh +# +# This script sets up the networking files for the new image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Make sure we have an /etc/sysconfig/network-scripts directory. +# +mkdir -p ${prefix}/etc/sysconfig/network-scripts/ + + +# +# Test for static vs. DHCP +# +if [ -z "${dhcp}" ]; then + + # + # Setup the initial interface + # + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0 +DEVICE=eth0 +ONBOOT=yes +BOOTPROTO=static +IPADDR=${ip1} +NETMASK=${netmask} +GATEWAY=${gateway} +E_O_STATIC + + # + # Now setup any other ones. + # + interface=1 + count=2 + + while [ "${count}" -le "${ip_count}" ]; do + + value=\$ip${count} + value=`eval echo $value` + + logMessage Adding etho:${interface} + + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0:${interface} +DEVICE=eth0:${interface} +ONBOOT=yes +BOOTPROTO=static +IPADDR=${value} +NETMASK=${netmask} +E_O_STATIC + count=`expr $count + 1` + interface=`expr $interface + 1` + done + +else + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0 +DEVICE=eth0 +BOOTPROTO=dhcp +ONBOOT=yes +E_O_DHCP +fi + + +# +# Don't forget to setup the default route. +# +cat <${prefix}/etc/sysconfig/network +NETWORKING=yes +GATEWAY=${gateway} +HOSTNAME=${hostname} +EOF + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-4/50-setup-hostname b/hooks/centos-4/50-setup-hostname new file mode 100755 index 0000000..e63509b --- /dev/null +++ b/hooks/centos-4/50-setup-hostname @@ -0,0 +1,118 @@ +#!/bin/sh +# +# This script places the new systems hostname into a couple of files within +# the new image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Setup the mailname + hostname files. +# +echo ${hostname} > ${prefix}/etc/hostname +echo ${hostname} > ${prefix}/etc/mailname + + +# +# Fixup the /etc/hosts file upon the new image for +# machines with static IPs +# +if [ -z "${dhcp}" ]; then + + # Non-IPv6 stuff. + grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts + + # New entry. + echo "${ip1} ${hostname}" >> ${prefix}/etc/hosts + echo " " >> ${prefix}/etc/hosts + + # IPv6 stuff. + grep '\(::\|IPv6\)' /etc/hosts >> ${prefix}/etc/hosts + +else + + # + # Stub /etc/hosts for DHCP clients. + # + cat >> ${prefix}/etc/hosts < /dev/null ) ; then + + logMessage Host already has IP address for the host ${hostname}. + + else + + # + # Short host name. + # + name=`echo ${hostname} | awk -F. '{print $1}'` + + logMessage Adding ${hostname} and ${name} to /etc/hosts on the host + + echo "${ip1} ${name} ${hostname}" >> /etc/hosts + + + # + # If we've updated the /etc/hosts file on the host machine + # and there is an installation of dnsmasq installed then + # reload it. + # + # This will let the local LAN clients lookup the new address. + # + if [ -x /usr/sbin/dnsmasq ] ; then + if [ -e /var/run/dnsmasq.pid ]; then + + logMessage Allowing DNSMasq to restart. + kill -HUP `cat /var/run/dnsmasq.pid` + fi + fi + fi +fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-4/55-create-dev b/hooks/centos-4/55-create-dev new file mode 100755 index 0000000..89577ce --- /dev/null +++ b/hooks/centos-4/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/centos-4/60-copy-host-files b/hooks/centos-4/60-copy-host-files new file mode 100755 index 0000000..080e90b --- /dev/null +++ b/hooks/centos-4/60-copy-host-files @@ -0,0 +1,58 @@ +#!/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. +# +# NONE DONE + +# +# If the host has sudo then copy the configuration file, and install +# the package +# +if [ -e /etc/sudoers ]; then + + logMessage Installing SUDO too. + + # + # Copy file and fixup permissions. + # + cp /etc/sudoers ${prefix}/etc + chown root:root ${prefix}/etc/sudoers + chmod 440 ${prefix}/etc/sudoers + + # + # Install sudo + # + installCentOS4Package ${prefix} sudo + +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 100755 index 0000000..a34fe94 --- /dev/null +++ b/hooks/centos-4/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/centos-4/70-install-ssh b/hooks/centos-4/70-install-ssh new file mode 100755 index 0000000..a51e528 --- /dev/null +++ b/hooks/centos-4/70-install-ssh @@ -0,0 +1,39 @@ +#!/bin/sh +# +# This script installs OpenSSH upon the new system. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + +# +# Install the OpenSSH server. +# +chroot ${prefix} /bin/mount /proc +chroot ${prefix} /usr/bin/yum -y install openssh-server +chroot ${prefix} /bin/umount /proc + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-4/80-install-modules b/hooks/centos-4/80-install-modules new file mode 100755 index 0000000..11f83d5 --- /dev/null +++ b/hooks/centos-4/80-install-modules @@ -0,0 +1,41 @@ +#!/bin/sh +# +# Install modules from the host system into 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 + + +# +# Copy the modules from the host to the new system - we should only +# really copy the *correct* modules, but we don't know what they are. +# +mkdir -p ${prefix}/lib/modules +cp -au /lib/modules/*/ ${prefix}/lib/modules + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-4/90-make-fstab b/hooks/centos-4/90-make-fstab new file mode 100755 index 0000000..841fd33 --- /dev/null +++ b/hooks/centos-4/90-make-fstab @@ -0,0 +1,98 @@ +#!/bin/sh +# +# This script is responsible for setting up /etc/fstab upon the +# new instance. +# +# This should be a simple job, but it is complicated by some of the +# differences between filesystems - some root filesystems will require +# the installation of new packages, and we have to handle that here. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +logMessage Filesystem options are ${options} + + +# +# Make sure we use ide style device names if required +# +device=sda +if [ "${ide}" ]; then + device=hda +fi + +# +# Now we have the options we can create the fstab. +# +has_xfs=0 +has_reiserfs=0 +cat < ${prefix}/etc/fstab +# /etc/fstab: static file system information. +# +# +proc /proc proc defaults 0 0 +E_O_FSTAB +for part in `seq 1 ${NUMPARTITIONS}`; do + eval "PARTITION=\"\${PARTITION${part}}\"" + OLDIFS="${IFS}" + IFS=: + x=0 + for partdata in ${PARTITION}; do + eval "partdata${x}=\"${partdata}\"" + x=$(( x+1 )) + done + IFS="${OLDIFS}" + + case "${partdata2}" in + xfs) + has_xfs=1 + ;; + reiserfs) + has_reiserfs=1 + ;; + esac + + if [ "${partdata2}" = "swap" ]; then + echo "/dev/${device}${part} none swap sw 0 0" >> ${prefix}/etc/fstab + else + echo "/dev/${device}${part} ${partdata3} ${partdata2} ${partdata4} 0 1" >> ${prefix}/etc/fstab + fi +done + + +# +# Finally we can install any required packages for the given root +# filesystem +# +#if [ $has_xfs -eq 1 ]; then +# installDebianPackage ${prefix} xfsprogs +#fi +#if [ $has_reiserfs -eq 1 ]; then +# installDebianPackage ${prefix} reiserfsprogs +#fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-4/99-clean-image b/hooks/centos-4/99-clean-image new file mode 100755 index 0000000..c068a94 --- /dev/null +++ b/hooks/centos-4/99-clean-image @@ -0,0 +1,44 @@ +#!/bin/sh +# +# This script cleans the yum database on the new system. +# +# 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 up RPM files. +# +logMessage Cleaning .rpm* files. +find ${prefix}/ -name '*.rpmorig' -exec rm -f \{\} \; +find ${prefix}/ -name '*.rpmnew' -exec rm -f \{\} \; + +# +# Clean yum +# +logMessage Cleaning Yum Repository +chroot ${prefix} /usr/bin/yum clean all + +# +# 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 100755 index 0000000..a80edd6 --- /dev/null +++ b/hooks/centos-5/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/centos-5/20-setup-yum b/hooks/centos-5/20-setup-yum new file mode 100755 index 0000000..b3a41ea --- /dev/null +++ b/hooks/centos-5/20-setup-yum @@ -0,0 +1,56 @@ +#!/bin/sh +# +# This script sets up the Yum for CentOS4. +# +# 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 + + +# +# DNS is probably required to run "yum update". +# +cp /etc/resolv.conf ${prefix}/etc + + +# +# Transform yum so that it works. +# +#perl -pi.bak -e 's/enabled=0/enabled=1/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/gpgcheck=1/gpgcheck=0/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/^\#baseurl/baseurl/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/^mirrorlist/#mirrorlist/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/\$releasever/4/g' ${prefix}/etc/yum.repos.d/*.repo + +# +# Update yum +# +chroot ${prefix} /usr/bin/yum update + +# +# Log our finish +# +logMessage Script $0 finished + + + + diff --git a/hooks/centos-5/30-disable-gettys b/hooks/centos-5/30-disable-gettys new file mode 100755 index 0000000..e822819 --- /dev/null +++ b/hooks/centos-5/30-disable-gettys @@ -0,0 +1,40 @@ +#!/bin/sh +# +# This script comments out all virtual terminals which aren't on the +# first console - that must remain so that 'xm console ...' works +# correctly. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Do the transformation. +# +sed -i -e 's/^\([2-6].*:respawn*\)/#\1/' -e 's/^T/#\t/' ${prefix}/etc/inittab + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-5/35-setup-users b/hooks/centos-5/35-setup-users new file mode 100755 index 0000000..1f80c58 --- /dev/null +++ b/hooks/centos-5/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/centos-5/40-setup-networking b/hooks/centos-5/40-setup-networking new file mode 100755 index 0000000..02f59c4 --- /dev/null +++ b/hooks/centos-5/40-setup-networking @@ -0,0 +1,98 @@ +#!/bin/sh +# +# This script sets up the networking files for the new image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Make sure we have an /etc/sysconfig/network-scripts directory. +# +mkdir -p ${prefix}/etc/sysconfig/network-scripts/ + + +# +# Test for static vs. DHCP +# +if [ -z "${dhcp}" ]; then + + # + # Setup the initial interface + # + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0 +DEVICE=eth0 +ONBOOT=yes +BOOTPROTO=static +IPADDR=${ip1} +NETMASK=${netmask} +GATEWAY=${gateway} +E_O_STATIC + + # + # Now setup any other ones. + # + interface=1 + count=2 + + while [ "${count}" -le "${ip_count}" ]; do + + value=\$ip${count} + value=`eval echo $value` + + logMessage Adding etho:${interface} + + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0:${interface} +DEVICE=eth0:${interface} +ONBOOT=yes +BOOTPROTO=static +IPADDR=${value} +NETMASK=${netmask} +E_O_STATIC + count=`expr $count + 1` + interface=`expr $interface + 1` + done + +else + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0 +DEVICE=eth0 +BOOTPROTO=dhcp +ONBOOT=yes +E_O_DHCP +fi + + +# +# Don't forget to setup the default route. +# +cat <${prefix}/etc/sysconfig/network +NETWORKING=yes +GATEWAY=${gateway} +HOSTNAME=${hostname} +EOF + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-5/50-setup-hostname b/hooks/centos-5/50-setup-hostname new file mode 100755 index 0000000..e63509b --- /dev/null +++ b/hooks/centos-5/50-setup-hostname @@ -0,0 +1,118 @@ +#!/bin/sh +# +# This script places the new systems hostname into a couple of files within +# the new image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Setup the mailname + hostname files. +# +echo ${hostname} > ${prefix}/etc/hostname +echo ${hostname} > ${prefix}/etc/mailname + + +# +# Fixup the /etc/hosts file upon the new image for +# machines with static IPs +# +if [ -z "${dhcp}" ]; then + + # Non-IPv6 stuff. + grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts + + # New entry. + echo "${ip1} ${hostname}" >> ${prefix}/etc/hosts + echo " " >> ${prefix}/etc/hosts + + # IPv6 stuff. + grep '\(::\|IPv6\)' /etc/hosts >> ${prefix}/etc/hosts + +else + + # + # Stub /etc/hosts for DHCP clients. + # + cat >> ${prefix}/etc/hosts < /dev/null ) ; then + + logMessage Host already has IP address for the host ${hostname}. + + else + + # + # Short host name. + # + name=`echo ${hostname} | awk -F. '{print $1}'` + + logMessage Adding ${hostname} and ${name} to /etc/hosts on the host + + echo "${ip1} ${name} ${hostname}" >> /etc/hosts + + + # + # If we've updated the /etc/hosts file on the host machine + # and there is an installation of dnsmasq installed then + # reload it. + # + # This will let the local LAN clients lookup the new address. + # + if [ -x /usr/sbin/dnsmasq ] ; then + if [ -e /var/run/dnsmasq.pid ]; then + + logMessage Allowing DNSMasq to restart. + kill -HUP `cat /var/run/dnsmasq.pid` + fi + fi + fi +fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-5/55-create-dev b/hooks/centos-5/55-create-dev new file mode 100755 index 0000000..89577ce --- /dev/null +++ b/hooks/centos-5/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/centos-5/60-copy-host-files b/hooks/centos-5/60-copy-host-files new file mode 100755 index 0000000..080e90b --- /dev/null +++ b/hooks/centos-5/60-copy-host-files @@ -0,0 +1,58 @@ +#!/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. +# +# NONE DONE + +# +# If the host has sudo then copy the configuration file, and install +# the package +# +if [ -e /etc/sudoers ]; then + + logMessage Installing SUDO too. + + # + # Copy file and fixup permissions. + # + cp /etc/sudoers ${prefix}/etc + chown root:root ${prefix}/etc/sudoers + chmod 440 ${prefix}/etc/sudoers + + # + # Install sudo + # + installCentOS4Package ${prefix} sudo + +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 100755 index 0000000..a34fe94 --- /dev/null +++ b/hooks/centos-5/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/centos-5/70-install-ssh b/hooks/centos-5/70-install-ssh new file mode 100755 index 0000000..a51e528 --- /dev/null +++ b/hooks/centos-5/70-install-ssh @@ -0,0 +1,39 @@ +#!/bin/sh +# +# This script installs OpenSSH upon the new system. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + +# +# Install the OpenSSH server. +# +chroot ${prefix} /bin/mount /proc +chroot ${prefix} /usr/bin/yum -y install openssh-server +chroot ${prefix} /bin/umount /proc + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-5/80-install-modules b/hooks/centos-5/80-install-modules new file mode 100755 index 0000000..11f83d5 --- /dev/null +++ b/hooks/centos-5/80-install-modules @@ -0,0 +1,41 @@ +#!/bin/sh +# +# Install modules from the host system into 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 + + +# +# Copy the modules from the host to the new system - we should only +# really copy the *correct* modules, but we don't know what they are. +# +mkdir -p ${prefix}/lib/modules +cp -au /lib/modules/*/ ${prefix}/lib/modules + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-5/90-make-fstab b/hooks/centos-5/90-make-fstab new file mode 100755 index 0000000..841fd33 --- /dev/null +++ b/hooks/centos-5/90-make-fstab @@ -0,0 +1,98 @@ +#!/bin/sh +# +# This script is responsible for setting up /etc/fstab upon the +# new instance. +# +# This should be a simple job, but it is complicated by some of the +# differences between filesystems - some root filesystems will require +# the installation of new packages, and we have to handle that here. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +logMessage Filesystem options are ${options} + + +# +# Make sure we use ide style device names if required +# +device=sda +if [ "${ide}" ]; then + device=hda +fi + +# +# Now we have the options we can create the fstab. +# +has_xfs=0 +has_reiserfs=0 +cat < ${prefix}/etc/fstab +# /etc/fstab: static file system information. +# +# +proc /proc proc defaults 0 0 +E_O_FSTAB +for part in `seq 1 ${NUMPARTITIONS}`; do + eval "PARTITION=\"\${PARTITION${part}}\"" + OLDIFS="${IFS}" + IFS=: + x=0 + for partdata in ${PARTITION}; do + eval "partdata${x}=\"${partdata}\"" + x=$(( x+1 )) + done + IFS="${OLDIFS}" + + case "${partdata2}" in + xfs) + has_xfs=1 + ;; + reiserfs) + has_reiserfs=1 + ;; + esac + + if [ "${partdata2}" = "swap" ]; then + echo "/dev/${device}${part} none swap sw 0 0" >> ${prefix}/etc/fstab + else + echo "/dev/${device}${part} ${partdata3} ${partdata2} ${partdata4} 0 1" >> ${prefix}/etc/fstab + fi +done + + +# +# Finally we can install any required packages for the given root +# filesystem +# +#if [ $has_xfs -eq 1 ]; then +# installDebianPackage ${prefix} xfsprogs +#fi +#if [ $has_reiserfs -eq 1 ]; then +# installDebianPackage ${prefix} reiserfsprogs +#fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/centos-5/99-clean-image b/hooks/centos-5/99-clean-image new file mode 100755 index 0000000..c068a94 --- /dev/null +++ b/hooks/centos-5/99-clean-image @@ -0,0 +1,44 @@ +#!/bin/sh +# +# This script cleans the yum database on the new system. +# +# 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 up RPM files. +# +logMessage Cleaning .rpm* files. +find ${prefix}/ -name '*.rpmorig' -exec rm -f \{\} \; +find ${prefix}/ -name '*.rpmnew' -exec rm -f \{\} \; + +# +# Clean yum +# +logMessage Cleaning Yum Repository +chroot ${prefix} /usr/bin/yum clean all + +# +# 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 100755 index 0000000..a80edd6 --- /dev/null +++ b/hooks/fedora-core-6/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/fedora-core-6/20-setup-yum b/hooks/fedora-core-6/20-setup-yum new file mode 100755 index 0000000..b3a41ea --- /dev/null +++ b/hooks/fedora-core-6/20-setup-yum @@ -0,0 +1,56 @@ +#!/bin/sh +# +# This script sets up the Yum for CentOS4. +# +# 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 + + +# +# DNS is probably required to run "yum update". +# +cp /etc/resolv.conf ${prefix}/etc + + +# +# Transform yum so that it works. +# +#perl -pi.bak -e 's/enabled=0/enabled=1/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/gpgcheck=1/gpgcheck=0/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/^\#baseurl/baseurl/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/^mirrorlist/#mirrorlist/g' ${prefix}/etc/yum.repos.d/*.repo +#perl -pi.bak -e 's/\$releasever/4/g' ${prefix}/etc/yum.repos.d/*.repo + +# +# Update yum +# +chroot ${prefix} /usr/bin/yum update + +# +# Log our finish +# +logMessage Script $0 finished + + + + diff --git a/hooks/fedora-core-6/30-disable-gettys b/hooks/fedora-core-6/30-disable-gettys new file mode 100755 index 0000000..e822819 --- /dev/null +++ b/hooks/fedora-core-6/30-disable-gettys @@ -0,0 +1,40 @@ +#!/bin/sh +# +# This script comments out all virtual terminals which aren't on the +# first console - that must remain so that 'xm console ...' works +# correctly. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Do the transformation. +# +sed -i -e 's/^\([2-6].*:respawn*\)/#\1/' -e 's/^T/#\t/' ${prefix}/etc/inittab + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/fedora-core-6/35-setup-users b/hooks/fedora-core-6/35-setup-users new file mode 100755 index 0000000..1f80c58 --- /dev/null +++ b/hooks/fedora-core-6/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/fedora-core-6/40-setup-networking b/hooks/fedora-core-6/40-setup-networking new file mode 100755 index 0000000..02f59c4 --- /dev/null +++ b/hooks/fedora-core-6/40-setup-networking @@ -0,0 +1,98 @@ +#!/bin/sh +# +# This script sets up the networking files for the new image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Make sure we have an /etc/sysconfig/network-scripts directory. +# +mkdir -p ${prefix}/etc/sysconfig/network-scripts/ + + +# +# Test for static vs. DHCP +# +if [ -z "${dhcp}" ]; then + + # + # Setup the initial interface + # + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0 +DEVICE=eth0 +ONBOOT=yes +BOOTPROTO=static +IPADDR=${ip1} +NETMASK=${netmask} +GATEWAY=${gateway} +E_O_STATIC + + # + # Now setup any other ones. + # + interface=1 + count=2 + + while [ "${count}" -le "${ip_count}" ]; do + + value=\$ip${count} + value=`eval echo $value` + + logMessage Adding etho:${interface} + + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0:${interface} +DEVICE=eth0:${interface} +ONBOOT=yes +BOOTPROTO=static +IPADDR=${value} +NETMASK=${netmask} +E_O_STATIC + count=`expr $count + 1` + interface=`expr $interface + 1` + done + +else + cat <${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0 +DEVICE=eth0 +BOOTPROTO=dhcp +ONBOOT=yes +E_O_DHCP +fi + + +# +# Don't forget to setup the default route. +# +cat <${prefix}/etc/sysconfig/network +NETWORKING=yes +GATEWAY=${gateway} +HOSTNAME=${hostname} +EOF + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/fedora-core-6/50-setup-hostname b/hooks/fedora-core-6/50-setup-hostname new file mode 100755 index 0000000..e63509b --- /dev/null +++ b/hooks/fedora-core-6/50-setup-hostname @@ -0,0 +1,118 @@ +#!/bin/sh +# +# This script places the new systems hostname into a couple of files within +# the new image. +# +# Steve +# -- +# http://www.steve.org.uk/ + + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Setup the mailname + hostname files. +# +echo ${hostname} > ${prefix}/etc/hostname +echo ${hostname} > ${prefix}/etc/mailname + + +# +# Fixup the /etc/hosts file upon the new image for +# machines with static IPs +# +if [ -z "${dhcp}" ]; then + + # Non-IPv6 stuff. + grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts + + # New entry. + echo "${ip1} ${hostname}" >> ${prefix}/etc/hosts + echo " " >> ${prefix}/etc/hosts + + # IPv6 stuff. + grep '\(::\|IPv6\)' /etc/hosts >> ${prefix}/etc/hosts + +else + + # + # Stub /etc/hosts for DHCP clients. + # + cat >> ${prefix}/etc/hosts < /dev/null ) ; then + + logMessage Host already has IP address for the host ${hostname}. + + else + + # + # Short host name. + # + name=`echo ${hostname} | awk -F. '{print $1}'` + + logMessage Adding ${hostname} and ${name} to /etc/hosts on the host + + echo "${ip1} ${name} ${hostname}" >> /etc/hosts + + + # + # If we've updated the /etc/hosts file on the host machine + # and there is an installation of dnsmasq installed then + # reload it. + # + # This will let the local LAN clients lookup the new address. + # + if [ -x /usr/sbin/dnsmasq ] ; then + if [ -e /var/run/dnsmasq.pid ]; then + + logMessage Allowing DNSMasq to restart. + kill -HUP `cat /var/run/dnsmasq.pid` + fi + fi + fi +fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/fedora-core-6/55-create-dev b/hooks/fedora-core-6/55-create-dev new file mode 100755 index 0000000..89577ce --- /dev/null +++ b/hooks/fedora-core-6/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/fedora-core-6/60-copy-host-files b/hooks/fedora-core-6/60-copy-host-files new file mode 100755 index 0000000..080e90b --- /dev/null +++ b/hooks/fedora-core-6/60-copy-host-files @@ -0,0 +1,58 @@ +#!/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. +# +# NONE DONE + +# +# If the host has sudo then copy the configuration file, and install +# the package +# +if [ -e /etc/sudoers ]; then + + logMessage Installing SUDO too. + + # + # Copy file and fixup permissions. + # + cp /etc/sudoers ${prefix}/etc + chown root:root ${prefix}/etc/sudoers + chmod 440 ${prefix}/etc/sudoers + + # + # Install sudo + # + installCentOS4Package ${prefix} sudo + +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 100755 index 0000000..a34fe94 --- /dev/null +++ b/hooks/fedora-core-6/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/fedora-core-6/70-install-ssh b/hooks/fedora-core-6/70-install-ssh new file mode 100755 index 0000000..a51e528 --- /dev/null +++ b/hooks/fedora-core-6/70-install-ssh @@ -0,0 +1,39 @@ +#!/bin/sh +# +# This script installs OpenSSH upon the new system. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + +# +# Install the OpenSSH server. +# +chroot ${prefix} /bin/mount /proc +chroot ${prefix} /usr/bin/yum -y install openssh-server +chroot ${prefix} /bin/umount /proc + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/fedora-core-6/80-install-modules b/hooks/fedora-core-6/80-install-modules new file mode 100755 index 0000000..11f83d5 --- /dev/null +++ b/hooks/fedora-core-6/80-install-modules @@ -0,0 +1,41 @@ +#!/bin/sh +# +# Install modules from the host system into 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 + + +# +# Copy the modules from the host to the new system - we should only +# really copy the *correct* modules, but we don't know what they are. +# +mkdir -p ${prefix}/lib/modules +cp -au /lib/modules/*/ ${prefix}/lib/modules + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/fedora-core-6/90-make-fstab b/hooks/fedora-core-6/90-make-fstab new file mode 100755 index 0000000..841fd33 --- /dev/null +++ b/hooks/fedora-core-6/90-make-fstab @@ -0,0 +1,98 @@ +#!/bin/sh +# +# This script is responsible for setting up /etc/fstab upon the +# new instance. +# +# This should be a simple job, but it is complicated by some of the +# differences between filesystems - some root filesystems will require +# the installation of new packages, and we have to handle that here. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +logMessage Filesystem options are ${options} + + +# +# Make sure we use ide style device names if required +# +device=sda +if [ "${ide}" ]; then + device=hda +fi + +# +# Now we have the options we can create the fstab. +# +has_xfs=0 +has_reiserfs=0 +cat < ${prefix}/etc/fstab +# /etc/fstab: static file system information. +# +# +proc /proc proc defaults 0 0 +E_O_FSTAB +for part in `seq 1 ${NUMPARTITIONS}`; do + eval "PARTITION=\"\${PARTITION${part}}\"" + OLDIFS="${IFS}" + IFS=: + x=0 + for partdata in ${PARTITION}; do + eval "partdata${x}=\"${partdata}\"" + x=$(( x+1 )) + done + IFS="${OLDIFS}" + + case "${partdata2}" in + xfs) + has_xfs=1 + ;; + reiserfs) + has_reiserfs=1 + ;; + esac + + if [ "${partdata2}" = "swap" ]; then + echo "/dev/${device}${part} none swap sw 0 0" >> ${prefix}/etc/fstab + else + echo "/dev/${device}${part} ${partdata3} ${partdata2} ${partdata4} 0 1" >> ${prefix}/etc/fstab + fi +done + + +# +# Finally we can install any required packages for the given root +# filesystem +# +#if [ $has_xfs -eq 1 ]; then +# installDebianPackage ${prefix} xfsprogs +#fi +#if [ $has_reiserfs -eq 1 ]; then +# installDebianPackage ${prefix} reiserfsprogs +#fi + + +# +# Log our finish +# +logMessage Script $0 finished diff --git a/hooks/fedora-core-6/99-clean-image b/hooks/fedora-core-6/99-clean-image new file mode 100755 index 0000000..c068a94 --- /dev/null +++ b/hooks/fedora-core-6/99-clean-image @@ -0,0 +1,44 @@ +#!/bin/sh +# +# This script cleans the yum database on the new system. +# +# 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 up RPM files. +# +logMessage Cleaning .rpm* files. +find ${prefix}/ -name '*.rpmorig' -exec rm -f \{\} \; +find ${prefix}/ -name '*.rpmnew' -exec rm -f \{\} \; + +# +# Clean yum +# +logMessage Cleaning Yum Repository +chroot ${prefix} /usr/bin/yum clean all + +# +# Log our finish +# +logMessage Script $0 finished