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

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3897 - (hide annotations) (download)
Fri Sep 8 10:26:01 2006 UTC (6 years, 8 months ago) by lange
File size: 7597 byte(s)
remove varaible diskvar, use $LOGDIR/disk_var.sh instead
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     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 3741 FAI_CONFIG_SRC= # 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 3831 if [ $do_init_tasks -eq 1 ]; then
84 lange 2661 trap 'echo "Now rebooting";faireboot' INT QUIT ;
85     else
86     trap "echo 'Aborted';rm -f $stamp" INT QUIT ;
87     fi
88    
89 lange 3831 if [ $do_init_tasks -eq 1 ]; then
90 lange 3777 eval_cmdline
91     # if HOST was specified on the commandline, set hostname to it
92     if [ -n "$HOST" ]; then
93     HOSTNAME=$HOST
94     hostname $HOST
95     echo "Hostname set to $HOST" | tee -a $LOGDIR/fai.log
96     fi
97    
98 lange 3708 mount -t sysfs sysfs /sys
99 lange 3814 [ -d /var/run/network ] || mkdir /var/run/network
100 lange 3708 ifup lo
101     # we really need to start udev
102     [ -x /etc/init.d/udev ] && /etc/init.d/udev start
103     [ -x /sbin/portmap ] && /sbin/portmap
104     mount -t devpts devpts /dev/pts
105 lange 3777 # add other options for nfs mount of /dev/root to root-path in dhcpd.conf
106 lange 3708 mount -o remount,noatime,ro /dev/root /
107     cat /proc/kmsg >/dev/tty4 &
108 lange 2661 fi
109 lange 3409
110 lange 3777 # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called
111 lange 3851 [ -z "$classes" ] && classes="DEFAULT $(uname -s | tr a-z A-Z) $HOSTNAME LAST"
112 lange 3777
113 lange 3409 prcopyleft
114 lange 2661
115     save_dmesg
116     }
117     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118     usage() {
119 lange 2732 cat <<-EOF
120 lange 3779 fai $FAI_VERSION. Copyright (C) 1999-2006 Thomas Lange
121 lange 2732 Usage: $0 [options] [action]
122 lange 2661
123 lange 2732 Options:
124     -v|--verbose display more information during the update
125     -h|--help display this help message
126 lange 2761 -N|--new renew list of classes
127 lange 3808 -C|--class comma separated list of classes
128     -c|--cfdir CFDIR Use CFDIR for reading the config files
129 lange 3784
130 lange 2661 EOF
131     exit 0
132     }
133     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
134     fstart() {
135    
136     # these tasks can define variables, that are needed later
137     task confdir
138     task setup
139     task defclass
140 lange 3820 unset cmdlineclasses renewclass
141 lange 3831 [ $do_init_tasks -eq 1 ] && set_disk_info
142 lange 2661 task defvar
143 lange 3831 [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
144 lange 2661 }
145     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
146     # Main routine
147    
148 lange 3876 export FAI_ETC_DIR=/etc/fai
149 lange 2661 # Parse commandline options
150 lange 3808 TEMP=$(getopt -o Nhvc:C: --long new,help,verbose,class:,cfdir: -n "$0" -- "$@")
151 lange 2661 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
152     # Note the quotes around `$TEMP': they are essential!
153     eval set -- "$TEMP"
154 lange 3810 unset TEMP
155 lange 2661
156     while true ; do
157     case "$1" in
158     -h|--help)
159     shift
160     usage
161     ;;
162     -v|--verbose)
163     shift
164 lange 3779 export verbose=1
165 lange 2661 ;;
166 lange 2761 -N|--new)
167     shift
168 lange 2770 renewclass=1
169 lange 2761 ;;
170 lange 3808 -c|--cfdir)
171     shift
172 lange 3875 FAI_ETC_DIR=$1
173 lange 3808 shift
174     ;;
175     -C|--class)
176 lange 3795
177     if [ $renewclass -eq 1 ]; then
178     echo "You can't use -c|--classes and -N|--new at the same time."
179     exit 9
180     fi
181 lange 3784 shift
182 lange 3795 export cmdlineclasses=$1
183 lange 3784 shift
184 lange 3795 cmdlineclasses=${cmdlineclasses//,/ }
185 lange 3784 ;;
186 lange 2661 --)
187     shift
188     break
189     ;;
190     *)
191     echo "$0: command line parsing error ! $@"
192     exit 1
193     ;;
194     esac
195     done
196    
197 lange 3784 # override FAI_ACTION later if a command line argument is given
198     [ "$1" ] && action=$1
199     [ "$2" ] && targetdir=$2 # only used for dirinst
200 lange 3708
201 lange 3784 if [ X$action = Xdirinst ]; then
202 lange 3798 if [ -z "$targetdir" ]; then
203     echo "Please specify a target directory. Aborted"
204     exit 3
205     fi
206 lange 3884 export NFSROOT=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $NFSROOT)
207 lange 3784 export FAI_ROOT=$targetdir
208     fi
209    
210 lange 3708 if [ $(id -u) != "0" ]; then
211 lange 3151 echo "Run this program as root."
212     exit 1
213     fi
214    
215 lange 3291 # exit if we do not run from nfsroot and no parameter is given
216 lange 3304 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
217 lange 3291 echo "Please give more parameters if not run from the nfsroot."
218     exit 2
219     fi
220    
221 lange 3826 # are we called as an init substitute ?
222 lange 3831 export do_init_tasks=0
223     [ "$0" = "/etc/init.d/rcS" ] && do_init_tasks=1
224     if [ $do_init_tasks -eq 1 ]; then
225 lange 3826 renewclass=1 # always renew class list when installing
226     create_ramdisk
227     fi
228     export start_seconds=$(cut -d . -f 1 /proc/uptime)
229 lange 3410
230 lange 3882 [ -d /var/run/fai ] || mkdir /var/run/fai
231 lange 3826 export LOGDIR=/var/log/fai/current
232     [ -d $LOGDIR ] && rm -rf $LOGDIR
233     mkdir -p $LOGDIR
234 lange 3519
235 lange 3826 # for compability, can be removed later
236 lange 3831 if [ $do_init_tasks -eq 1 ]; then
237 lange 3826 mkdir /tmp/fai
238     mount --bind $LOGDIR /tmp/fai
239     fi
240 lange 3410
241 lange 2661 fai_init
242 lange 3784 if [ X$action = Xdirinst ]; then
243 lange 3795 skiptask confdir
244 lange 3784 export FAI=$FAI_CONFIGDIR
245     fi
246 lange 2661
247 lange 3691 mkfifo $LOGDIR/logfifo
248     tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &
249 lange 2661 # in bash &> redirect stdout and stderr to file
250 lange 3691 fstart &> $LOGDIR/logfifo
251     rm $LOGDIR/logfifo
252 lange 2661 sleep 1 # wait for tee to complete. One second should be ok
253    
254     # old code
255     # {
256     # # a bash group command with { does not work on sparc
257     # task confdir
258     # task setup
259     # task defclass
260     # task defvar
261     # load_keymap_consolechars
262     # set_disk_info
263 lange 3689 # } > >( tee -a $LOGDIR/fai.log ) 2>&1
264 lange 2661
265 lange 3784 [ "$action" ] && FAI_ACTION=$action
266 lange 3810 unset action
267 lange 3689 task action 2>&1 | tee -a $LOGDIR/fai.log
268 lange 2661
269 lange 3850 [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
270 lange 2674
271 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