| 1 |
#! /bin/sh
|
| 2 |
|
| 3 |
# $Id$
|
| 4 |
#
|
| 5 |
# subroutine definitions for linux
|
| 6 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 7 |
set_disk_info() {
|
| 8 |
|
| 9 |
# the variable holds a space separated list of devices and their block size
|
| 10 |
device_size=$(disk-info)
|
| 11 |
|
| 12 |
# a list of all local disks, without size
|
| 13 |
disklist=$(list_disks $device_size)
|
| 14 |
}
|
| 15 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 16 |
jobsrunning() {
|
| 17 |
|
| 18 |
# test if jobs are running
|
| 19 |
ps r | egrep -qv "ps r|TIME COMMAND"
|
| 20 |
}
|
| 21 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 22 |
eval_cmdline() {
|
| 23 |
|
| 24 |
# parse kernel parameters and define variables
|
| 25 |
local word
|
| 26 |
|
| 27 |
echo -n "Kernel parameters: "; cat /proc/cmdline
|
| 28 |
for word in $(cat /proc/cmdline) ; do
|
| 29 |
case $word in
|
| 30 |
[a-zA-Z]*=*)
|
| 31 |
echo "Defining variable: $word"
|
| 32 |
eval $word
|
| 33 |
;;
|
| 34 |
esac
|
| 35 |
done
|
| 36 |
}
|
| 37 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 38 |
task_confdir() {
|
| 39 |
|
| 40 |
local bootlog
|
| 41 |
eval_cmdline
|
| 42 |
|
| 43 |
bootlog=$LOGDIR/boot.log
|
| 44 |
get-boot-info
|
| 45 |
echo "Reading $bootlog"
|
| 46 |
. $bootlog
|
| 47 |
unset T170 T171 T172 ROOT_PATH BOOTFILE
|
| 48 |
|
| 49 |
# define flags to see if syslogd should be started
|
| 50 |
# this routine is called again, so you can use a hook to redefine flags
|
| 51 |
echo 6 > /proc/sys/kernel/printk
|
| 52 |
define_fai_flags
|
| 53 |
[ "$syslogd" ] && {
|
| 54 |
klogd -c7 -f $LOGDIR/kernel.log
|
| 55 |
syslogd -m 0 -p /tmp/etc/syslogsocket
|
| 56 |
}
|
| 57 |
|
| 58 |
echo "SERVER=$SERVER" >> $rcsfaivar
|
| 59 |
create_resolv_conf
|
| 60 |
get_fai_dir
|
| 61 |
}
|
| 62 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 63 |
task_partition() {
|
| 64 |
|
| 65 |
echo "Partitioning local harddisks"
|
| 66 |
[ ! -s $diskvar ] && setup_harddisks -d -X > $LOGDIR/format.log 2>&1
|
| 67 |
# setup_harddisks must create $diskvar file
|
| 68 |
if [ ! -s $diskvar ]; then
|
| 69 |
cat $LOGDIR/format.log
|
| 70 |
die "setup_harddisks did not create $diskvar file."
|
| 71 |
fi
|
| 72 |
# now define variable for root and boot partition and boot device
|
| 73 |
. $diskvar
|
| 74 |
}
|
| 75 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 76 |
task_extrbase() {
|
| 77 |
|
| 78 |
local fs=$FAI_ROOT/etc/$fstab
|
| 79 |
# extract the tar file which was the result of debootstrap
|
| 80 |
echo "Unpacking Debian base archive"
|
| 81 |
gzip -dc /var/tmp/base.tgz | tar -C $FAI_ROOT -xpf -
|
| 82 |
# now we can copy fstab
|
| 83 |
[ -f $fs ] && mv $fs $fs.old
|
| 84 |
cp -p $LOGDIR/$fstab $fs
|
| 85 |
}
|
| 86 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 87 |
task_mirror() {
|
| 88 |
|
| 89 |
# mount debian mirror directory
|
| 90 |
[ "$FAI_DEBMIRROR" ] || return # nothing to do
|
| 91 |
mkdir -p $FAI_ROOT/$MNTPOINT
|
| 92 |
mount $romountopt $FAI_DEBMIRROR $FAI_ROOT/$MNTPOINT ||
|
| 93 |
die "Can't mount $FAI_DEBMIRROR"
|
| 94 |
}
|
| 95 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 96 |
task_updatebase() {
|
| 97 |
|
| 98 |
# maybe the base system is not up to date
|
| 99 |
echo "Updating base"
|
| 100 |
# try to mount the config space, since it can also contain Debian Packages
|
| 101 |
# in /fai/files/packages
|
| 102 |
mount --bind $FAI $FAI_ROOT/fai
|
| 103 |
if [ "$debug" ]; then
|
| 104 |
prepare_apt | tee -a $LOGDIR/updatebase.log 2>&1
|
| 105 |
else
|
| 106 |
prepare_apt > $LOGDIR/updatebase.log 2>&1
|
| 107 |
fi
|
| 108 |
}
|
| 109 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 110 |
task_instsoft() {
|
| 111 |
|
| 112 |
echo "Installing software may take a while"
|
| 113 |
if [ "$debug" ]; then
|
| 114 |
install_packages | tee -a $LOGDIR/software.log
|
| 115 |
elif [ "$verbose" ]; then
|
| 116 |
yes '' | install_packages 2>&1 | tee -a $LOGDIR/software.log
|
| 117 |
else
|
| 118 |
yes '' | install_packages >> $LOGDIR/software.log 2>&1
|
| 119 |
fi
|
| 120 |
}
|
| 121 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 122 |
task_finish() {
|
| 123 |
|
| 124 |
# umount swap space
|
| 125 |
ifconfig
|
| 126 |
local sd
|
| 127 |
for sd in $SWAPLIST; do
|
| 128 |
swapoff $sd && [ "$verbose" ] && echo "Disable swap device $sd"
|
| 129 |
done
|
| 130 |
umount -n $FAI_ROOT/proc
|
| 131 |
# undo fake of all programs made by fai
|
| 132 |
fai-divert -R
|
| 133 |
}
|
| 134 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 135 |
task_chboot() {
|
| 136 |
|
| 137 |
local frsh
|
| 138 |
frsh="$FAI_REMOTESH -l $LOGUSER ${SERVER}"
|
| 139 |
|
| 140 |
if [ -z "$LOGUSER" ] ; then
|
| 141 |
echo "LOGUSER not defined. Can't change network boot configuration"
|
| 142 |
exit
|
| 143 |
fi
|
| 144 |
|
| 145 |
if dmesg | grep -q "Sending BOOTP requests"; then
|
| 146 |
# change boot device (local disk or network) when using bootp
|
| 147 |
[ "$LOGUSER" -a "$TFTPLINK" ] &&
|
| 148 |
$frsh "cd /boot/fai; rm -f $HOSTNAME; ln -s $TFTPLINK $HOSTNAME"
|
| 149 |
else
|
| 150 |
# change boot device (local disk or network) when using DHCP
|
| 151 |
# first test if a given filename exists on the server
|
| 152 |
testcmd="test -s /boot/fai/$HOSTNAME-localboot ; echo \$?"
|
| 153 |
ret=`$FAI_REMOTESH -l $LOGUSER ${SERVER} "$testcmd"`
|
| 154 |
if [ "$ret" -ne 0 ]; then
|
| 155 |
# copy the kernel to the server
|
| 156 |
$FAI_REMOTECP $target/boot/vmlinuz-* $LOGUSER@${SERVER}:/boot/fai/$HOSTNAME-localboot
|
| 157 |
fi
|
| 158 |
. $diskvar # read ROOT_PARTITION
|
| 159 |
$frsh fai-chboot -v $HOSTNAME-localboot $ROOT_PARTITION $HOSTNAME
|
| 160 |
fi
|
| 161 |
}
|
| 162 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|