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

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4117 - (hide annotations) (download)
Sun Oct 29 14:58:53 2006 UTC (6 years, 6 months ago) by lange
File size: 8663 byte(s)
start udev before creating /dev/shm/network
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 3304 # (c) 1999-2006 by Thomas Lange, lange@informatik.uni-koeln.de
9 lange 2661 # 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 lange 3850 stamp=/var/run/fai/FAI_INSTALLATION_IN_PROGRESS
35 lange 2661 romountopt="-o async,noatime,nolock,ro,actimeo=1800"
36    
37 lange 3920 export faimond=0
38 lange 3779 export renewclass=0
39 lange 2661 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40     fai_init() {
41    
42     set -a # now export all variables
43    
44     umask 022
45 lange 3875 if [ ! -d "$FAI_ETC_DIR" ]; then
46     echo "$FAI_ETC_DIR is not a directory"
47 lange 3808 exit 6
48     fi
49 lange 3875 [ -f $FAI_ETC_DIR/fai.conf ] && . $FAI_ETC_DIR/fai.conf
50 lange 2661
51     if [ -f /boot/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 lange 3912 FAI_CONFIG_SRC="file://$FAI" # on a fai-cd the config space is already available
57 lange 2661 fi
58    
59     # some variables from are not needed any more
60 lange 3784 #unset FAI_CONFIGDIR
61 lange 2661
62     # read subroutine definitions
63 lange 3714 local sub=/usr/lib/fai/subroutines
64 lange 2661 [ -f $sub ] && . $sub
65 lange 3714 [ -f $sub-linux ] && . $sub-linux
66 lange 2661
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 lange 3831 [ $do_init_tasks -eq 1 ] && FAI_ROOT=/tmp/target || FAI_ROOT=/
76 lange 2661 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 lange 3777 target=$FAI_ROOT
82 lange 2661
83 lange 4074 if [ X$action = Xdirinstall -a -n "$newhostname" ]; then
84 lange 4067 HOSTNAME=$newhostname
85     HOST=$newhostname
86     unset newhostname
87     echo "Hostname set to $HOST" | tee -a $LOGDIR/fai.log
88     fi
89    
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     # 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 lange 3708 mount -t sysfs sysfs /sys
106 lange 4117 # we really need to start udev
107     [ -x /etc/init.d/udev ] && /etc/init.d/udev start
108 lange 3814 [ -d /var/run/network ] || mkdir /var/run/network
109 lange 4082 [ -d /dev/shm/network ] || mkdir /dev/shm/network # when using initrd kernels
110 lange 3708 ifup lo
111     [ -x /sbin/portmap ] && /sbin/portmap
112     mount -t devpts devpts /dev/pts
113 lange 3777 # add other options for nfs mount of /dev/root to root-path in dhcpd.conf
114 lange 3708 mount -o remount,noatime,ro /dev/root /
115     cat /proc/kmsg >/dev/tty4 &
116 lange 2661 fi
117 lange 3409
118 lange 3777 # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called
119 lange 3851 [ -z "$classes" ] && classes="DEFAULT $(uname -s | tr a-z A-Z) $HOSTNAME LAST"
120 lange 3777
121 lange 3409 prcopyleft
122 lange 2661
123     save_dmesg
124     }
125     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126     usage() {
127 lange 2732 cat <<-EOF
128 lange 3779 fai $FAI_VERSION. Copyright (C) 1999-2006 Thomas Lange
129 lange 2732 Usage: $0 [options] [action]
130 lange 2661
131 lange 2732 Options:
132     -v|--verbose display more information during the update
133     -h|--help display this help message
134 lange 2761 -N|--new renew list of classes
135 lange 3952 -c|--class comma separated list of classes
136     -C|--cfdir CFDIR Use CFDIR for reading the config files
137 lange 3784
138 lange 2661 EOF
139     exit 0
140     }
141     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
142     fstart() {
143    
144     # these tasks can define variables, that are needed later
145 lange 3950 [ -n "$etc_message" ] && echo ""
146 lange 3949 echo "$etc_message"
147 lange 3969 [ $do_init_tasks -eq 1 ] || echo "Using configuration files from $FAI_ETC_DIR"
148 lange 3948 unset etc_message
149 lange 2661 task confdir
150     task setup
151     task defclass
152 lange 3820 unset cmdlineclasses renewclass
153 lange 3831 [ $do_init_tasks -eq 1 ] && set_disk_info
154 lange 2661 task defvar
155 lange 3831 [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
156 lange 2661 }
157     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158     # Main routine
159    
160     # Parse commandline options
161 lange 4067 TEMP=$(getopt -o u:Nhvc:C: --long new,help,verbose,class:,cfdir: -n "$0" -- "$@")
162 lange 2661 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
163     # Note the quotes around `$TEMP': they are essential!
164     eval set -- "$TEMP"
165 lange 3810 unset TEMP
166 lange 2661
167     while true ; do
168     case "$1" in
169     -h|--help)
170     shift
171     usage
172     ;;
173     -v|--verbose)
174     shift
175 lange 3779 export verbose=1
176 lange 2661 ;;
177 lange 2761 -N|--new)
178     shift
179 lange 2770 renewclass=1
180 lange 2761 ;;
181 lange 3922 -C|--cfdir)
182 lange 3808 shift
183 lange 3948 cfdir=$1
184 lange 3808 shift
185     ;;
186 lange 3922 -c|--class)
187 lange 3795
188     if [ $renewclass -eq 1 ]; then
189     echo "You can't use -c|--classes and -N|--new at the same time."
190     exit 9
191     fi
192 lange 3784 shift
193 lange 3795 export cmdlineclasses=$1
194 lange 3784 shift
195 lange 3795 cmdlineclasses=${cmdlineclasses//,/ }
196 lange 3784 ;;
197 lange 4067 -u|--hostname)
198     shift
199     export newhostname=$1
200     ;;
201 lange 2661 --)
202     shift
203     break
204     ;;
205     *)
206     echo "$0: command line parsing error ! $@"
207     exit 1
208     ;;
209     esac
210     done
211    
212 lange 3948 # use FAI_ETC_DIR from environment variable
213     if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
214     # print this message later so it gets into the log files
215 lange 3949 etc_message="Using environment variable \$FAI_ETC_DIR."
216 lange 3948 fi
217     [ -n "$cfdir" ] && FAI_ETC_DIR=$cfdir
218     unset cfdir
219     : ${FAI_ETC_DIR:=/etc/fai}
220 lange 3949 FAI_ETC_DIR=$(readlink -f $FAI_ETC_DIR) # canonicalize path
221 lange 3948 export FAI_ETC_DIR
222    
223 lange 3784 # override FAI_ACTION later if a command line argument is given
224     [ "$1" ] && action=$1
225 lange 4074 [ "$2" ] && export FAI_ROOT=$2 # only used for dirinstall
226 lange 3708
227 lange 4074 if [ X$action = Xdirinstall ]; then
228 lange 3987 if [ -z "$FAI_ROOT" ]; then
229 lange 3798 echo "Please specify a target directory. Aborted"
230     exit 3
231     fi
232 lange 3884 export NFSROOT=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $NFSROOT)
233 lange 3784 fi
234    
235 lange 3708 if [ $(id -u) != "0" ]; then
236 lange 3151 echo "Run this program as root."
237     exit 1
238     fi
239    
240 lange 3291 # exit if we do not run from nfsroot and no parameter is given
241 lange 3304 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
242 lange 3291 echo "Please give more parameters if not run from the nfsroot."
243     exit 2
244     fi
245    
246 lange 3826 # are we called as an init substitute ?
247 lange 3831 export do_init_tasks=0
248     [ "$0" = "/etc/init.d/rcS" ] && do_init_tasks=1
249     if [ $do_init_tasks -eq 1 ]; then
250 lange 3826 renewclass=1 # always renew class list when installing
251     create_ramdisk
252     fi
253     export start_seconds=$(cut -d . -f 1 /proc/uptime)
254 lange 3410
255 lange 3882 [ -d /var/run/fai ] || mkdir /var/run/fai
256 lange 3826 export LOGDIR=/var/log/fai/current
257     [ -d $LOGDIR ] && rm -rf $LOGDIR
258     mkdir -p $LOGDIR
259 lange 3519
260 lange 3826 # for compability, can be removed later
261 lange 3831 if [ $do_init_tasks -eq 1 ]; then
262 lange 3826 mkdir /tmp/fai
263     mount --bind $LOGDIR /tmp/fai
264     fi
265 lange 3410
266 lange 2661 fai_init
267 lange 4074 if [ X$action = Xdirinstall ]; then
268 lange 3795 skiptask confdir
269 lange 3784 export FAI=$FAI_CONFIGDIR
270 lange 3930 set -a
271     clean_exit() {
272     rm -f $stamp
273 lange 3987 [ -z "$FAI_ROOT" ] && return
274     [ -d $FAI_ROOT/proc/self ] && umount $FAI_ROOT/proc $FAI_ROOT/sys
275     [ -f /etc/init.d/udev ] && umount $FAI_ROOT/dev
276 lange 3930 }
277     set +a
278     trap 'clean_exit' EXIT
279 lange 3784 fi
280 lange 2661
281 lange 3691 mkfifo $LOGDIR/logfifo
282     tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &
283 lange 2661 # in bash &> redirect stdout and stderr to file
284 lange 3691 fstart &> $LOGDIR/logfifo
285     rm $LOGDIR/logfifo
286 lange 2661 sleep 1 # wait for tee to complete. One second should be ok
287     # old code
288     # {
289     # # a bash group command with { does not work on sparc
290     # task confdir
291     # task setup
292     # task defclass
293     # task defvar
294     # load_keymap_consolechars
295     # set_disk_info
296 lange 3689 # } > >( tee -a $LOGDIR/fai.log ) 2>&1
297 lange 2661
298 lange 3952 [ "$action" ] && export FAI_ACTION=$action
299 lange 3810 unset action
300 lange 3689 task action 2>&1 | tee -a $LOGDIR/fai.log
301 lange 2661
302 lange 3850 [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
303 lange 2674
304 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