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

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3520 - (show annotations) (download)
Tue Jun 13 17:15:04 2006 UTC (7 years ago) by lange
File size: 7108 byte(s)
fix error
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-2006 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 rundir=/var/run/fai
35 stamp=$rundir/FAI_INSTALLATION_IN_PROGRESS
36 romountopt="-o async,noatime,nolock,ro,actimeo=1800"
37 fstab=fstab # Solaris uses vfstab
38
39 # the type of operating system (linux, sunos)
40 oclass=$(uname -s | tr a-z A-Z)
41 # $classes is now set so we can call hooks before fai-class defines the classes
42 classes="DEFAULT $oclass $HOSTNAME LAST"
43 faimond=0
44 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45 fai_init() {
46
47 local sub ostype
48 set -a # now export all variables
49
50 umask 022
51 # read fai.conf
52 # linux dir
53 [ -f /etc/fai/fai.conf ] && . /etc/fai/fai.conf
54 # solaris dir
55 [ -f /tmp/install_config/fai/fai.conf ] && . /tmp/install_config/fai/fai.conf
56
57 if [ -f /boot/RUNNING_FROM_FAICD ]; then # we are booting from fai cd
58 umount /initrd
59 romountopt=
60 FAI_DEBMIRROR="--bind /media/mirror"
61 MNTPOINT=/media/mirror
62 FAI_LOCATION=
63 fi
64
65 # some variables from are not needed any more
66 unset FAI_CONFIGDIR installserver
67
68 ostype=$(uname -s | tr A-Z a-z)
69 # read subroutine definitions
70 sub=/usr/lib/fai/subroutines
71 [ -f $sub ] && . $sub
72 [ -f $sub-$ostype ] && . $sub-$ostype
73
74 [ -f "$stamp" ] && {
75 echo "$0 already running, aborting"
76 exit 1
77 }
78
79 DEBIAN_FRONTEND=noninteractive
80 # local disks are mounted to $FAI_ROOT
81 if [ -z "$FAI_ROOT" ] ; then
82 [ $DO_INIT_TASKS -eq 1 ] && FAI_ROOT=/tmp/target || FAI_ROOT=/
83 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
89 # several log files
90 diskvar=$LOGDIR/disk_var.sh
91 rcslog=$LOGDIR/fai.log
92
93 # variables for cfengine
94 files=$FAI/files
95 target=$FAI_ROOT
96
97 if [ $DO_INIT_TASKS -eq 1 ]; then
98 trap 'echo "Now rebooting";faireboot' INT QUIT ;
99 else
100 trap "echo 'Aborted';rm -f $stamp" INT QUIT ;
101 fi
102
103 # if HOST was specified on the commandline, set hostname to it
104 [ $DO_INIT_TASKS -eq 1 ] && eval_cmdline
105 if [ -n "$HOST" ]; then
106 HOSTNAME=$HOST
107 hostname $HOST
108 echo "Hostname set to $HOST" | tee -a $rcslog
109 sleep 3
110 fi
111 export HOSTNAME
112
113 if [ X$oclass = XLINUX ]; then
114 if [ $DO_INIT_TASKS -eq 1 ]; then
115 grep -q '[[:space:]]sysfs' /proc/filesystems && mount -t sysfs sysfs /sys
116 ifup lo
117 [ -x /etc/init.d/udev ] && /etc/init.d/udev start
118 [ -x /sbin/portmap ] && /sbin/portmap
119 mount -t devpts devpts /dev/pts
120 # add other options for nfs mount of /dev/root to root-path in dhcpd.conf
121 mount -o remount,noatime,ro /dev/root /
122 cat /proc/kmsg >/dev/tty4 &
123 fi
124 fi
125
126 prcopyleft
127 unset oclass
128
129 save_dmesg
130 }
131 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
132 usage() {
133 cat <<-EOF
134 fai $FAI_VERSION. Copyright (C) 1999-2005 Thomas Lange
135 Usage: $0 [options] [action]
136
137 Options:
138 -v|--verbose display more information during the update
139 -h|--help display this help message
140 -N|--new renew list of classes
141 EOF
142 exit 0
143 }
144 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145 fstart() {
146
147 # these tasks can define variables, that are needed later
148 task confdir
149 task setup
150 task defclass
151 set_disk_info
152 task defvar
153 [ $DO_INIT_TASKS -eq 1 ] && load_keymap_consolechars
154 }
155 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156 # Main routine
157
158 export renewclass=0
159 # Parse commandline options
160 TEMP=$(getopt -o Nhv --long new,help,verbose -n "$0" -- "$@")
161 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
162 # Note the quotes around `$TEMP': they are essential!
163 eval set -- "$TEMP"
164
165 while true ; do
166 case "$1" in
167 -h|--help)
168 shift
169 usage
170 ;;
171 -v|--verbose)
172 shift
173 verbose=1
174 ;;
175 -N|--new)
176 shift
177 renewclass=1
178 ;;
179 --)
180 shift
181 break
182 ;;
183 *)
184 echo "$0: command line parsing error ! $@"
185 exit 1
186 ;;
187 esac
188 done
189
190 if [ `id -u` -ne 0 ]; then
191 echo "Run this program as root."
192 exit 1
193 fi
194
195 # exit if we do not run from nfsroot and no parameter is given
196 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
197 echo "Please give more parameters if not run from the nfsroot."
198 exit 2
199 fi
200
201 # HG: are we called as an init substitute ?
202 export DO_INIT_TASKS=0
203 [ "$0" = "/etc/init.d/rcS" ] && DO_INIT_TASKS=1
204 [ $DO_INIT_TASKS -eq 1 ] && renewclass=1 # always renew class list when installing
205
206 # Solaris has already a writable /tmp directory
207 [ "$oclass" = LINUX -a $DO_INIT_TASKS -eq 1 ] && create_ramdisk
208
209 export LOGDIR=/var/log/fai/current
210 mkdir -p $LOGDIR
211
212 # for compability, can be removed later
213 if [ $DO_INIT_TASKS -eq 1 ]; then
214 mkdir /tmp/fai
215 mount --bind /var/log/fai/current /tmp/fai
216 fi
217
218 fai_init
219
220 lpipe=$LOGDIR/logfifo
221 mkfifo $lpipe
222 tee -a $rcslog < $lpipe &
223 # in bash &> redirect stdout and stderr to file
224 fstart &> $lpipe
225 rm $lpipe
226 unset lpipe
227 sleep 1 # wait for tee to complete. One second should be ok
228
229 # old code
230 # {
231 # # a bash group command with { does not work on sparc
232 # task confdir
233 # task setup
234 # task defclass
235 # task defvar
236 # load_keymap_consolechars
237 # set_disk_info
238 # } > >( tee -a $rcslog ) 2>&1
239
240 # override FAI_ACTION if a command line argument is given
241 [ "$1" ] && FAI_ACTION=$1
242 [ "$2" ] && targetdir=$2 # only used for dirinst
243
244 task action 2>&1 | tee -a $rcslog
245
246 # not happy with this at all!
247 [ "$FAI_CVSROOT" ] && rm -rf $FAI
248
249 [ -L "$rundir/current_log" ] && rm -f "$rundir/current_log"
250 [ -L "$rundir/current_config" ] && rm -f "$rundir/current_config"
251
252 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