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

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4319 - (show annotations) (download)
Tue Jun 12 16:50:45 2007 UTC (5 years, 11 months ago) by lange
File size: 8537 byte(s)
fix path
1 #!/bin/bash
2 # $Id$
3 #*********************************************************************
4 #
5 # fai -- main installation script executed after booting
6 #
7 # This script is part of FAI (Fully Automatic Installation)
8 # (c) 1999-2007 by Thomas Lange, lange@informatik.uni-koeln.de
9 # Universitaet zu Koeln
10 #
11 #*********************************************************************
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
21 #
22 # A copy of the GNU General Public License is available as
23 # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
24 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
25 # can also obtain it by writing to the Free Software Foundation, Inc.,
26 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #*********************************************************************
28
29 #set -xv # for full debugging
30
31 export PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
32 # some variables
33 export FAI_VERSION=FAIVERSIONSTRING
34 stamp=/var/run/fai/FAI_INSTALLATION_IN_PROGRESS
35 romountopt="-o async,noatime,nolock,ro,actimeo=1800"
36
37 export faimond=0
38 export renewclass=0
39 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40 fai_init() {
41
42 set -a # now export all variables
43
44 umask 022
45 if [ ! -d "$FAI_ETC_DIR" ]; then
46 echo "$FAI_ETC_DIR is not a directory"
47 exit 6
48 fi
49 [ -f $FAI_ETC_DIR/fai.conf ] && . $FAI_ETC_DIR/fai.conf
50
51 if [ -f /etc/RUNNING_FROM_FAICD ]; then # we are booting from fai cd
52 umount /initrd
53 romountopt=
54 FAI_DEBMIRROR="--bind /media/mirror"
55 MNTPOINT=/media/mirror
56 FAI_CONFIG_SRC="file://$FAI" # on a fai-cd the config space is already available
57 fi
58
59 # some variables from are not needed any more
60 #unset FAI_CONFIGDIR
61
62 # read subroutine definitions
63 local sub=/usr/lib/fai/subroutines
64 [ -f $sub ] && . $sub
65 [ -f $sub-linux ] && . $sub-linux
66
67 [ -f "$stamp" ] && {
68 echo "$0 already running, aborting"
69 exit 1
70 }
71
72 DEBIAN_FRONTEND=noninteractive
73 # local disks are mounted to $FAI_ROOT
74 if [ -z "$FAI_ROOT" ] ; then
75 [ $do_init_tasks -eq 1 ] && FAI_ROOT=/tmp/target || FAI_ROOT=/
76 fi
77 # executed command in the environment of the new system
78 ROOTCMD="chroot $FAI_ROOT"
79 # no chroot needed
80 [ "$FAI_ROOT" = '/' ] && ROOTCMD=
81 target=$FAI_ROOT
82
83 if [ X$action = Xdirinstall -a -n "$newhostname" ]; then
84 HOSTNAME=$newhostname
85 HOST=$newhostname
86 unset newhostname
87 echo "Hostname set to $HOST" | tee -a $LOGDIR/fai.log
88 fi
89
90 if [ $do_init_tasks -eq 1 ]; then
91 trap 'echo "Now rebooting";faireboot' INT QUIT
92 else
93 trap "echo 'Aborted';rm -f $stamp" INT QUIT
94 fi
95
96 if [ $do_init_tasks -eq 1 ]; then
97 eval_cmdline
98 # if HOST was specified on the commandline, set hostname to it
99 if [ -n "$HOST" ]; then
100 HOSTNAME=$HOST
101 hostname $HOST
102 echo "Hostname set to $HOST" | tee -a $LOGDIR/fai.log
103 fi
104
105 mount -t sysfs sysfs /sys
106 # we really need to start udev
107 [ -x /etc/init.d/udev ] && /etc/init.d/udev start
108 [ -d /var/run/network ] || mkdir /var/run/network
109 [ -d /dev/shm/network ] || mkdir /dev/shm/network # when using initrd kernels
110 ifup lo
111 [ -x /sbin/portmap ] && /sbin/portmap
112 mount -t devpts devpts /dev/pts
113 cat /proc/kmsg >/dev/tty4 &
114 fi
115
116 # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called
117 [ -z "$classes" ] && classes="DEFAULT $(uname -s | tr a-z A-Z) $HOSTNAME LAST"
118
119 prcopyleft
120
121 save_dmesg
122 }
123 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124 usage() {
125 cat <<-EOF
126 fai $FAI_VERSION. Copyright (C) 1999-2006 Thomas Lange
127 Usage: $0 [options] [action]
128
129 Options:
130 -v|--verbose display more information during the update
131 -h|--help display this help message
132 -N|--new renew list of classes
133 -c|--class comma separated list of classes
134 -C|--cfdir CFDIR Use CFDIR for reading the config files
135
136 EOF
137 exit 0
138 }
139 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
140 fstart() {
141
142 # these tasks can define variables, that are needed later
143 [ -n "$etc_message" ] && echo ""
144 echo "$etc_message"
145 [ $do_init_tasks -eq 1 ] || echo "Using configuration files from $FAI_ETC_DIR"
146 unset etc_message
147 task confdir
148 task setup
149 task defclass
150 unset cmdlineclasses renewclass
151 [ $do_init_tasks -eq 1 ] && set_disk_info
152 task defvar
153 [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
154 }
155 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156 # Main routine
157
158 # Parse commandline options
159 TEMP=$(getopt -o u:Nhvc:C: --long hostname:,new,help,verbose,class:,cfdir: -n "$0" -- "$@")
160 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
161 # Note the quotes around `$TEMP': they are essential!
162 eval set -- "$TEMP"
163 unset TEMP
164
165 while true ; do
166 case "$1" in
167 -h|--help)
168 shift
169 usage
170 ;;
171 -v|--verbose)
172 shift
173 export verbose=1
174 ;;
175 -N|--new)
176 shift
177 renewclass=1
178 ;;
179 -C|--cfdir)
180 shift
181 cfdir=$1
182 shift
183 ;;
184 -c|--class)
185
186 if [ $renewclass -eq 1 ]; then
187 echo "You can't use -c|--classes and -N|--new at the same time."
188 exit 9
189 fi
190 shift
191 export cmdlineclasses=$1
192 shift
193 cmdlineclasses=${cmdlineclasses//,/ }
194 ;;
195 -u|--hostname)
196 shift
197 export newhostname=$1
198 shift
199 ;;
200 --)
201 shift
202 break
203 ;;
204 *)
205 echo "$0: command line parsing error ! $@"
206 exit 1
207 ;;
208 esac
209 done
210
211 # 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 etc_message="Using environment variable \$FAI_ETC_DIR."
215 fi
216 [ -n "$cfdir" ] && FAI_ETC_DIR=$cfdir
217 unset cfdir
218 : ${FAI_ETC_DIR:=/etc/fai}
219 FAI_ETC_DIR=$(readlink -f $FAI_ETC_DIR) # canonicalize path
220 export FAI_ETC_DIR
221
222 # override FAI_ACTION later if a command line argument is given
223 [ "$1" ] && action=$1
224 [ "$2" ] && export FAI_ROOT=$2 # only used for dirinstall
225
226 if [ X$action = Xdirinstall ]; then
227 if [ -z "$FAI_ROOT" ]; then
228 echo "Please specify a target directory. Aborted"
229 exit 3
230 fi
231 export NFSROOT=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $NFSROOT)
232 fi
233
234 if [ $(id -u) != "0" ]; then
235 echo "Run this program as root."
236 exit 1
237 fi
238
239 # exit if we do not run from nfsroot and no parameter is given
240 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
241 echo "Please give more parameters if not run from the nfsroot."
242 exit 2
243 fi
244
245 # are we called as an init substitute ?
246 export do_init_tasks=0
247 [ "$0" = "/etc/init.d/rcS" ] && do_init_tasks=1
248 if [ $do_init_tasks -eq 1 ]; then
249 renewclass=1 # always renew class list when installing
250 fi
251 export start_seconds=$(cut -d . -f 1 /proc/uptime)
252
253 [ -d /var/run/fai ] || mkdir /var/run/fai
254 export LOGDIR=/var/log/fai/current
255 [ -d $LOGDIR ] && rm -rf $LOGDIR
256 mkdir -p $LOGDIR
257
258 # for compability, can be removed later
259 if [ $do_init_tasks -eq 1 ]; then
260 mkdir /tmp/fai
261 mount --bind $LOGDIR /tmp/fai
262 fi
263
264 fai_init
265 if [ X$action = Xdirinstall ]; then
266 skiptask confdir
267 export FAI=$FAI_CONFIGDIR
268 set -a
269 clean_exit() {
270 rm -f $stamp
271 [ -z "$FAI_ROOT" ] && return
272 [ -d $FAI_ROOT/proc/self ] && umount $FAI_ROOT/proc $FAI_ROOT/sys
273 [ -f /etc/init.d/udev ] && umount $FAI_ROOT/dev
274 }
275 trap 'clean_exit' EXIT
276 fi
277
278 mkfifo $LOGDIR/logfifo
279 tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &
280 # in bash &> redirect stdout and stderr to file
281 fstart &> $LOGDIR/logfifo
282 rm $LOGDIR/logfifo
283 sleep 1 # wait for tee to complete. One second should be ok
284 # old code
285 # {
286 # # a bash group command with { does not work on sparc
287 # task confdir
288 # task setup
289 # task defclass
290 # task defvar
291 # load_keymap_consolechars
292 # set_disk_info
293 # } > >( tee -a $LOGDIR/fai.log ) 2>&1
294
295 [ "$action" ] && export FAI_ACTION=$action
296 unset action
297 task action 2>&1 | tee -a $LOGDIR/fai.log
298
299 [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
300
301 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