File: subroutines-linux

package info (click to toggle)
fai 3.1.8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,144 kB
  • ctags: 164
  • sloc: sh: 3,410; perl: 1,780; makefile: 113
file content (292 lines) | stat: -rw-r--r-- 8,978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#! /bin/bash

# $Id: subroutines-linux 4170 2006-11-27 16:32:52Z lange $
#
# subroutine definitions for linux
#
# This script is part of FAI (Fully Automatic Installation)
# (c) 2005-2006 by Thomas Lange, lange@informatik.uni-koeln.de
# Universitaet zu Koeln
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### BEGIN SUBROUTINE INFO
# Provides-Var:    $device_size $disklist
# Requires-Var:    
# Short-Description: create list of available disks and their sizes
### END SUBROUTINE INFO

set_disk_info() {

    # the variable holds a space separated list of devices and their block size
    device_size=$(disk-info)

    # a list of all local disks, without size
    disklist=$(list_disks $device_size | sort)
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
jobsrunning() {

    # test if jobs are running
    ps r | egrep -qv "ps r|TIME COMMAND"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
eval_cmdline() {

    # parse kernel parameters and define variables
    local word

    echo -n "Kernel parameters: "; cat /proc/cmdline
    for word in $(cat /proc/cmdline) ; do
	case $word in
	    [a-zA-Z]*=*)
		eval "export $word"
		;;
	esac
    done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### BEGIN SUBROUTINE INFO
# Provides-Var:    $faimond $sendhostname
# Requires-Var:    $LOGDIR $FAI
# Suggests-Var:    $monserver
# Short-Description: <task desc.>
### END SUBROUTINE INFO

task_confdir() {

    if [ $do_init_tasks -eq 1 ] ; then
        local bootlog
        eval_cmdline

        bootlog=$LOGDIR/boot.log
        get-boot-info
        echo "Reading $bootlog"
        . $bootlog
        unset T170 T171 T172 ROOT_PATH BOOTFILE

        echo 6 > /proc/sys/kernel/printk
	klogd -c7 -f $LOGDIR/kernel.log
	syslogd -m 0
        create_resolv_conf
	mkrw -s 100m $FAI
    fi
    define_fai_flags
    get-config-dir || {
	echo "Problems accessing the config space."
	die ""
    }
    # now you have enough time to make changes to the config space
    if [ -n "$flag_wait" ]; then
	echo "Sleeping. Now you may change the config space in $FAI."
	echo "Continue after killall sleep."
	sleep 50000
    fi

    # check if monitor server is available
    [ -z "$monserver" ] && monserver=$SERVER
    faimond=1
    sendhostname=$HOSTNAME # save current hostname
    if sendmon check; then
	echo "Monitoring to server $monserver enabled."
    else
	faimond=0
	echo "Can't connect to monserver on $monserver port 4711. Monitoring disabled."
    fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### BEGIN SUBROUTINE INFO
# Provides-Var:    $BOOT_DEVICE $ROOT_PARTITION $BOOT_PARTITION $SWAPLIST
# Requires-Var:    $LOGDIR $LOGDIR/disk_var.sh
# Short-Description: partition local hard disk
### END SUBROUTINE INFO

task_partition() {

    echo "Partitioning local harddisks"
    [ ! -s $LOGDIR/disk_var.sh ] && setup_harddisks -d -X | tee $LOGDIR/format.log 2>&1
    # setup_harddisks must create $LOGDIR/disk_var.sh file
    if [ ! -s $LOGDIR/disk_var.sh ]; then
	cat $LOGDIR/format.log
	sendmon "TASKERROR partition 21"
	die "setup_harddisks did not create $LOGDIR/disk_var.sh file."
    fi
    # now define variable for root and boot partition and boot device
    . $LOGDIR/disk_var.sh
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### BEGIN SUBROUTINE INFO
# Provides-Var:    none
# Requires-Var:    $FAI_ROOT $do_init_tasks $NFSROOT $LOGDIR
# Suggests-Var:    
# Short-Description: <task desc.>
### END SUBROUTINE INFO

task_extrbase() {

    local fs=$FAI_ROOT/etc/fstab
    local basefile=/var/tmp/base.tgz

    echo "Unpacking Debian base archive"
    # copy the base file class based if it exists
    [ -d $FAI/basefiles ] && ftar -1v -s $FAI/basefiles /
    if [ $? -ne 0 ]; then
	[ $do_init_tasks -eq 0 ] && basefile=$NFSROOT/var/tmp/base.tgz
	[ -f $basefile ] || die "$basefile not found. Can't extract it. Aborting."
	# extract the tar file which was the result of debootstrap
	echo "Extracting $NFSROOT/var/tmp/base.tgz"
	gzip -dc $basefile | tar -C $FAI_ROOT -xpf -
    fi
    # now we can copy fstab
    [ -f $fs ] && mv $fs $fs.old
    [ -f $LOGDIR/fstab ] && cp -p $LOGDIR/fstab $fs
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### BEGIN SUBROUTINE INFO
# Provides-Var:    
# Requires-Var:    $FAI_ROOT $MNTPOINT $romountopt
# Suggests-Var:    $FAI_DEBMIRROR $debug
# Short-Description: <task desc.>
### END SUBROUTINE INFO

task_mirror() {

    # mount debian mirror directory
    [ "$FAI_DEBMIRROR" ] || return   # nothing to do
    mkdir -p $FAI_ROOT/$MNTPOINT
    if mount $romountopt $FAI_DEBMIRROR $FAI_ROOT/$MNTPOINT; then
      [ "$debug" ] && echo "Mirror mounted from $FAI_DEBMIRROR to $FAI_ROOT/$MNTPOINT"
    else
      sendmon "TASKERROR mirror $?"
      die "Can't mount $FAI_DEBMIRROR"
    fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
task_debconf () {

    if [ ! -d $FAI/debconf ]; then
	echo "Can't find debconf directory $FAI/debconf. Skipping preseeding."
	task_error=2
	return
    fi
    fai-debconf $FAI/debconf
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### BEGIN SUBROUTINE INFO
# Provides-Var:    none
# Requires-Var:    $FAI_ROOT $FAI_ETC_DIR
# Suggests-Var:    $IPADDR $DOMAIN
# Short-Description: <task desc.>
### END SUBROUTINE INFO

task_prepareapt () {

    # ftp and http needs resolv.conf in chroot environment, /etc/hosts is useful
    # think about using fcopy for these two files
    [ -f /etc/resolv.conf ] && cp /etc/resolv.conf $FAI_ROOT/etc
    [ -f /etc/hosts ] && cp /etc/hosts $FAI_ROOT/etc
    # set hostname in $FAI_ROOT
    if [ -f /var/run/fai/FAI_INSTALLATION_IN_PROGRESS ]; then
      echo $HOSTNAME >$FAI_ROOT/etc/hostname
      if [ -n "$IPADDR" ]; then
	  ainsl -s $FAI_ROOT/etc/hosts "$IPADDR $HOSTNAME.$DOMAIN $HOSTNAME"
      fi
    fi

    if [ X$FAI_ALLOW_UNSIGNED = X1 ]; then
	cat <<EOF > $FAI_ROOT/etc/apt/apt.conf.d/10fai
APT::Get::AllowUnauthenticated "true";
Aptitude::CmdLine::Ignore-Trust-Violations yes;
EOF
    fi
    # during normal installation, we need sources.list from /etc/apt
    [ $do_init_tasks -eq 1 ] && FAI_ETC_DIR=/etc
    [ -d $FAI_ETC_DIR/apt ] && cp -r $FAI_ETC_DIR/apt/* $FAI_ROOT/etc/apt/
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
task_updatebase() {

    # maybe the base system is not up to date
    echo "Updating base"
    updatebase
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
task_instsoft() {

    echo "Installing software may take a while"
    if [ "$debug" ]; then
	install_packages | tee -a $LOGDIR/software.log
    elif [ "$verbose" ]; then
	install_packages </dev/null 2>&1 | tee -a $LOGDIR/software.log
    else
	install_packages </dev/null >> $LOGDIR/software.log 2>&1
    fi
    # This almost indicates an error
    egrep "^E:" $LOGDIR/software.log && task_error=1
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
task_finish() {

    if [ $do_init_tasks -eq 1 ] ; then
	# show some local information
	ifconfig; df
	# umount swap space
	swapoff -a
    fi
    # undo fake of all programs made by fai
    fai-divert -R
    rm -f $FAI_ROOT/etc/apt/apt.conf.d/{10,90}fai
    date
    echo "The $FAI_ACTION took $[$(cut -d . -f 1 /proc/uptime)-$start_seconds] seconds."
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
task_chboot() {

    # the whole subroutine may be an externel script

    [ -z "$LOGUSER" ] && return # silently return from subroutine

    local frsh
    local doexit=0
    local hostname=$(hostname)
    local ipaddr=$(grep IPADDR $LOGDIR/boot.log | cut -d\' -f2)
    local remotesh

    case "$FAI_LOGPROTO" in
	ftp) remotesh=ssh ;;
	ssh) remotesh=ssh ;;
	rsh) remotesh=rsh ;;
    esac
    frsh="$remotesh -l $LOGUSER ${SERVER}"

    if [ -z "$SERVER" ] ; then
	echo "SERVER not defined. Can't change network boot configuration"
	task_error=2
	doexit=1
    fi
    [ $doexit -eq 1 ] && return

    if dmesg | grep -q "Sending BOOTP requests"; then
        # change boot device (local disk or network) when using bootp
	[ "$LOGUSER" -a "$TFTPLINK" ] &&
	    $frsh "cd /srv/tftp/fai; rm -f $hostname; ln -s $TFTPLINK $hostname"
    else
        # change boot device (local disk or network) when using PXE
        # first test if rsh to server works
	$frsh true >/dev/null 2>&1
	if [ $? -ne 0 ]; then
	    task_error=3
	    echo "WARNING: $frsh failed. Can't call fai-chboot on the install server."
	else
	    # remove pxe config, so host will use default and boot from local disk
	    $frsh /usr/sbin/fai-chboot -vd $ipaddr
	fi
    fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sendmon() {

    # send message to monitor daemon
    [ "$faimond" -eq 0 ] && return 0
    echo "$sendhostname $*" | nc $monserver 4711 2>/dev/null
    return $?
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -