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

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5335 - (hide annotations) (download)
Thu Apr 16 13:07:16 2009 UTC (4 years, 1 month ago) by lange
File size: 9733 byte(s)
in a file called class/*.var (closes: #515139),
create /var/run/fai (closes: #515775)
* fai-client.dirs, fai-server.dirs: remove /var/run/fai
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 2661
122 lange 2732 Options:
123     -v|--verbose display more information during the update
124     -h|--help display this help message
125 lange 2761 -N|--new renew list of classes
126 lange 3952 -c|--class comma separated list of classes
127     -C|--cfdir CFDIR Use CFDIR for reading the config files
128 lange 3784
129 lange 2661 EOF
130     exit 0
131     }
132     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
133     fstart() {
134    
135     # these tasks can define variables, that are needed later
136 lange 3950 [ -n "$etc_message" ] && echo ""
137 lange 3949 echo "$etc_message"
138 lange 3969 [ $do_init_tasks -eq 1 ] || echo "Using configuration files from $FAI_ETC_DIR"
139 lange 3948 unset etc_message
140 lange 2661 task confdir
141     task setup
142     task defclass
143 lange 3820 unset cmdlineclasses renewclass
144 lange 3831 [ $do_init_tasks -eq 1 ] && set_disk_info
145 lange 2661 task defvar
146 lange 3831 [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
147 lange 2661 }
148     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
149     # Main routine
150    
151     # Parse commandline options
152 lange 4213 TEMP=$(getopt -o u:Nhvc:C: --long hostname:,new,help,verbose,class:,cfdir: -n "$0" -- "$@")
153 lange 2661 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
154     # Note the quotes around `$TEMP': they are essential!
155     eval set -- "$TEMP"
156 lange 3810 unset TEMP
157 lange 2661
158     while true ; do
159     case "$1" in
160     -h|--help)
161     shift
162     usage
163     ;;
164     -v|--verbose)
165     shift
166 lange 3779 export verbose=1
167 lange 2661 ;;
168 lange 2761 -N|--new)
169     shift
170 lange 2770 renewclass=1
171 lange 2761 ;;
172 lange 3922 -C|--cfdir)
173 lange 3808 shift
174 lange 3948 cfdir=$1
175 lange 3808 shift
176     ;;
177 lange 3922 -c|--class)
178 lange 3795
179     if [ $renewclass -eq 1 ]; then
180     echo "You can't use -c|--classes and -N|--new at the same time."
181     exit 9
182     fi
183 lange 3784 shift
184 lange 3795 export cmdlineclasses=$1
185 lange 3784 shift
186 lange 3795 cmdlineclasses=${cmdlineclasses//,/ }
187 lange 3784 ;;
188 lange 4067 -u|--hostname)
189     shift
190     export newhostname=$1
191 lange 4200 shift
192 lange 4067 ;;
193 lange 2661 --)
194     shift
195     break
196     ;;
197     *)
198     echo "$0: command line parsing error ! $@"
199     exit 1
200     ;;
201     esac
202     done
203    
204 lange 3948 # use FAI_ETC_DIR from environment variable
205     if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
206     # print this message later so it gets into the log files
207 lange 3949 etc_message="Using environment variable \$FAI_ETC_DIR."
208 lange 3948 fi
209     [ -n "$cfdir" ] && FAI_ETC_DIR=$cfdir
210     unset cfdir
211     : ${FAI_ETC_DIR:=/etc/fai}
212 lange 3949 FAI_ETC_DIR=$(readlink -f $FAI_ETC_DIR) # canonicalize path
213 lange 3948 export FAI_ETC_DIR
214    
215 lange 3784 # override FAI_ACTION later if a command line argument is given
216 lange 4374 [ "$1" ] && export action=$1
217 lange 4074 [ "$2" ] && export FAI_ROOT=$2 # only used for dirinstall
218 lange 3708
219 lange 4074 if [ X$action = Xdirinstall ]; then
220 lange 3987 if [ -z "$FAI_ROOT" ]; then
221 lange 3798 echo "Please specify a target directory. Aborted"
222     exit 3
223     fi
224 lange 4492 if [ $renewclass -eq 0 -a -z "$cmdlineclasses" ]; then
225     echo "Please use -c or -N. Aborted"
226     exit 4
227     fi
228    
229 lange 4900 # two lines taken from task_dirinstall
230     mkdir -p $FAI_ROOT
231     FAI_ROOT=$(cd $FAI_ROOT;pwd)
232    
233 lange 4815 # check if target directory is mounted with bad options
234 lange 4900 fs=$(df $FAI_ROOT | tail -1 | awk '{print $6}')
235     if mount | grep "on $fs " | awk '{print $6}' | egrep -q "nosuid|nodev"; then
236 holger 4896 echo "Target directory is mounted using nosuid or nodev. Aborting"
237 lange 4815 exit 5
238     fi
239 lange 4900 unset fs
240 lange 4492
241 lange 3884 export NFSROOT=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $NFSROOT)
242 lange 4389 export FAI_DEBOOTSTRAP=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_DEBOOTSTRAP)
243 lange 4689 export FAI_DEBOOTSTRAP_OPTS=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_DEBOOTSTRAP_OPTS)
244 lange 4389
245 lange 3784 fi
246    
247 lange 3708 if [ $(id -u) != "0" ]; then
248 lange 3151 echo "Run this program as root."
249     exit 1
250     fi
251    
252 lange 3291 # exit if we do not run from nfsroot and no parameter is given
253 lange 3304 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
254 lange 3291 echo "Please give more parameters if not run from the nfsroot."
255     exit 2
256     fi
257    
258 lange 3826 # are we called as an init substitute ?
259 lange 3831 export do_init_tasks=0
260     [ "$0" = "/etc/init.d/rcS" ] && do_init_tasks=1
261     if [ $do_init_tasks -eq 1 ]; then
262 lange 4344 hostname $HOSTNAME
263 lange 3826 renewclass=1 # always renew class list when installing
264 lange 4447 mkdir -p /var/lib/discover /var/discover /etc/sysconfig
265 lange 3826 fi
266 lange 4811
267     [ -f /proc/version ] || mount -n -t proc proc /proc # ubuntu initrd does not mount /proc
268 lange 3826 export start_seconds=$(cut -d . -f 1 /proc/uptime)
269 lange 3410
270 lange 4377 if [ X$action = Xdirinstall -a -n "$newhostname" ]; then
271 lange 4384 export HOSTNAME=$newhostname
272 lange 4377 fi
273    
274 lange 3831 if [ $do_init_tasks -eq 1 ]; then
275 lange 4756 # we are running an initial installation
276     export LOGDIR=/tmp/fai
277 lange 4773 mkdir -p $LOGDIR
278 lange 4756 else
279 lange 4761 export fai_rundate=$(date +'%Y%m%d_%H%M%S')
280 lange 4756 export LOGDIR=/var/log/fai/$HOSTNAME/$action-$fai_rundate
281 lange 4773 mkdir -p $LOGDIR
282 lange 4775 ln -snf $action-$fai_rundate $LOGDIR/../last-$action
283     ln -snf $action-$fai_rundate $LOGDIR/../last
284 lange 3826 fi
285 lange 4757 chown root $LOGDIR
286     chgrp adm $LOGDIR
287 lange 4765 chmod 0750 $LOGDIR
288 lange 3410
289 lange 2661 fai_init
290 lange 4074 if [ X$action = Xdirinstall ]; then
291 lange 4377 [ -n "$newhostname" ] && echo "Hostname set to $HOSTNAME" | tee -a $LOGDIR/fai.log
292     unset newhostname
293 lange 3795 skiptask confdir
294 lange 3784 export FAI=$FAI_CONFIGDIR
295 lange 3930 set -a
296     clean_exit() {
297     rm -f $stamp
298 lange 3987 [ -z "$FAI_ROOT" ] && return
299     [ -d $FAI_ROOT/proc/self ] && umount $FAI_ROOT/proc $FAI_ROOT/sys
300 lange 5240 umount $FAI_ROOT/dev/pts 2>/dev/null || true
301 lange 3987 [ -f /etc/init.d/udev ] && umount $FAI_ROOT/dev
302 lange 3930 }
303     trap 'clean_exit' EXIT
304 lange 3784 fi
305 lange 2661
306 lange 4806 # remove this crap, use old thing
307 lange 3691 mkfifo $LOGDIR/logfifo
308     tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &
309 lange 2661 # in bash &> redirect stdout and stderr to file
310 lange 3691 fstart &> $LOGDIR/logfifo
311     rm $LOGDIR/logfifo
312 lange 2661 sleep 1 # wait for tee to complete. One second should be ok
313     # old code
314     # {
315     # # a bash group command with { does not work on sparc
316     # task confdir
317     # task setup
318     # task defclass
319     # task defvar
320     # load_keymap_consolechars
321     # set_disk_info
322 lange 3689 # } > >( tee -a $LOGDIR/fai.log ) 2>&1
323 lange 2661
324 lange 3952 [ "$action" ] && export FAI_ACTION=$action
325 lange 3810 unset action
326 lange 3689 task action 2>&1 | tee -a $LOGDIR/fai.log
327 lange 2661
328 lange 3850 [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
329 lange 2674
330 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