| 1 |
#! /bin/sh
|
| 2 |
|
| 3 |
# $Id$
|
| 4 |
#*********************************************************************
|
| 5 |
#
|
| 6 |
# make-fai-nfsroot -- create nfsroot directory and add additional packages
|
| 7 |
#
|
| 8 |
# This script is part of FAI (Fully Automatic Installation)
|
| 9 |
# (c) 2000-2001 by Thomas Lange, lange@informatik.uni-koeln.de
|
| 10 |
# Universitaet zu Koeln
|
| 11 |
#
|
| 12 |
#*********************************************************************
|
| 13 |
# This program is free software; you can redistribute it and/or modify
|
| 14 |
# it under the terms of the GNU General Public License as published by
|
| 15 |
# the Free Software Foundation; either version 2 of the License, or
|
| 16 |
# (at your option) any later version.
|
| 17 |
#
|
| 18 |
# This program is distributed in the hope that it will be useful, but
|
| 19 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 21 |
# General Public License for more details.
|
| 22 |
#
|
| 23 |
# A copy of the GNU General Public License is available as
|
| 24 |
# `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
|
| 25 |
# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
|
| 26 |
# can also obtain it by writing to the Free Software Foundation, Inc.,
|
| 27 |
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 28 |
#*********************************************************************
|
| 29 |
|
| 30 |
# Thomas Lange, Universitaet Koeln, 2000
|
| 31 |
|
| 32 |
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
| 33 |
|
| 34 |
while getopts v opt ; do
|
| 35 |
case "$opt" in
|
| 36 |
v) verbose=1 ;;
|
| 37 |
esac
|
| 38 |
done
|
| 39 |
|
| 40 |
if [ "$UID" -ne 0 ]; then
|
| 41 |
echo "Run this program as root."
|
| 42 |
exit 9
|
| 43 |
fi
|
| 44 |
|
| 45 |
set -e
|
| 46 |
. /etc/fai.conf
|
| 47 |
|
| 48 |
conffile=$NFSROOT/etc/rcS_fai.conf
|
| 49 |
|
| 50 |
# Additional packages that are install to nfsroot
|
| 51 |
packages="$NFSROOT_PACKAGES perl-5.005 dhcp-client file rdate cfengine bootpc wget rsh-client less dump ext2resize raidtools2 strace expect5.31 hdparm parted dnsutils"
|
| 52 |
|
| 53 |
export DEBIAN_FRONTEND=Noninteractive
|
| 54 |
|
| 55 |
if [ "$verbose" ]; then
|
| 56 |
devnull=/dev/tty
|
| 57 |
else
|
| 58 |
devnull=/dev/null
|
| 59 |
fi
|
| 60 |
|
| 61 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 62 |
die() {
|
| 63 |
|
| 64 |
echo $*
|
| 65 |
exit 99
|
| 66 |
}
|
| 67 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 68 |
setup_ssh() {
|
| 69 |
|
| 70 |
# if no ssh in nfsroot available, do nothing
|
| 71 |
[ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return
|
| 72 |
mkdir -p -m 700 $NFSROOT/root/.ssh
|
| 73 |
hkey=`cat /etc/ssh/ssh_host_key.pub`
|
| 74 |
hname=`$NFSROOT/usr/bin/host $HOST | perl -pe 's/\s+A\s+/,/'`
|
| 75 |
echo "$hname $hkey " > $NFSROOT/root/.ssh/known_hosts
|
| 76 |
loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
|
| 77 |
[ -d $loguserhome/.ssh ] && cp -p $loguserhome/.ssh/identity* $NFSROOT/root/.ssh/
|
| 78 |
|
| 79 |
# enable root login
|
| 80 |
perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
|
| 81 |
if [ -f "$SSH_IDENTITY" ]; then
|
| 82 |
cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
|
| 83 |
echo You can log into install clients without password using $SSH_IDENTITY
|
| 84 |
fi
|
| 85 |
}
|
| 86 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 87 |
copy_fai_files() {
|
| 88 |
|
| 89 |
perl -pi -e "s/^root::/root:${FAI_ROOTPW}:/" etc/passwd
|
| 90 |
mkdir -p $NFSROOT/fai/fai_config $NFSROOT/usr/share/fai
|
| 91 |
cp -p $LIBFAI/sbin/dhclient-script $LIBFAI/etc/dhclient.conf $NFSROOT/etc
|
| 92 |
cp -p $LIBFAI/sbin/* $NFSROOT/sbin
|
| 93 |
cp -p /usr/share/fai/* $NFSROOT/usr/share/fai
|
| 94 |
cp -p $LIBFAI/etc/apt.conf $NFSROOT/etc/apt
|
| 95 |
cp -p $LIBFAI/etc/fai_modules_off $NFSROOT/etc/modutils
|
| 96 |
cp -p /usr/lib/perl5/Debian/Fai.pm $NFSROOT/usr/lib/perl5/Debian/
|
| 97 |
cp -p /etc/fai.conf $NFSROOT/etc
|
| 98 |
cp -p /tmp/base?_?.tgz $NFSROOT/var/tmp
|
| 99 |
echo $NFSROOT_ETC_HOSTS >> $NFSROOT/etc/hosts
|
| 100 |
}
|
| 101 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 102 |
create_nfsroot() {
|
| 103 |
|
| 104 |
mkdir -p $NFSROOT
|
| 105 |
cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
|
| 106 |
get_basetgz
|
| 107 |
echo -n "Unpacking " ; ls /tmp/base?_?.tgz
|
| 108 |
tar -C $NFSROOT -zxpf /tmp/base?_?.tgz
|
| 109 |
# needed by make-fai-bootfloppy
|
| 110 |
mknod $NFSROOT/dev/boot255 c 0 255
|
| 111 |
|
| 112 |
if [ "$FAI_DEBMIRROR" ]; then
|
| 113 |
mkdir -p $NFSROOT/$MNTPOINT
|
| 114 |
mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || die "Can't mount $FAI_DEBMIRROR"
|
| 115 |
fi
|
| 116 |
|
| 117 |
# hoaks some packages
|
| 118 |
touch etc/fstab etc/raidtab # dump and raidtool2 needs these files
|
| 119 |
mkdir -p lib/modules/$KERNELVERSION # dirty trick to hoax lvm
|
| 120 |
touch lib/modules/$KERNELVERSION/modules.dep # dirty trick to hoax lvm
|
| 121 |
mkdir -p $NFSROOT/etc/ssh
|
| 122 |
touch $NFSROOT/etc/ssh/NOSERVER
|
| 123 |
|
| 124 |
echo "$FAI_SOURCES_LIST" > $NFSROOT/etc/apt/sources.list
|
| 125 |
upgrade_nfsroot
|
| 126 |
copy_fai_files
|
| 127 |
|
| 128 |
# set timezone
|
| 129 |
rm -f $NFSROOT/etc/localtime
|
| 130 |
cp -d /etc/localtime /etc/timezone $NFSROOT/etc
|
| 131 |
|
| 132 |
# make little changes to nfsroot, because file systems are
|
| 133 |
# read only for the install clients
|
| 134 |
rm -rf etc/mtab var/run
|
| 135 |
mv $NFSROOT/etc/init.d/rcS $NFSROOT/etc/init.d/rcS.orig
|
| 136 |
ln -s /proc/mounts $NFSROOT/etc/mtab
|
| 137 |
ln -s /tmp/var/run $NFSROOT/var/run
|
| 138 |
ln -sf /tmp/etc/resolv.conf $NFSROOT/etc/resolv.conf
|
| 139 |
ln -s /sbin/rcS_fai $NFSROOT/etc/init.d/rcS
|
| 140 |
|
| 141 |
# turn off logging of loading kernel modules
|
| 142 |
rmdir $NFSROOT/var/log/ksymoops/
|
| 143 |
ln -s /dev/null $NFSROOT/var/log/ksymoops
|
| 144 |
|
| 145 |
# definition for loopback device
|
| 146 |
echo "iface lo inet loopback" >$NFSROOT/etc/network/interfaces
|
| 147 |
|
| 148 |
echo "*.* /tmp/syslog.log" >$NFSROOT/etc/syslog.conf
|
| 149 |
echo ". /usr/share/fai/subroutines" >> $NFSROOT/root/.profile
|
| 150 |
|
| 151 |
setup_ssh
|
| 152 |
umount $NFSROOT/dev/pts 2>/dev/null || true
|
| 153 |
|
| 154 |
cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
|
| 155 |
#!/bin/sh
|
| 156 |
echo FAI: installation aborted.
|
| 157 |
echo reboot with: faireboot
|
| 158 |
echo or after a logout
|
| 159 |
sh
|
| 160 |
cd /
|
| 161 |
umount -ar
|
| 162 |
reboot -dfi
|
| 163 |
EOF
|
| 164 |
chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
|
| 165 |
}
|
| 166 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 167 |
upgrade_nfsroot() {
|
| 168 |
|
| 169 |
echo "Upgrading $NFSROOT"
|
| 170 |
{
|
| 171 |
cp /etc/resolv.conf $NFSROOT/etc
|
| 172 |
chroot $NFSROOT apt-get update
|
| 173 |
chroot $NFSROOT apt-get check
|
| 174 |
chroot $NFSROOT mount -n -t proc proc /proc
|
| 175 |
rm -rf $NFSROOT/etc/pcmcia $NFSROOT/etc/apm
|
| 176 |
chroot $NFSROOT apt-get -y remove pcmcia-cs </dev/null
|
| 177 |
|
| 178 |
# fake start-stop-dameon
|
| 179 |
chroot $NFSROOT dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon
|
| 180 |
cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin
|
| 181 |
chroot $NFSROOT apt-get -y upgrade
|
| 182 |
} > $devnull
|
| 183 |
echo "Adding additional packages to $NFSROOT:"
|
| 184 |
echo "$packages"
|
| 185 |
{
|
| 186 |
chroot $NFSROOT apt-get -y --fix-missing install $packages </dev/null
|
| 187 |
chroot $NFSROOT apt-get clean
|
| 188 |
chroot $NFSROOT umount -n /proc
|
| 189 |
} > $devnull
|
| 190 |
}
|
| 191 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 192 |
get_basetgz() {
|
| 193 |
|
| 194 |
[ -f /tmp/base?_?.tgz ] && return
|
| 195 |
[ "$FAI_BASETGZ" ] || die "no /tmp/base?_?.tgz found and FAI_BASETGZ not defined."
|
| 196 |
case $FAI_BASETGZ in
|
| 197 |
ftp:*|http:*)
|
| 198 |
echo "Getting $FAI_BASETGZ via wget. This may take some time."
|
| 199 |
TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1
|
| 200 |
rm $TMPBDIR; mkdir $TMPBDIR || exit
|
| 201 |
wget -P$TMPBDIR $FAI_BASETGZ
|
| 202 |
mv $TMPBDIR/base?_?.tgz /tmp
|
| 203 |
rm -rf $TMPBDIR
|
| 204 |
;;
|
| 205 |
/*/base?_?.tgz)
|
| 206 |
rm -f /tmp/base?_?.tgz
|
| 207 |
test -r $FAI_BASETGZ || die "Can't read $FAI_BASETGZ. Check FAI_BASETGZ in fai.conf."
|
| 208 |
ln -s $FAI_BASETGZ /tmp
|
| 209 |
;;
|
| 210 |
*)
|
| 211 |
die "FAI_BASETGZ in fai.conf is $FAI_BASETGZ and looks very strong."
|
| 212 |
;;
|
| 213 |
esac
|
| 214 |
}
|
| 215 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 216 |
# main routine
|
| 217 |
|
| 218 |
if [ -d $NFSROOT/fai ]; then
|
| 219 |
echo $NFSROOT already exists. Removing $NFSROOT
|
| 220 |
umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
|
| 221 |
rm -rf $NFSROOT
|
| 222 |
fi
|
| 223 |
|
| 224 |
create_nfsroot
|
| 225 |
|
| 226 |
# TODO: only umount if created (debian mirror via NFS)
|
| 227 |
test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
|
| 228 |
|
| 229 |
exit 0
|