/[fai]/trunk/bin/fai
ViewVC logotype

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5368 - (hide annotations) (download)
Mon Apr 20 09:54:59 2009 UTC (4 years, 2 months ago) by lange
File size: 9492 byte(s)
fai,subroutines: move definition of trap clean_exit into task
dirinstall
1 lange 2661 #!/bin/bash
2     # $Id$
3     #*********************************************************************
4     #
5 lange 2732 # fai -- main installation script executed after booting
6 lange 2661 #
7     # This script is part of FAI (Fully Automatic Installation)
8 lange 5240 # (c) 1999-2009 by Thomas Lange, lange@informatik.uni-koeln.de
9 lange 2661 # Universitaet zu Koeln
10 lange 5018 # (c) 2001-2005 by Henning Glawe, glaweh@physik.fu-berlin.de
11     # Freie Universitaet Berlin
12 lange 2661 #
13     #*********************************************************************
14     # This program is free software; you can redistribute it and/or modify
15     # it under the terms of the GNU General Public License as published by
16     # the Free Software Foundation; either version 2 of the License, or
17     # (at your option) any later version.
18     #
19     # This program is distributed in the hope that it will be useful, but
20     # WITHOUT ANY WARRANTY; without even the implied warranty of
21     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22     # General Public License for more details.
23     #
24     # A copy of the GNU General Public License is available as
25     # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
26     # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
27     # can also obtain it by writing to the Free Software Foundation, Inc.,
28 lange 4677 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29 lange 2661 #*********************************************************************
30    
31     #set -xv # for full debugging
32    
33     export PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
34     # some variables
35     export FAI_VERSION=FAIVERSIONSTRING
36 lange 3850 stamp=/var/run/fai/FAI_INSTALLATION_IN_PROGRESS
37 lange 4655 export romountopt="-o async,noatime,nolock,ro,actimeo=1800"
38 lange 2661
39 lange 5332 export STOP_ON_ERROR=700
40 lange 3920 export faimond=0
41 lange 3779 export renewclass=0
42 lange 2661 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43     fai_init() {
44    
45     set -a # now export all variables
46 lange 4684 set -o pipefail
47 lange 2661
48     umask 022
49 lange 5335 mkdir -p /var/run/fai
50 lange 3875 if [ ! -d "$FAI_ETC_DIR" ]; then
51     echo "$FAI_ETC_DIR is not a directory"
52 lange 3808 exit 6
53     fi
54 lange 3875 [ -f $FAI_ETC_DIR/fai.conf ] && . $FAI_ETC_DIR/fai.conf
55 lange 2661
56 lange 4319 if [ -f /etc/RUNNING_FROM_FAICD ]; then # we are booting from fai cd
57 lange 2661 umount /initrd
58     romountopt=
59     FAI_DEBMIRROR="--bind /media/mirror"
60     MNTPOINT=/media/mirror
61 lange 3912 FAI_CONFIG_SRC="file://$FAI" # on a fai-cd the config space is already available
62 lange 2661 fi
63    
64     # some variables from are not needed any more
65 lange 3784 #unset FAI_CONFIGDIR
66 lange 2661
67     # read subroutine definitions
68 lange 3714 local sub=/usr/lib/fai/subroutines
69 lange 2661 [ -f $sub ] && . $sub
70 lange 3714 [ -f $sub-linux ] && . $sub-linux
71 lange 2661
72     [ -f "$stamp" ] && {
73 lange 4710 echo -n "$0 already running or was aborted before. PID: "
74     cat $stamp
75 lange 4565 echo "You may remove $stamp and try again."
76 lange 2661 exit 1
77     }
78    
79     DEBIAN_FRONTEND=noninteractive
80     # local disks are mounted to $FAI_ROOT
81     if [ -z "$FAI_ROOT" ] ; then
82 lange 4512 [ $do_init_tasks -eq 1 ] && FAI_ROOT=/target || FAI_ROOT=/
83 lange 2661 fi
84     # executed command in the environment of the new system
85     ROOTCMD="chroot $FAI_ROOT"
86     # no chroot needed
87     [ "$FAI_ROOT" = '/' ] && ROOTCMD=
88 lange 3777 target=$FAI_ROOT
89 lange 2661
90 lange 3831 if [ $do_init_tasks -eq 1 ]; then
91 lange 3930 trap 'echo "Now rebooting";faireboot' INT QUIT
92 lange 2661 else
93 lange 3930 trap "echo 'Aborted';rm -f $stamp" INT QUIT
94 lange 2661 fi
95    
96 lange 3831 if [ $do_init_tasks -eq 1 ]; then
97 lange 3777 eval_cmdline
98 lange 3708 mount -t sysfs sysfs /sys
99 lange 4117 # we really need to start udev
100     [ -x /etc/init.d/udev ] && /etc/init.d/udev start
101 lange 4363 mkdir -p /var/run/network
102     mkdir -p /dev/shm/network # when using initrd kernels
103 lange 3708 ifup lo
104     [ -x /sbin/portmap ] && /sbin/portmap
105     mount -t devpts devpts /dev/pts
106     cat /proc/kmsg >/dev/tty4 &
107 lange 2661 fi
108 lange 3409
109 lange 3777 # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called
110 lange 3851 [ -z "$classes" ] && classes="DEFAULT $(uname -s | tr a-z A-Z) $HOSTNAME LAST"
111 lange 3777
112 lange 3409 prcopyleft
113 lange 2661
114 lange 4375 [ $do_init_tasks -eq 1 ] && save_dmesg
115 lange 2661 }
116     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
117     usage() {
118 lange 2732 cat <<-EOF
119 lange 5240 fai $FAI_VERSION. Copyright (C) 1999-2009 Thomas Lange
120 lange 2732 Usage: $0 [options] [action]
121 lange 5351
122 lange 2732 Options:
123 lange 5351 -v|--verbose display more information during the update
124     -h|--help display this help message
125     -N|--new renew list of classes
126     -c|--class comma separated list of classes
127     -C|--cfdir CFDIR Use CFDIR for reading the config files
128     -u|--hostname HNAME set hostname to be used
129 lange 3784
130 lange 2661 EOF
131     exit 0
132     }
133     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
134     fstart() {
135    
136     # these tasks can define variables, that are needed later
137 lange 3950 [ -n "$etc_message" ] && echo ""
138 lange 3949 echo "$etc_message"
139 lange 3969 [ $do_init_tasks -eq 1 ] || echo "Using configuration files from $FAI_ETC_DIR"
140 lange 3948 unset etc_message
141 lange 2661 task confdir
142     task setup
143     task defclass
144 lange 3820 unset cmdlineclasses renewclass
145 lange 3831 [ $do_init_tasks -eq 1 ] && set_disk_info
146 lange 2661 task defvar
147 lange 3831 [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
148 lange 2661 }
149     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150     # Main routine
151    
152     # Parse commandline options
153 lange 4213 TEMP=$(getopt -o u:Nhvc:C: --long hostname:,new,help,verbose,class:,cfdir: -n "$0" -- "$@")
154 lange 2661 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
155     # Note the quotes around `$TEMP': they are essential!
156     eval set -- "$TEMP"
157 lange 3810 unset TEMP
158 lange 2661
159     while true ; do
160     case "$1" in
161     -h|--help)
162     shift
163     usage
164     ;;
165     -v|--verbose)
166     shift
167 lange 3779 export verbose=1
168 lange 2661 ;;
169 lange 2761 -N|--new)
170     shift
171 lange 2770 renewclass=1
172 lange 2761 ;;
173 lange 3922 -C|--cfdir)
174 lange 3808 shift
175 lange 3948 cfdir=$1
176 lange 3808 shift
177     ;;
178 lange 3922 -c|--class)
179 lange 3795
180     if [ $renewclass -eq 1 ]; then
181     echo "You can't use -c|--classes and -N|--new at the same time."
182     exit 9
183     fi
184 lange 3784 shift
185 lange 3795 export cmdlineclasses=$1
186 lange 3784 shift
187 lange 3795 cmdlineclasses=${cmdlineclasses//,/ }
188 lange 3784 ;;
189 lange 4067 -u|--hostname)
190     shift
191     export newhostname=$1
192 lange 4200 shift
193 lange 4067 ;;
194 lange 2661 --)
195     shift
196     break
197     ;;
198     *)
199     echo "$0: command line parsing error ! $@"
200     exit 1
201     ;;
202     esac
203     done
204    
205 lange 3948 # use FAI_ETC_DIR from environment variable
206     if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
207     # print this message later so it gets into the log files
208 lange 3949 etc_message="Using environment variable \$FAI_ETC_DIR."
209 lange 3948 fi
210     [ -n "$cfdir" ] && FAI_ETC_DIR=$cfdir
211     unset cfdir
212     : ${FAI_ETC_DIR:=/etc/fai}
213 lange 3949 FAI_ETC_DIR=$(readlink -f $FAI_ETC_DIR) # canonicalize path
214 lange 3948 export FAI_ETC_DIR
215    
216 lange 3784 # override FAI_ACTION later if a command line argument is given
217 lange 4374 [ "$1" ] && export action=$1
218 lange 4074 [ "$2" ] && export FAI_ROOT=$2 # only used for dirinstall
219 lange 3708
220 lange 4074 if [ X$action = Xdirinstall ]; then
221 lange 3987 if [ -z "$FAI_ROOT" ]; then
222 lange 3798 echo "Please specify a target directory. Aborted"
223     exit 3
224     fi
225 lange 4492 if [ $renewclass -eq 0 -a -z "$cmdlineclasses" ]; then
226     echo "Please use -c or -N. Aborted"
227     exit 4
228     fi
229    
230 lange 4900 # two lines taken from task_dirinstall
231     mkdir -p $FAI_ROOT
232     FAI_ROOT=$(cd $FAI_ROOT;pwd)
233    
234 lange 4815 # check if target directory is mounted with bad options
235 lange 4900 fs=$(df $FAI_ROOT | tail -1 | awk '{print $6}')
236     if mount | grep "on $fs " | awk '{print $6}' | egrep -q "nosuid|nodev"; then
237 holger 4896 echo "Target directory is mounted using nosuid or nodev. Aborting"
238 lange 4815 exit 5
239     fi
240 lange 4900 unset fs
241 lange 4492
242 lange 3884 export NFSROOT=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $NFSROOT)
243 lange 4389 export FAI_DEBOOTSTRAP=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_DEBOOTSTRAP)
244 lange 4689 export FAI_DEBOOTSTRAP_OPTS=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_DEBOOTSTRAP_OPTS)
245 lange 4389
246 lange 3784 fi
247    
248 lange 3708 if [ $(id -u) != "0" ]; then
249 lange 3151 echo "Run this program as root."
250     exit 1
251     fi
252    
253 lange 3291 # exit if we do not run from nfsroot and no parameter is given
254 lange 3304 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
255 lange 3291 echo "Please give more parameters if not run from the nfsroot."
256     exit 2
257     fi
258    
259 lange 3826 # are we called as an init substitute ?
260 lange 3831 export do_init_tasks=0
261     [ "$0" = "/etc/init.d/rcS" ] && do_init_tasks=1
262     if [ $do_init_tasks -eq 1 ]; then
263 lange 4344 hostname $HOSTNAME
264 lange 3826 renewclass=1 # always renew class list when installing
265 lange 4447 mkdir -p /var/lib/discover /var/discover /etc/sysconfig
266 lange 3826 fi
267 lange 4811
268     [ -f /proc/version ] || mount -n -t proc proc /proc # ubuntu initrd does not mount /proc
269 lange 3826 export start_seconds=$(cut -d . -f 1 /proc/uptime)
270 lange 3410
271 lange 5351 [ -n "$newhostname" ] && export HOSTNAME=$newhostname
272 lange 4377
273 lange 3831 if [ $do_init_tasks -eq 1 ]; then
274 lange 4756 # we are running an initial installation
275     export LOGDIR=/tmp/fai
276 lange 4773 mkdir -p $LOGDIR
277 lange 4756 else
278 lange 4761 export fai_rundate=$(date +'%Y%m%d_%H%M%S')
279 lange 4756 export LOGDIR=/var/log/fai/$HOSTNAME/$action-$fai_rundate
280 lange 4773 mkdir -p $LOGDIR
281 lange 4775 ln -snf $action-$fai_rundate $LOGDIR/../last-$action
282     ln -snf $action-$fai_rundate $LOGDIR/../last
283 lange 3826 fi
284 lange 4757 chown root $LOGDIR
285     chgrp adm $LOGDIR
286 lange 4765 chmod 0750 $LOGDIR
287 lange 3410
288 lange 2661 fai_init
289 lange 5351 [ -n "$newhostname" ] && echo "Hostname set to $HOSTNAME" | tee -a $LOGDIR/fai.log
290     unset newhostname
291 lange 4074 if [ X$action = Xdirinstall ]; then
292 lange 3795 skiptask confdir
293 lange 3784 export FAI=$FAI_CONFIGDIR
294 lange 3930 set -a
295 lange 3784 fi
296 lange 2661
297 lange 4806 # remove this crap, use old thing
298 lange 3691 mkfifo $LOGDIR/logfifo
299     tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &
300 lange 2661 # in bash &> redirect stdout and stderr to file
301 lange 3691 fstart &> $LOGDIR/logfifo
302     rm $LOGDIR/logfifo
303 lange 2661 sleep 1 # wait for tee to complete. One second should be ok
304     # old code
305     # {
306     # # a bash group command with { does not work on sparc
307     # task confdir
308     # task setup
309     # task defclass
310     # task defvar
311     # load_keymap_consolechars
312     # set_disk_info
313 lange 3689 # } > >( tee -a $LOGDIR/fai.log ) 2>&1
314 lange 2661
315 lange 3952 [ "$action" ] && export FAI_ACTION=$action
316 lange 3810 unset action
317 lange 3689 task action 2>&1 | tee -a $LOGDIR/fai.log
318 lange 2661
319 lange 3850 [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
320 lange 2674
321 lange 2661 echo "End of $0"

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5