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

Contents of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6737 - (hide annotations) (download)
Sat Oct 22 22:27:09 2011 UTC (19 months ago) by lange
File size: 9878 byte(s)
use default value for FAI_LOGPROTO
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 6608 # (c) 1999-2011 by Thomas Lange, lange@informatik.uni-koeln.de
9 lange 2661 # Universitaet zu Koeln
10 lange 5018 # (c) 2001-2005 by Henning Glawe, glaweh@physik.fu-berlin.de
11     # Freie Universitaet Berlin
12 lange 2661 #
13     #*********************************************************************
14     # This program is free software; you can redistribute it and/or modify
15     # it under the terms of the GNU General Public License as published by
16     # the Free Software Foundation; either version 2 of the License, or
17     # (at your option) any later version.
18     #
19     # This program is distributed in the hope that it will be useful, but
20     # WITHOUT ANY WARRANTY; without even the implied warranty of
21     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22     # General Public License for more details.
23     #
24     # A copy of the GNU General Public License is available as
25     # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
26     # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
27     # can also obtain it by writing to the Free Software Foundation, Inc.,
28 lange 4677 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29 lange 2661 #*********************************************************************
30    
31     #set -xv # for full debugging
32    
33 lange 5583 export PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/usr/sbin:/usr/bin:/sbin:/bin
34 lange 2661 # some variables
35     export FAI_VERSION=FAIVERSIONSTRING
36 lange 3850 stamp=/var/run/fai/FAI_INSTALLATION_IN_PROGRESS
37 lange 4655 export romountopt="-o async,noatime,nolock,ro,actimeo=1800"
38 lange 2661
39 lange 5332 export STOP_ON_ERROR=700
40 lange 3920 export faimond=0
41 lange 3779 export renewclass=0
42 lange 2661 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43     fai_init() {
44    
45     set -a # now export all variables
46 lange 4684 set -o pipefail
47 lange 2661
48     umask 022
49 lange 5335 mkdir -p /var/run/fai
50 lange 3875 [ -f $FAI_ETC_DIR/fai.conf ] && . $FAI_ETC_DIR/fai.conf
51 lange 6607 : ${FAI:=/var/lib/fai/config} # default value
52 lange 6608 : ${MNTPOINT:=/media/mirror} # default value
53 lange 6737 : ${FAI_LOGPROTO:=ssh} # default value
54 lange 5451 [ -n "$cspace" ] && FAI_CONFIG_SRC=$cspace
55     unset cspace
56 lange 2661
57 lange 4319 if [ -f /etc/RUNNING_FROM_FAICD ]; then # we are booting from fai cd
58 lange 2661 umount /initrd
59     romountopt=
60     FAI_DEBMIRROR="--bind /media/mirror"
61     MNTPOINT=/media/mirror
62 lange 3912 FAI_CONFIG_SRC="file://$FAI" # on a fai-cd the config space is already available
63 lange 2661 fi
64    
65     # read subroutine definitions
66 lange 5516 . /usr/lib/fai/subroutines
67 lange 2661
68     [ -f "$stamp" ] && {
69 lange 4710 echo -n "$0 already running or was aborted before. PID: "
70     cat $stamp
71 lange 4565 echo "You may remove $stamp and try again."
72 lange 2661 exit 1
73     }
74    
75     DEBIAN_FRONTEND=noninteractive
76     # local disks are mounted to $FAI_ROOT
77     if [ -z "$FAI_ROOT" ] ; then
78 lange 4512 [ $do_init_tasks -eq 1 ] && FAI_ROOT=/target || FAI_ROOT=/
79 lange 2661 fi
80     # executed command in the environment of the new system
81     ROOTCMD="chroot $FAI_ROOT"
82     # no chroot needed
83     [ "$FAI_ROOT" = '/' ] && ROOTCMD=
84 lange 3777 target=$FAI_ROOT
85 lange 2661
86 lange 3831 if [ $do_init_tasks -eq 1 ]; then
87 lange 3930 trap 'echo "Now rebooting";faireboot' INT QUIT
88 lange 2661 else
89 lange 3930 trap "echo 'Aborted';rm -f $stamp" INT QUIT
90 lange 2661 fi
91    
92 lange 3831 if [ $do_init_tasks -eq 1 ]; then
93 lange 3777 eval_cmdline
94 lange 5658 [ -d /sys/kernel ] || mount -t sysfs sysfs /sys
95 lange 4117 # we really need to start udev
96 lange 5658 [ -x /etc/init.d/udev ] && [ X$UPSTART_JOB != Xfai ] && /etc/init.d/udev start
97 lange 5518 mkdir -p /var/run/network /dev/shm/network # when using initrd kernels
98 lange 3708 ifup lo
99     [ -x /sbin/portmap ] && /sbin/portmap
100     mount -t devpts devpts /dev/pts
101     cat /proc/kmsg >/dev/tty4 &
102 lange 2661 fi
103 lange 3409
104 lange 3777 # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called
105 lange 3851 [ -z "$classes" ] && classes="DEFAULT $(uname -s | tr a-z A-Z) $HOSTNAME LAST"
106 lange 3777
107 lange 3409 prcopyleft
108 lange 2661
109 lange 4375 [ $do_init_tasks -eq 1 ] && save_dmesg
110 lange 2661 }
111     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112     usage() {
113 lange 2732 cat <<-EOF
114 lange 6326 fai $FAI_VERSION. Copyright (C) 1999-2011 Thomas Lange
115 lange 2732 Usage: $0 [options] [action]
116 lange 5351
117 lange 2732 Options:
118 lange 5351 -v|--verbose display more information during the update
119     -h|--help display this help message
120     -N|--new renew list of classes
121     -c|--class comma separated list of classes
122     -C|--cfdir CFDIR Use CFDIR for reading the config files
123 lange 5572 -s|--cspace CSDIR URI of the configuration space
124 lange 5532 -u|--hostname HNAME set hostname to be used
125 lange 3784
126 lange 2661 EOF
127     exit 0
128     }
129     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130     fstart() {
131    
132     # these tasks can define variables, that are needed later
133 lange 3950 [ -n "$etc_message" ] && echo ""
134 lange 3949 echo "$etc_message"
135 lange 3969 [ $do_init_tasks -eq 1 ] || echo "Using configuration files from $FAI_ETC_DIR"
136 lange 3948 unset etc_message
137 lange 2661 task confdir
138 lange 5543 # if the config space is a local directory, reset $FAI
139 lange 5570 local method=$(expr match "$FAI_CONFIG_SRC" '\([^+]*\).*://')
140     if [ $method = "file" ]; then
141     local localpath=$(expr match "$FAI_CONFIG_SRC" '.*://\(/.*\)')
142     export FAI=$localpath
143 lange 5543 fi
144 lange 2661 task setup
145     task defclass
146 lange 3820 unset cmdlineclasses renewclass
147 lange 3831 [ $do_init_tasks -eq 1 ] && set_disk_info
148 lange 2661 task defvar
149 lange 3831 [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
150 lange 2661 }
151     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152     # Main routine
153    
154     # Parse commandline options
155 lange 5564 TEMP=$(getopt -o s:u:Nhvc:C: --long cspace:,hostname:,new,help,verbose,class:,cfdir: -n "$0" -- "$@")
156 lange 2661 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
157     # Note the quotes around `$TEMP': they are essential!
158     eval set -- "$TEMP"
159 lange 3810 unset TEMP
160 lange 2661
161     while true ; do
162     case "$1" in
163     -h|--help)
164 lange 5901 usage ;;
165 lange 2661 -v|--verbose)
166 lange 3779 export verbose=1
167 lange 5901 shift ;;
168 lange 2761 -N|--new)
169 lange 2770 renewclass=1
170 lange 5901 shift ;;
171 lange 3922 -C|--cfdir)
172 lange 5901 cfdir=$2
173     shift 2 ;;
174 lange 3922 -c|--class)
175 lange 3795 if [ $renewclass -eq 1 ]; then
176     echo "You can't use -c|--classes and -N|--new at the same time."
177     exit 9
178     fi
179 lange 5901 export cmdlineclasses=$2
180 lange 3795 cmdlineclasses=${cmdlineclasses//,/ }
181 lange 5901 shift 2 ;;
182 lange 5451 -s|--cspace)
183 lange 5901 cspace=$2
184     shift 2 ;;
185 lange 4067 -u|--hostname)
186 lange 5901 export newhostname=$2
187     shift 2 ;;
188 lange 2661 --)
189     shift
190 lange 5901 break ;;
191 lange 2661 *)
192     echo "$0: command line parsing error ! $@"
193 lange 5901 exit 1 ;;
194 lange 2661 esac
195     done
196    
197 lange 3948 # use FAI_ETC_DIR from environment variable
198     if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
199     # print this message later so it gets into the log files
200 lange 3949 etc_message="Using environment variable \$FAI_ETC_DIR."
201 lange 3948 fi
202     [ -n "$cfdir" ] && FAI_ETC_DIR=$cfdir
203     unset cfdir
204     : ${FAI_ETC_DIR:=/etc/fai}
205 lange 3949 FAI_ETC_DIR=$(readlink -f $FAI_ETC_DIR) # canonicalize path
206 lange 3948 export FAI_ETC_DIR
207    
208 lange 3784 # override FAI_ACTION later if a command line argument is given
209 lange 4374 [ "$1" ] && export action=$1
210 lange 4074 [ "$2" ] && export FAI_ROOT=$2 # only used for dirinstall
211 lange 3708
212 lange 4074 if [ X$action = Xdirinstall ]; then
213 lange 3987 if [ -z "$FAI_ROOT" ]; then
214 lange 3798 echo "Please specify a target directory. Aborted"
215     exit 3
216     fi
217 lange 4492 if [ $renewclass -eq 0 -a -z "$cmdlineclasses" ]; then
218     echo "Please use -c or -N. Aborted"
219     exit 4
220     fi
221    
222 lange 4900 # two lines taken from task_dirinstall
223     mkdir -p $FAI_ROOT
224     FAI_ROOT=$(cd $FAI_ROOT;pwd)
225    
226 lange 4815 # check if target directory is mounted with bad options
227 mt 6136 fs=$(df -P $FAI_ROOT | tail -1 | awk '{print $6}')
228 lange 4900 if mount | grep "on $fs " | awk '{print $6}' | egrep -q "nosuid|nodev"; then
229 holger 4896 echo "Target directory is mounted using nosuid or nodev. Aborting"
230 lange 4815 exit 5
231     fi
232 lange 4900 unset fs
233 lange 4492
234 lange 5547 if [ ! -e $FAI_ETC_DIR/make-fai-nfsroot.conf ]; then
235     echo "$FAI_ETC_DIR/make-fai-nfsroot.conf not found."
236     echo "You may want to install the package fai-server"
237     exit 7
238     fi
239 lange 3884 export NFSROOT=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $NFSROOT)
240 lange 4389 export FAI_DEBOOTSTRAP=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_DEBOOTSTRAP)
241 lange 4689 export FAI_DEBOOTSTRAP_OPTS=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $FAI_DEBOOTSTRAP_OPTS)
242 lange 4389
243 lange 3784 fi
244    
245 lange 3708 if [ $(id -u) != "0" ]; then
246 lange 3151 echo "Run this program as root."
247     exit 1
248     fi
249    
250 lange 3291 # exit if we do not run from nfsroot and no parameter is given
251 lange 3304 if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "X$1" = "X" ]; then
252 lange 3291 echo "Please give more parameters if not run from the nfsroot."
253     exit 2
254     fi
255    
256 lange 3826 # are we called as an init substitute ?
257 lange 3831 export do_init_tasks=0
258 lange 5658 [ "$0" = "/etc/init.d/rcS" ] || [ X$UPSTART_JOB = Xfai ] && do_init_tasks=1
259 lange 3831 if [ $do_init_tasks -eq 1 ]; then
260 mika 6124
261 lange 6173 # if hostname was set on the kernel command line (mostly when booting from CD)
262     for word in $(cat /proc/cmdline) ; do
263     case $word in
264     hostname=*)
265     HOSTNAME=${word#*hostname=}
266     ;;
267     esac
268     done
269 lange 6195 unset word
270 mika 6124
271 lange 6173 hostname $HOSTNAME
272 mika 6124 export HOSTNAME
273    
274 lange 3826 renewclass=1 # always renew class list when installing
275 lange 4447 mkdir -p /var/lib/discover /var/discover /etc/sysconfig
276 lange 3826 fi
277 lange 4811
278     [ -f /proc/version ] || mount -n -t proc proc /proc # ubuntu initrd does not mount /proc
279 lange 3826 export start_seconds=$(cut -d . -f 1 /proc/uptime)
280 lange 3410
281 lange 5351 [ -n "$newhostname" ] && export HOSTNAME=$newhostname
282 lange 4377
283 lange 3831 if [ $do_init_tasks -eq 1 ]; then
284 lange 4756 # we are running an initial installation
285     export LOGDIR=/tmp/fai
286 lange 4773 mkdir -p $LOGDIR
287 lange 4756 else
288 lange 4761 export fai_rundate=$(date +'%Y%m%d_%H%M%S')
289 lange 4756 export LOGDIR=/var/log/fai/$HOSTNAME/$action-$fai_rundate
290 lange 4773 mkdir -p $LOGDIR
291 lange 4775 ln -snf $action-$fai_rundate $LOGDIR/../last-$action
292     ln -snf $action-$fai_rundate $LOGDIR/../last
293 lange 3826 fi
294 lange 5901 chown root:adm $LOGDIR
295 lange 4765 chmod 0750 $LOGDIR
296 lange 3410
297 lange 2661 fai_init
298 mika 5840
299     if [ $do_init_tasks -ne 1 ]; then
300     echo "Starting FAI execution - $fai_rundate" | tee -a $LOGDIR/fai.log
301     fi
302    
303 lange 5351 [ -n "$newhostname" ] && echo "Hostname set to $HOSTNAME" | tee -a $LOGDIR/fai.log
304     unset newhostname
305 lange 2661
306 lange 5646 fstart > >( tee -a $LOGDIR/fai.log ) 2>&1
307 lange 2661
308 lange 3952 [ "$action" ] && export FAI_ACTION=$action
309 lange 3810 unset action
310 lange 3689 task action 2>&1 | tee -a $LOGDIR/fai.log
311 mika 5830 final_exit_code=${PIPESTATUS[0]}
312 lange 2661
313 lange 3850 [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
314 lange 2674
315 lange 2661 echo "End of $0"
316 mika 5830 exit $final_exit_code

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5