2007-07-16 00:33:58 by steve
Added.
This commit is contained in:
parent
6f6aef2155
commit
c6ec56f7fa
49
hooks/centos-4/10-disable-tls
Executable file
49
hooks/centos-4/10-disable-tls
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script disables TLS on the new image.
|
||||
#
|
||||
# Steve
|
||||
# --
|
||||
# http://www.steve.org.uk/
|
||||
|
||||
|
||||
|
||||
prefix=$1
|
||||
|
||||
|
||||
#
|
||||
# Source our common functions
|
||||
#
|
||||
if [ -e /usr/lib/xen-tools/common.sh ]; then
|
||||
. /usr/lib/xen-tools/common.sh
|
||||
else
|
||||
. ./hooks/common.sh
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our start
|
||||
#
|
||||
logMessage Script $0 starting
|
||||
|
||||
|
||||
#
|
||||
# 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
|
||||
56
hooks/centos-4/20-setup-yum
Executable file
56
hooks/centos-4/20-setup-yum
Executable file
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
40
hooks/centos-4/30-disable-gettys
Executable file
40
hooks/centos-4/30-disable-gettys
Executable file
@ -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
|
||||
181
hooks/centos-4/35-setup-users
Executable file
181
hooks/centos-4/35-setup-users
Executable file
@ -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 ( <EXISTING> )
|
||||
{
|
||||
#
|
||||
# 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 ( <PASSWD> )
|
||||
{
|
||||
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 ( <SHADOW> )
|
||||
{
|
||||
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" );
|
||||
}
|
||||
}
|
||||
98
hooks/centos-4/40-setup-networking
Executable file
98
hooks/centos-4/40-setup-networking
Executable file
@ -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 <<E_O_STATIC >${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 <<E_O_STATIC >${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 <<E_O_DHCP >${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 <<EOF >${prefix}/etc/sysconfig/network
|
||||
NETWORKING=yes
|
||||
GATEWAY=${gateway}
|
||||
HOSTNAME=${hostname}
|
||||
EOF
|
||||
|
||||
|
||||
#
|
||||
# Log our finish
|
||||
#
|
||||
logMessage Script $0 finished
|
||||
118
hooks/centos-4/50-setup-hostname
Executable file
118
hooks/centos-4/50-setup-hostname
Executable file
@ -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 <<EOF
|
||||
127.0.0.1 localhost
|
||||
|
||||
# The following lines are desirable for IPv6 capable hosts
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
|
||||
EOF
|
||||
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Allow the host system to know the IP address of our new guest.
|
||||
#
|
||||
if [ -z "${dhcp}" ]; then
|
||||
|
||||
if ( grep ${hostname} /etc/hosts > /dev/null ) ; then
|
||||
|
||||
logMessage Host already has IP address for the host ${hostname}.
|
||||
|
||||
else
|
||||
|
||||
#
|
||||
# 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
|
||||
53
hooks/centos-4/55-create-dev
Executable file
53
hooks/centos-4/55-create-dev
Executable file
@ -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
|
||||
58
hooks/centos-4/60-copy-host-files
Executable file
58
hooks/centos-4/60-copy-host-files
Executable file
@ -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
|
||||
49
hooks/centos-4/65-copy-user-files
Executable file
49
hooks/centos-4/65-copy-user-files
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copy files from a 'skel' directory, if present, into the
|
||||
# new images
|
||||
#
|
||||
|
||||
|
||||
prefix=$1
|
||||
|
||||
|
||||
#
|
||||
# Source our common functions
|
||||
#
|
||||
if [ -e /usr/lib/xen-tools/common.sh ]; then
|
||||
. /usr/lib/xen-tools/common.sh
|
||||
else
|
||||
. ./hooks/common.sh
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our start
|
||||
#
|
||||
logMessage Script $0 starting
|
||||
|
||||
|
||||
#
|
||||
# Copy everything from the skel directory into the new instance
|
||||
# if that directory exists.
|
||||
#
|
||||
if [ -d /etc/xen-tools/skel ]; then
|
||||
|
||||
logMessage Copying files from /etc/xen-tools/skel
|
||||
|
||||
(cd /etc/xen-tools/skel; tar -cf - . ) | (cd ${prefix}/; tar -xpf -)
|
||||
|
||||
logMessage Finished
|
||||
|
||||
else
|
||||
|
||||
logMessage skel directory, /etc/xen-tools/skell, not present ignoring.
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our finish
|
||||
#
|
||||
logMessage Script $0 finished
|
||||
39
hooks/centos-4/70-install-ssh
Executable file
39
hooks/centos-4/70-install-ssh
Executable file
@ -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
|
||||
41
hooks/centos-4/80-install-modules
Executable file
41
hooks/centos-4/80-install-modules
Executable file
@ -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
|
||||
98
hooks/centos-4/90-make-fstab
Executable file
98
hooks/centos-4/90-make-fstab
Executable file
@ -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 <<E_O_FSTAB > ${prefix}/etc/fstab
|
||||
# /etc/fstab: static file system information.
|
||||
#
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
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
|
||||
44
hooks/centos-4/99-clean-image
Executable file
44
hooks/centos-4/99-clean-image
Executable file
@ -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
|
||||
49
hooks/centos-5/10-disable-tls
Executable file
49
hooks/centos-5/10-disable-tls
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script disables TLS on the new image.
|
||||
#
|
||||
# Steve
|
||||
# --
|
||||
# http://www.steve.org.uk/
|
||||
|
||||
|
||||
|
||||
prefix=$1
|
||||
|
||||
|
||||
#
|
||||
# Source our common functions
|
||||
#
|
||||
if [ -e /usr/lib/xen-tools/common.sh ]; then
|
||||
. /usr/lib/xen-tools/common.sh
|
||||
else
|
||||
. ./hooks/common.sh
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our start
|
||||
#
|
||||
logMessage Script $0 starting
|
||||
|
||||
|
||||
#
|
||||
# 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
|
||||
56
hooks/centos-5/20-setup-yum
Executable file
56
hooks/centos-5/20-setup-yum
Executable file
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
40
hooks/centos-5/30-disable-gettys
Executable file
40
hooks/centos-5/30-disable-gettys
Executable file
@ -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
|
||||
181
hooks/centos-5/35-setup-users
Executable file
181
hooks/centos-5/35-setup-users
Executable file
@ -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 ( <EXISTING> )
|
||||
{
|
||||
#
|
||||
# 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 ( <PASSWD> )
|
||||
{
|
||||
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 ( <SHADOW> )
|
||||
{
|
||||
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" );
|
||||
}
|
||||
}
|
||||
98
hooks/centos-5/40-setup-networking
Executable file
98
hooks/centos-5/40-setup-networking
Executable file
@ -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 <<E_O_STATIC >${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 <<E_O_STATIC >${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 <<E_O_DHCP >${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 <<EOF >${prefix}/etc/sysconfig/network
|
||||
NETWORKING=yes
|
||||
GATEWAY=${gateway}
|
||||
HOSTNAME=${hostname}
|
||||
EOF
|
||||
|
||||
|
||||
#
|
||||
# Log our finish
|
||||
#
|
||||
logMessage Script $0 finished
|
||||
118
hooks/centos-5/50-setup-hostname
Executable file
118
hooks/centos-5/50-setup-hostname
Executable file
@ -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 <<EOF
|
||||
127.0.0.1 localhost
|
||||
|
||||
# The following lines are desirable for IPv6 capable hosts
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
|
||||
EOF
|
||||
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Allow the host system to know the IP address of our new guest.
|
||||
#
|
||||
if [ -z "${dhcp}" ]; then
|
||||
|
||||
if ( grep ${hostname} /etc/hosts > /dev/null ) ; then
|
||||
|
||||
logMessage Host already has IP address for the host ${hostname}.
|
||||
|
||||
else
|
||||
|
||||
#
|
||||
# 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
|
||||
53
hooks/centos-5/55-create-dev
Executable file
53
hooks/centos-5/55-create-dev
Executable file
@ -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
|
||||
58
hooks/centos-5/60-copy-host-files
Executable file
58
hooks/centos-5/60-copy-host-files
Executable file
@ -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
|
||||
49
hooks/centos-5/65-copy-user-files
Executable file
49
hooks/centos-5/65-copy-user-files
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copy files from a 'skel' directory, if present, into the
|
||||
# new images
|
||||
#
|
||||
|
||||
|
||||
prefix=$1
|
||||
|
||||
|
||||
#
|
||||
# Source our common functions
|
||||
#
|
||||
if [ -e /usr/lib/xen-tools/common.sh ]; then
|
||||
. /usr/lib/xen-tools/common.sh
|
||||
else
|
||||
. ./hooks/common.sh
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our start
|
||||
#
|
||||
logMessage Script $0 starting
|
||||
|
||||
|
||||
#
|
||||
# Copy everything from the skel directory into the new instance
|
||||
# if that directory exists.
|
||||
#
|
||||
if [ -d /etc/xen-tools/skel ]; then
|
||||
|
||||
logMessage Copying files from /etc/xen-tools/skel
|
||||
|
||||
(cd /etc/xen-tools/skel; tar -cf - . ) | (cd ${prefix}/; tar -xpf -)
|
||||
|
||||
logMessage Finished
|
||||
|
||||
else
|
||||
|
||||
logMessage skel directory, /etc/xen-tools/skell, not present ignoring.
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our finish
|
||||
#
|
||||
logMessage Script $0 finished
|
||||
39
hooks/centos-5/70-install-ssh
Executable file
39
hooks/centos-5/70-install-ssh
Executable file
@ -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
|
||||
41
hooks/centos-5/80-install-modules
Executable file
41
hooks/centos-5/80-install-modules
Executable file
@ -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
|
||||
98
hooks/centos-5/90-make-fstab
Executable file
98
hooks/centos-5/90-make-fstab
Executable file
@ -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 <<E_O_FSTAB > ${prefix}/etc/fstab
|
||||
# /etc/fstab: static file system information.
|
||||
#
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
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
|
||||
44
hooks/centos-5/99-clean-image
Executable file
44
hooks/centos-5/99-clean-image
Executable file
@ -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
|
||||
49
hooks/fedora-core-6/10-disable-tls
Executable file
49
hooks/fedora-core-6/10-disable-tls
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script disables TLS on the new image.
|
||||
#
|
||||
# Steve
|
||||
# --
|
||||
# http://www.steve.org.uk/
|
||||
|
||||
|
||||
|
||||
prefix=$1
|
||||
|
||||
|
||||
#
|
||||
# Source our common functions
|
||||
#
|
||||
if [ -e /usr/lib/xen-tools/common.sh ]; then
|
||||
. /usr/lib/xen-tools/common.sh
|
||||
else
|
||||
. ./hooks/common.sh
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our start
|
||||
#
|
||||
logMessage Script $0 starting
|
||||
|
||||
|
||||
#
|
||||
# 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
|
||||
56
hooks/fedora-core-6/20-setup-yum
Executable file
56
hooks/fedora-core-6/20-setup-yum
Executable file
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
40
hooks/fedora-core-6/30-disable-gettys
Executable file
40
hooks/fedora-core-6/30-disable-gettys
Executable file
@ -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
|
||||
181
hooks/fedora-core-6/35-setup-users
Executable file
181
hooks/fedora-core-6/35-setup-users
Executable file
@ -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 ( <EXISTING> )
|
||||
{
|
||||
#
|
||||
# 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 ( <PASSWD> )
|
||||
{
|
||||
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 ( <SHADOW> )
|
||||
{
|
||||
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" );
|
||||
}
|
||||
}
|
||||
98
hooks/fedora-core-6/40-setup-networking
Executable file
98
hooks/fedora-core-6/40-setup-networking
Executable file
@ -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 <<E_O_STATIC >${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 <<E_O_STATIC >${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 <<E_O_DHCP >${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 <<EOF >${prefix}/etc/sysconfig/network
|
||||
NETWORKING=yes
|
||||
GATEWAY=${gateway}
|
||||
HOSTNAME=${hostname}
|
||||
EOF
|
||||
|
||||
|
||||
#
|
||||
# Log our finish
|
||||
#
|
||||
logMessage Script $0 finished
|
||||
118
hooks/fedora-core-6/50-setup-hostname
Executable file
118
hooks/fedora-core-6/50-setup-hostname
Executable file
@ -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 <<EOF
|
||||
127.0.0.1 localhost
|
||||
|
||||
# The following lines are desirable for IPv6 capable hosts
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
|
||||
EOF
|
||||
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Allow the host system to know the IP address of our new guest.
|
||||
#
|
||||
if [ -z "${dhcp}" ]; then
|
||||
|
||||
if ( grep ${hostname} /etc/hosts > /dev/null ) ; then
|
||||
|
||||
logMessage Host already has IP address for the host ${hostname}.
|
||||
|
||||
else
|
||||
|
||||
#
|
||||
# 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
|
||||
53
hooks/fedora-core-6/55-create-dev
Executable file
53
hooks/fedora-core-6/55-create-dev
Executable file
@ -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
|
||||
58
hooks/fedora-core-6/60-copy-host-files
Executable file
58
hooks/fedora-core-6/60-copy-host-files
Executable file
@ -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
|
||||
49
hooks/fedora-core-6/65-copy-user-files
Executable file
49
hooks/fedora-core-6/65-copy-user-files
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copy files from a 'skel' directory, if present, into the
|
||||
# new images
|
||||
#
|
||||
|
||||
|
||||
prefix=$1
|
||||
|
||||
|
||||
#
|
||||
# Source our common functions
|
||||
#
|
||||
if [ -e /usr/lib/xen-tools/common.sh ]; then
|
||||
. /usr/lib/xen-tools/common.sh
|
||||
else
|
||||
. ./hooks/common.sh
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our start
|
||||
#
|
||||
logMessage Script $0 starting
|
||||
|
||||
|
||||
#
|
||||
# Copy everything from the skel directory into the new instance
|
||||
# if that directory exists.
|
||||
#
|
||||
if [ -d /etc/xen-tools/skel ]; then
|
||||
|
||||
logMessage Copying files from /etc/xen-tools/skel
|
||||
|
||||
(cd /etc/xen-tools/skel; tar -cf - . ) | (cd ${prefix}/; tar -xpf -)
|
||||
|
||||
logMessage Finished
|
||||
|
||||
else
|
||||
|
||||
logMessage skel directory, /etc/xen-tools/skell, not present ignoring.
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Log our finish
|
||||
#
|
||||
logMessage Script $0 finished
|
||||
39
hooks/fedora-core-6/70-install-ssh
Executable file
39
hooks/fedora-core-6/70-install-ssh
Executable file
@ -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
|
||||
41
hooks/fedora-core-6/80-install-modules
Executable file
41
hooks/fedora-core-6/80-install-modules
Executable file
@ -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
|
||||
98
hooks/fedora-core-6/90-make-fstab
Executable file
98
hooks/fedora-core-6/90-make-fstab
Executable file
@ -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 <<E_O_FSTAB > ${prefix}/etc/fstab
|
||||
# /etc/fstab: static file system information.
|
||||
#
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
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
|
||||
44
hooks/fedora-core-6/99-clean-image
Executable file
44
hooks/fedora-core-6/99-clean-image
Executable file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user