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

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5543 - (hide annotations) (download)
Fri Oct 16 13:20:41 2009 UTC (3 years, 7 months ago) by lange
File size: 9959 byte(s)
get-config-dir, fai: set FAI to local path, if FAI_CONFIG_SRC is of
type file: (closes: #481137)
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 5451 [ -n "$cspace" ] && FAI_CONFIG_SRC=$cspace
56     unset cspace
57 lange 2661
58 lange 4319 if [ -f /etc/RUNNING_FROM_FAICD ]; then # we are booting from fai cd
59 lange 2661 umount /initrd
60     romountopt=
61     FAI_DEBMIRROR="--bind /media/mirror"
62     MNTPOINT=/media/mirror
63 lange 3912 FAI_CONFIG_SRC="file://$FAI" # on a fai-cd the config space is already available
64 lange 2661 fi
65    
66     # read subroutine definitions
67 lange 5516 . /usr/lib/fai/subroutines
68 lange 2661
69     [ -f "$stamp" ] && {
70 lange 4710 echo -n "$0 already running or was aborted before. PID: "
71     cat $stamp
72 lange 4565 echo "You may remove $stamp and try again."
73 lange 2661 exit 1
74     }
75    
76     DEBIAN_FRONTEND=noninteractive
77     # local disks are mounted to $FAI_ROOT
78     if [ -z "$FAI_ROOT" ] ; then
79 lange 4512 [ $do_init_tasks -eq 1 ] && FAI_ROOT=/target || FAI_ROOT=/
80 lange 2661 fi
81     # executed command in the environment of the new system
82     ROOTCMD="chroot $FAI_ROOT"
83     # no chroot needed
84     [ "$FAI_ROOT" = '/' ] && ROOTCMD=
85 lange 3777 target=$FAI_ROOT
86 lange 2661
87 lange 3831 if [ $do_init_tasks -eq 1 ]; then
88 lange 3930 trap 'echo "Now rebooting";faireboot' INT QUIT
89 lange 2661 else
90 lange 3930 trap "echo 'Aborted';rm -f $stamp" INT QUIT
91 lange 2661 fi
92    
93 lange 3831 if [ $do_init_tasks -eq 1 ]; then
94 lange 3777 eval_cmdline
95 lange 3708 mount -t sysfs sysfs /sys
96 lange 4117 # we really need to start udev
97     [ -x /etc/init.d/udev ] && /etc/init.d/udev start
98 lange 5518 mkdir -p /var/run/network /dev/shm/network # when using initrd kernels
99 lange 3708 ifup lo
100     [ -x /sbin/portmap ] && /sbin/portmap
101     mount -t devpts devpts /dev/pts
102     cat /proc/kmsg >/dev/tty4 &
103 lange 2661 fi
104 lange 3409
105 lange 3777 # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called
106 lange 3851 [ -z "$classes" ] && classes="DEFAULT $(uname -s | tr a-z A-Z) $HOSTNAME LAST"
107 lange 3777
108 lange 3409 prcopyleft
109 lange 2661
110 lange 4375 [ $do_init_tasks -eq 1 ] && save_dmesg
111 lange 2661 }
112     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113     usage() {
114 lange 2732 cat <<-EOF
115 lange 5240 fai $FAI_VERSION. Copyright (C) 1999-2009 Thomas Lange
116 lange 2732 Usage: $0 [options] [action]
117 lange 5351
118 lange 2732 Options:
119 lange 5351 -v|--verbose display more information during the update
120     -h|--help display this help message
121     -N|--new renew list of classes
122     -c|--class comma separated list of classes
123     -C|--cfdir CFDIR Use CFDIR for reading the config files
124 lange 5532 -u|--hostname HNAME set hostname to be used
125 lange 3784
126 lange 2661 EOF
127     exit 0
128     }
129     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130     fstart() {
131    
132     # these tasks can define variables, that are needed later
133 lange 3950 [ -n "$etc_message" ] && echo ""
134 lange 3949 echo "$etc_message"
135 lange 3969 [ $do_init_tasks -eq 1 ] || echo "Using configuration files from $FAI_ETC_DIR"
136 lange 3948 unset etc_message
137 lange 2661 task confdir
138 lange 5543 # if the config space is a local directory, reset $FAI
139     local method=$(expr match "$FAI_CONFIG_SRC" '\([^+]*\).*://')
140     if [ $method = "file" ]; then
141     local localpath=$(expr match "$FAI_CONFIG_SRC" '.*://\(/.*\)')
142     export FAI=$localpath
143     fi
144 lange 2661 task setup
145     task defclass
146 lange 3820 unset cmdlineclasses renewclass
147 lange 3831 [ $do_init_tasks -eq 1 ] && set_disk_info
148 lange 2661 task defvar
149 lange 3831 [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
150 lange 2661 }
151     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152     # Main routine
153    
154     # Parse commandline options
155 lange 5451 TEMP=$(getopt -o su:Nhvc:C: --long cspace:,hostname:,new,help,verbose,class:,cfdir: -n "$0" -- "$@")
156 lange 2661 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
157     # Note the quotes around `$TEMP': they are essential!
158     eval set -- "$TEMP"
159 lange 3810 unset TEMP
160 lange 2661
161     while true ; do
162     case "$1" in
163     -h|--help)
164     shift
165     usage
166     ;;
167     -v|--verbose)
168     shift
169 lange 3779 export verbose=1
170 lange 2661 ;;
171 lange 2761 -N|--new)
172     shift
173 lange 2770 renewclass=1
174 lange 2761 ;;
175 lange 3922 -C|--cfdir)
176 lange 3808 shift
177 lange 3948 cfdir=$1
178 lange 3808 shift
179     ;;
180 lange 3922 -c|--class)
181 lange 3795
182     if [ $renewclass -eq 1 ]; then
183     echo "You can't use -c|--classes and -N|--new at the same time."
184     exit 9
185     fi
186 lange 3784 shift
187 lange 3795 export cmdlineclasses=$1
188 lange 3784 shift
189 lange 3795 cmdlineclasses=${cmdlineclasses//,/ }
190 lange 3784 ;;
191 lange 5451 -s|--cspace)
192     shift
193     cspace=$1
194     ;;
195 lange 4067 -u|--hostname)
196     shift
197     export newhostname=$1
198 lange 4200 shift
199 lange 4067 ;;
200 lange 2661 --)
201     shift
202     break
203     ;;
204     *)
205     echo "$0: command line parsing error ! $@"
206     exit 1
207     ;;
208     esac
209     done
210    
211 lange 3948 # use FAI_ETC_DIR from environment variable
212     if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
213     # print this message later so it gets into the log files
214 lange 3949 etc_message="Using environment variable \$FAI_ETC_DIR."
215 lange 3948 fi
216     [ -n "$cfdir" ] && FAI_ETC_DIR=$cfdir
217     unset cfdir
218     : ${FAI_ETC_DIR:=/etc/fai}
219 lange 3949 FAI_ETC_DIR=$(readlink -f $FAI_ETC_DIR) # canonicalize path
220 lange 3948 export FAI_ETC_DIR
221    
222 lange 3784 # override FAI_ACTION later if a command line argument is given
223 lange 4374 [ "$1" ] && export action=$1
224 lange 4074 [ "$2" ] && export FAI_ROOT=$2 # only used for dirinstall
225 lange 3708
226 lange 4074 if [ X$action = Xdirinstall ]; then
227 lange 3987 if [ -z "$FAI_ROOT" ]; then
228 lange 3798 echo "Please specify a target directory. Aborted"
229     exit 3
230     fi
231 lange 4492 if [ $renewclass -eq 0 -a -z "$cmdlineclasses" ]; then
232     echo "Please use -c or -N. Aborted"
233     exit 4
234     fi
235    
236 lange 4900 # two lines taken from task_dirinstall
237     mkdir -p $FAI_ROOT
238     FAI_ROOT=$(cd $FAI_ROOT;pwd)
239    
240 lange 4815 # check if target directory is mounted with bad options
241 lange 4900 fs=$(df $FAI_ROOT | tail -1 | awk '{print $6}')
242     if mount | grep "on $fs " | awk '{print $6}' | egrep -q "nosuid|nodev"; then
243 holger 4896 echo "Target directory is mounted using nosuid or nodev. Aborting"
244 lange 4815 exit 5
245     fi
246 lange 4900 unset fs
247 lange 4492
248 lange 3884 export NFSROOT=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $NFSROOT)
249 lange 4389 export FAI_DEBOOTSTRAP=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_DEBOOTSTRAP)
250 lange 4689 export FAI_DEBOOTSTRAP_OPTS=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_DEBOOTSTRAP_OPTS)
251 lange 4389
252 lange 3784 fi
253    
254 lange 3708 if [ $(id -u) != "0" ]; then
255 lange 3151 echo "Run this program as root."
256     exit 1
257     fi
258    
259 lange 3291 # exit if we do not run from nfsroot and no parameter is given
260 lange 3304 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
261 lange 3291 echo "Please give more parameters if not run from the nfsroot."
262     exit 2
263     fi
264    
265 lange 3826 # are we called as an init substitute ?
266 lange 3831 export do_init_tasks=0
267     [ "$0" = "/etc/init.d/rcS" ] && do_init_tasks=1
268     if [ $do_init_tasks -eq 1 ]; then
269 lange 4344 hostname $HOSTNAME
270 lange 3826 renewclass=1 # always renew class list when installing
271 lange 4447 mkdir -p /var/lib/discover /var/discover /etc/sysconfig
272 lange 3826 fi
273 lange 4811
274     [ -f /proc/version ] || mount -n -t proc proc /proc # ubuntu initrd does not mount /proc
275 lange 3826 export start_seconds=$(cut -d . -f 1 /proc/uptime)
276 lange 3410
277 lange 5351 [ -n "$newhostname" ] && export HOSTNAME=$newhostname
278 lange 4377
279 lange 3831 if [ $do_init_tasks -eq 1 ]; then
280 lange 4756 # we are running an initial installation
281     export LOGDIR=/tmp/fai
282 lange 4773 mkdir -p $LOGDIR
283 lange 4756 else
284 lange 4761 export fai_rundate=$(date +'%Y%m%d_%H%M%S')
285 lange 4756 export LOGDIR=/var/log/fai/$HOSTNAME/$action-$fai_rundate
286 lange 4773 mkdir -p $LOGDIR
287 lange 4775 ln -snf $action-$fai_rundate $LOGDIR/../last-$action
288     ln -snf $action-$fai_rundate $LOGDIR/../last
289 lange 3826 fi
290 lange 4757 chown root $LOGDIR
291     chgrp adm $LOGDIR
292 lange 4765 chmod 0750 $LOGDIR
293 lange 3410
294 lange 2661 fai_init
295 lange 5351 [ -n "$newhostname" ] && echo "Hostname set to $HOSTNAME" | tee -a $LOGDIR/fai.log
296     unset newhostname
297 lange 4074 if [ X$action = Xdirinstall ]; then
298 lange 3795 skiptask confdir
299 lange 5452 # dirinstall still uses FAI_CONFIGDIR, which is wrong IMO. It
300 lange 5450 # should use FAI_CONFIG_SRC
301     FAI_CONFIGDIR=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_CONFIGDIR)
302 lange 3784 export FAI=$FAI_CONFIGDIR
303 lange 5452 # TODO: add a check here if we have a lcoation/URL for the config space
304 lange 3930 set -a
305 lange 3784 fi
306 lange 2661
307 lange 4806 # remove this crap, use old thing
308 lange 3691 mkfifo $LOGDIR/logfifo
309     tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &
310 lange 2661 # in bash &> redirect stdout and stderr to file
311 lange 3691 fstart &> $LOGDIR/logfifo
312     rm $LOGDIR/logfifo
313 lange 2661 sleep 1 # wait for tee to complete. One second should be ok
314     # old code
315     # {
316     # # a bash group command with { does not work on sparc
317     # task confdir
318     # task setup
319     # task defclass
320     # task defvar
321     # load_keymap_consolechars
322     # set_disk_info
323 lange 3689 # } > >( tee -a $LOGDIR/fai.log ) 2>&1
324 lange 2661
325 lange 3952 [ "$action" ] && export FAI_ACTION=$action
326 lange 3810 unset action
327 lange 3689 task action 2>&1 | tee -a $LOGDIR/fai.log
328 lange 2661
329 lange 3850 [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
330 lange 2674
331 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