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

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3850 - (hide annotations) (download)
Tue Sep 5 12:05:49 2006 UTC (6 years, 8 months ago) by lange
File size: 7647 byte(s)
replace $rundir by fixed path
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 rundir=/var/run/fai
35     stamp=/var/run/fai/FAI_INSTALLATION_IN_PROGRESS
36 lange 2661 romountopt="-o async,noatime,nolock,ro,actimeo=1800"
37    
38     # the type of operating system (linux, sunos)
39 lange 3096 oclass=$(uname -s | tr a-z A-Z)
40 lange 2661 faimond=0
41 lange 3779 export renewclass=0
42 lange 3808 cfdir=/etc/fai
43 lange 2661 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44     fai_init() {
45    
46     set -a # now export all variables
47    
48     umask 022
49 lange 3808 if [ ! -d "$cfdir" ]; then
50     echo "$cfdir is not a directory"
51     exit 6
52     fi
53     [ -f $cfdir/fai.conf ] && . $cfdir/fai.conf
54 lange 2661
55     if [ -f /boot/RUNNING_FROM_FAICD ]; then # we are booting from fai cd
56     umount /initrd
57     romountopt=
58     FAI_DEBMIRROR="--bind /media/mirror"
59     MNTPOINT=/media/mirror
60 lange 3741 FAI_CONFIG_SRC= # on a fai-cd the config space is already available
61 lange 2661 fi
62    
63     # some variables from are not needed any more
64 lange 3784 #unset FAI_CONFIGDIR
65 lange 2661
66     # read subroutine definitions
67 lange 3714 local sub=/usr/lib/fai/subroutines
68 lange 2661 [ -f $sub ] && . $sub
69 lange 3714 [ -f $sub-linux ] && . $sub-linux
70 lange 2661
71     [ -f "$stamp" ] && {
72     echo "$0 already running, aborting"
73     exit 1
74     }
75    
76     DEBIAN_FRONTEND=noninteractive
77     # local disks are mounted to $FAI_ROOT
78     if [ -z "$FAI_ROOT" ] ; then
79 lange 3831 [ $do_init_tasks -eq 1 ] && FAI_ROOT=/tmp/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     # several log files
88     diskvar=$LOGDIR/disk_var.sh
89    
90 lange 3831 if [ $do_init_tasks -eq 1 ]; then
91 lange 2661 trap 'echo "Now rebooting";faireboot' INT QUIT ;
92     else
93     trap "echo 'Aborted';rm -f $stamp" INT QUIT ;
94     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 3814 [ -d /var/run/network ] || mkdir /var/run/network
107 lange 3708 ifup lo
108     # we really need to start udev
109     [ -x /etc/init.d/udev ] && /etc/init.d/udev start
110     [ -x /sbin/portmap ] && /sbin/portmap
111     mount -t devpts devpts /dev/pts
112 lange 3777 # add other options for nfs mount of /dev/root to root-path in dhcpd.conf
113 lange 3708 mount -o remount,noatime,ro /dev/root /
114     cat /proc/kmsg >/dev/tty4 &
115 lange 2661 fi
116 lange 3409
117 lange 3777 # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called
118     [ -z "$classes" ] && classes="DEFAULT $oclass $HOSTNAME LAST"
119    
120 lange 3409 prcopyleft
121 lange 2661
122     save_dmesg
123     }
124     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125     usage() {
126 lange 2732 cat <<-EOF
127 lange 3779 fai $FAI_VERSION. Copyright (C) 1999-2006 Thomas Lange
128 lange 2732 Usage: $0 [options] [action]
129 lange 2661
130 lange 2732 Options:
131     -v|--verbose display more information during the update
132     -h|--help display this help message
133 lange 2761 -N|--new renew list of classes
134 lange 3808 -C|--class comma separated list of classes
135     -c|--cfdir CFDIR Use CFDIR for reading the config files
136 lange 3784
137 lange 2661 EOF
138     exit 0
139     }
140     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141     fstart() {
142    
143     # these tasks can define variables, that are needed later
144     task confdir
145     task setup
146     task defclass
147 lange 3820 unset cmdlineclasses renewclass
148 lange 3831 [ $do_init_tasks -eq 1 ] && set_disk_info
149 lange 2661 task defvar
150 lange 3831 [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
151 lange 2661 }
152     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153     # Main routine
154    
155     # Parse commandline options
156 lange 3808 TEMP=$(getopt -o Nhvc:C: --long new,help,verbose,class:,cfdir: -n "$0" -- "$@")
157 lange 2661 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
158     # Note the quotes around `$TEMP': they are essential!
159     eval set -- "$TEMP"
160 lange 3810 unset TEMP
161 lange 2661
162     while true ; do
163     case "$1" in
164     -h|--help)
165     shift
166     usage
167     ;;
168     -v|--verbose)
169     shift
170 lange 3779 export verbose=1
171 lange 2661 ;;
172 lange 2761 -N|--new)
173     shift
174 lange 2770 renewclass=1
175 lange 2761 ;;
176 lange 3808 -c|--cfdir)
177     shift
178     cfdir=$1
179     shift
180     ;;
181     -C|--class)
182 lange 3795
183     if [ $renewclass -eq 1 ]; then
184     echo "You can't use -c|--classes and -N|--new at the same time."
185     exit 9
186     fi
187 lange 3784 shift
188 lange 3795 export cmdlineclasses=$1
189 lange 3784 shift
190 lange 3795 cmdlineclasses=${cmdlineclasses//,/ }
191 lange 3784 ;;
192 lange 2661 --)
193     shift
194     break
195     ;;
196     *)
197     echo "$0: command line parsing error ! $@"
198     exit 1
199     ;;
200     esac
201     done
202    
203 lange 3784 # override FAI_ACTION later if a command line argument is given
204     [ "$1" ] && action=$1
205     [ "$2" ] && targetdir=$2 # only used for dirinst
206 lange 3708
207 lange 3784 if [ X$action = Xdirinst ]; then
208 lange 3798 if [ -z "$targetdir" ]; then
209     echo "Please specify a target directory. Aborted"
210     exit 3
211     fi
212    
213 lange 3820 eval $(grep NFSROOT= $cfdir/make-fai-nfsroot.conf)
214 lange 3784 export NFSROOT
215     export FAI_ROOT=$targetdir
216     fi
217    
218 lange 3708 if [ $(id -u) != "0" ]; then
219 lange 3151 echo "Run this program as root."
220     exit 1
221     fi
222    
223 lange 3291 # exit if we do not run from nfsroot and no parameter is given
224 lange 3304 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
225 lange 3291 echo "Please give more parameters if not run from the nfsroot."
226     exit 2
227     fi
228    
229 lange 3826 # are we called as an init substitute ?
230 lange 3831 export do_init_tasks=0
231     [ "$0" = "/etc/init.d/rcS" ] && do_init_tasks=1
232     if [ $do_init_tasks -eq 1 ]; then
233 lange 3826 renewclass=1 # always renew class list when installing
234     create_ramdisk
235     fi
236     export start_seconds=$(cut -d . -f 1 /proc/uptime)
237 lange 3410
238 lange 3826 export LOGDIR=/var/log/fai/current
239     [ -d $LOGDIR ] && rm -rf $LOGDIR
240     mkdir -p $LOGDIR
241 lange 3519
242 lange 3826 # for compability, can be removed later
243 lange 3831 if [ $do_init_tasks -eq 1 ]; then
244 lange 3826 mkdir /tmp/fai
245     mount --bind $LOGDIR /tmp/fai
246     fi
247 lange 3410
248 lange 2661 fai_init
249 lange 3784 if [ X$action = Xdirinst ]; then
250 lange 3795 skiptask confdir
251 lange 3784 export FAI=$FAI_CONFIGDIR
252     fi
253 lange 2661
254 lange 3691 mkfifo $LOGDIR/logfifo
255     tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &
256 lange 2661 # in bash &> redirect stdout and stderr to file
257 lange 3691 fstart &> $LOGDIR/logfifo
258     rm $LOGDIR/logfifo
259 lange 2661 sleep 1 # wait for tee to complete. One second should be ok
260    
261     # old code
262     # {
263     # # a bash group command with { does not work on sparc
264     # task confdir
265     # task setup
266     # task defclass
267     # task defvar
268     # load_keymap_consolechars
269     # set_disk_info
270 lange 3689 # } > >( tee -a $LOGDIR/fai.log ) 2>&1
271 lange 2661
272 lange 3784 [ "$action" ] && FAI_ACTION=$action
273 lange 3810 unset action
274 lange 3689 task action 2>&1 | tee -a $LOGDIR/fai.log
275 lange 2661
276 lange 3850 [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
277 lange 2674
278 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