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

Diff of /trunk/bin/fai

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3726 by lange, Tue Aug 1 20:38:50 2006 UTC revision 3950 by lange, Wed Sep 13 16:52:37 2006 UTC
# Line 31  Line 31 
31  export PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:  export PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
32  # some variables  # some variables
33  export FAI_VERSION=FAIVERSIONSTRING  export FAI_VERSION=FAIVERSIONSTRING
34  rundir=/var/run/fai  stamp=/var/run/fai/FAI_INSTALLATION_IN_PROGRESS
 stamp=$rundir/FAI_INSTALLATION_IN_PROGRESS  
35  romountopt="-o async,noatime,nolock,ro,actimeo=1800"  romountopt="-o async,noatime,nolock,ro,actimeo=1800"
36    
37  # the type of operating system (linux, sunos)  export faimond=0
38  oclass=$(uname -s | tr a-z A-Z)  export renewclass=0
 unset oclass  
 faimond=0  
39  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40  fai_init() {  fai_init() {
41    
42      set -a # now export all variables      set -a # now export all variables
43    
44      umask 022      umask 022
45      # read fai.conf      if [ ! -d "$FAI_ETC_DIR" ]; then
46      # linux dir          echo "$FAI_ETC_DIR is not a directory"
47      [ -f /etc/fai/fai.conf ] && . /etc/fai/fai.conf          exit 6
48        fi
49        [ -f $FAI_ETC_DIR/fai.conf ] && . $FAI_ETC_DIR/fai.conf
50    
51      if [ -f /boot/RUNNING_FROM_FAICD ]; then   # we are booting from fai cd      if [ -f /boot/RUNNING_FROM_FAICD ]; then   # we are booting from fai cd
52          umount /initrd          umount /initrd
53          romountopt=          romountopt=
54          FAI_DEBMIRROR="--bind /media/mirror"          FAI_DEBMIRROR="--bind /media/mirror"
55          MNTPOINT=/media/mirror          MNTPOINT=/media/mirror
56          FAI_LOCATION=          FAI_CONFIG_SRC="file://$FAI"   # on a fai-cd the config space is already available
57      fi      fi
58    
59      # some variables from are not needed any more      # some variables from are not needed any more
60      unset FAI_CONFIGDIR      #unset FAI_CONFIGDIR
61    
62      # read subroutine definitions      # read subroutine definitions
63      local sub=/usr/lib/fai/subroutines      local sub=/usr/lib/fai/subroutines
# Line 73  fai_init() { Line 72  fai_init() {
72      DEBIAN_FRONTEND=noninteractive      DEBIAN_FRONTEND=noninteractive
73      # local disks are mounted to $FAI_ROOT      # local disks are mounted to $FAI_ROOT
74      if [ -z "$FAI_ROOT" ] ; then      if [ -z "$FAI_ROOT" ] ; then
75        [ $DO_INIT_TASKS -eq 1 ] && FAI_ROOT=/tmp/target || FAI_ROOT=/        [ $do_init_tasks -eq 1 ] && FAI_ROOT=/tmp/target || FAI_ROOT=/
76      fi      fi
77      # executed command in the environment of the new system      # executed command in the environment of the new system
78      ROOTCMD="chroot $FAI_ROOT"      ROOTCMD="chroot $FAI_ROOT"
79      # no chroot needed      # no chroot needed
80      [ "$FAI_ROOT" = '/' ] && ROOTCMD=      [ "$FAI_ROOT" = '/' ] && ROOTCMD=
   
     # several log files  
     diskvar=$LOGDIR/disk_var.sh  
   
     # variables for cfengine  
81      target=$FAI_ROOT      target=$FAI_ROOT
82    
83      if [ $DO_INIT_TASKS -eq 1 ]; then      if [ $do_init_tasks -eq 1 ]; then
84          trap 'echo "Now rebooting";faireboot' INT QUIT ;          trap 'echo "Now rebooting";faireboot' INT QUIT
85      else      else
86          trap "echo 'Aborted';rm -f $stamp" INT QUIT ;          trap "echo 'Aborted';rm -f $stamp" INT QUIT
87      fi      fi
88    
89      # if HOST was specified on the commandline, set hostname to it      if [ $do_init_tasks -eq 1 ]; then
90      [ $DO_INIT_TASKS -eq 1 ] && eval_cmdline          eval_cmdline
91      if [ -n "$HOST" ]; then          # if HOST was specified on the commandline, set hostname to it
92          HOSTNAME=$HOST          if [ -n "$HOST" ]; then
93          hostname $HOST              HOSTNAME=$HOST
94          echo "Hostname set to $HOST" | tee -a $LOGDIR/fai.log              hostname $HOST
95      fi              echo "Hostname set to $HOST" | tee -a $LOGDIR/fai.log
96      export HOSTNAME          fi
     # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called  
     [ -z "$classes" ] && classes="DEFAULT $oclass $HOSTNAME LAST"  
97    
     if [ $DO_INIT_TASKS -eq 1 ]; then  
98          mount -t sysfs sysfs /sys          mount -t sysfs sysfs /sys
99            [ -d /var/run/network ] || mkdir /var/run/network
100          ifup lo          ifup lo
101              # we really need to start udev              # we really need to start udev
102          [ -x /etc/init.d/udev ] && /etc/init.d/udev start          [ -x /etc/init.d/udev ] && /etc/init.d/udev start
103          [ -x /sbin/portmap ] && /sbin/portmap          [ -x /sbin/portmap ] && /sbin/portmap
104          mount -t devpts devpts /dev/pts          mount -t devpts devpts /dev/pts
105              # add other options for nfs mount of /dev/root to root-path in dhcpd.conf          # add other options for nfs mount of /dev/root to root-path in dhcpd.conf
106          mount -o remount,noatime,ro /dev/root /          mount -o remount,noatime,ro /dev/root /
107          cat /proc/kmsg >/dev/tty4 &          cat /proc/kmsg >/dev/tty4 &
108      fi      fi
109    
110        # since HOSTNAME may change define classes now, so we can call hooks before fai-class is called
111        [ -z "$classes" ] && classes="DEFAULT $(uname -s | tr a-z A-Z) $HOSTNAME LAST"
112    
113      prcopyleft      prcopyleft
114    
115      save_dmesg      save_dmesg
# Line 122  fai_init() { Line 117  fai_init() {
117  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118  usage() {  usage() {
119      cat <<-EOF      cat <<-EOF
120          fai $FAI_VERSION. Copyright (C) 1999-2005 Thomas Lange          fai $FAI_VERSION. Copyright (C) 1999-2006 Thomas Lange
121          Usage: $0 [options] [action]          Usage: $0 [options] [action]
122    
123          Options:          Options:
124             -v|--verbose      display more information during the update             -v|--verbose      display more information during the update
125             -h|--help         display this help message             -h|--help         display this help message
126             -N|--new          renew list of classes             -N|--new          renew list of classes
127               -C|--class        comma separated list of classes
128               -c|--cfdir CFDIR  Use CFDIR for  reading the config files
129    
130  EOF  EOF
131      exit 0      exit 0
132  }  }
# Line 136  EOF Line 134  EOF
134  fstart() {  fstart() {
135    
136      # these tasks can define variables, that are needed later      # these tasks can define variables, that are needed later
137        [ -n "$etc_message" ] && echo ""
138        echo "$etc_message"
139        echo "Using configuration files from $FAI_ETC_DIR"
140        unset etc_message
141      task confdir      task confdir
142      task setup      task setup
143      task defclass      task defclass
144      set_disk_info      unset cmdlineclasses renewclass
145        [ $do_init_tasks -eq 1 ] && set_disk_info
146      task defvar      task defvar
147      [ $DO_INIT_TASKS -eq 1 ] && load_keymap_consolechars      [ $do_init_tasks -eq 1 ] && load_keymap_consolechars
148  }  }
149  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150  # Main routine  # Main routine
151    
 export renewclass=0  
152  # Parse commandline options  # Parse commandline options
153  TEMP=$(getopt -o Nhv --long new,help,verbose -n "$0" -- "$@")  TEMP=$(getopt -o Nhvc:C: --long new,help,verbose,class:,cfdir: -n "$0" -- "$@")
154  if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi  if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
155  # Note the quotes around `$TEMP': they are essential!  # Note the quotes around `$TEMP': they are essential!
156  eval set -- "$TEMP"  eval set -- "$TEMP"
157    unset TEMP
158    
159  while true ; do  while true ; do
160      case "$1" in      case "$1" in
# Line 161  while true ; do Line 164  while true ; do
164              ;;              ;;
165          -v|--verbose)          -v|--verbose)
166              shift              shift
167              verbose=1              export verbose=1
168              ;;              ;;
169          -N|--new)          -N|--new)
170              shift              shift
171              renewclass=1              renewclass=1
172              ;;              ;;
173            -C|--cfdir)
174                shift
175                cfdir=$1
176                shift
177                ;;
178            -c|--class)
179    
180                if [ $renewclass -eq 1 ]; then
181                    echo "You can't use -c|--classes and -N|--new at the same time."
182                    exit 9
183                fi
184                shift
185                export cmdlineclasses=$1
186                shift
187                cmdlineclasses=${cmdlineclasses//,/ }
188                ;;
189          --)          --)
190              shift              shift
191              break              break
# Line 178  while true ; do Line 197  while true ; do
197      esac      esac
198  done  done
199    
200    # use FAI_ETC_DIR from environment variable
201    if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
202        # print this message later so it gets into the log files
203        etc_message="Using environment variable \$FAI_ETC_DIR."
204    fi
205    [ -n "$cfdir" ] && FAI_ETC_DIR=$cfdir
206    unset cfdir
207    : ${FAI_ETC_DIR:=/etc/fai}
208    FAI_ETC_DIR=$(readlink -f $FAI_ETC_DIR) # canonicalize path
209    export FAI_ETC_DIR
210    
211    # override FAI_ACTION later if a command line argument is given
212    [ "$1" ] && action=$1
213    [ "$2" ] && targetdir=$2 # only used for dirinst
214    
215    if [ X$action = Xdirinst ]; then
216        if [ -z "$targetdir" ]; then
217            echo "Please specify a target directory. Aborted"
218            exit 3
219        fi
220        export NFSROOT=$(source $FAI_ETC_DIR/make-fai-nfsroot.conf; echo $NFSROOT)
221        export FAI_ROOT=$targetdir
222    fi
223    
224  if [ $(id -u) != "0" ]; then  if [ $(id -u) != "0" ]; then
225      echo "Run this program as root."      echo "Run this program as root."
# Line 190  if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a " Line 232  if [ ! -f /.THIS_IS_THE_FAI_NFSROOT -a "
232      exit 2      exit 2
233  fi  fi
234    
235      # HG: are we called as an init substitute ?  # are we called as an init substitute ?
236      export DO_INIT_TASKS=0  export do_init_tasks=0
237      [ "$0" = "/etc/init.d/rcS" ] && DO_INIT_TASKS=1  [ "$0" = "/etc/init.d/rcS" ] && do_init_tasks=1
238      if [ $DO_INIT_TASKS -eq 1 ]; then  if [ $do_init_tasks -eq 1 ]; then
239          renewclass=1 # always renew class list when installing      renewclass=1 # always renew class list when installing
240          create_ramdisk      create_ramdisk
241      fi  fi
242    export start_seconds=$(cut -d . -f 1 /proc/uptime)
243    
244      export LOGDIR=/var/log/fai/current  [ -d /var/run/fai ] || mkdir /var/run/fai
245      mkdir -p $LOGDIR  export LOGDIR=/var/log/fai/current
246    [ -d $LOGDIR ] && rm -rf $LOGDIR
247      # for compability, can be removed later  mkdir -p $LOGDIR
248      if [ $DO_INIT_TASKS -eq 1 ]; then  
249          mkdir /tmp/fai  # for compability, can be removed later
250          mount --bind /var/log/fai/current /tmp/fai  if [ $do_init_tasks -eq 1 ]; then
251      fi      mkdir /tmp/fai
252        mount --bind $LOGDIR /tmp/fai
253    fi
254    
255  fai_init  fai_init
256    if [ X$action = Xdirinst ]; then
257        skiptask confdir
258        export FAI=$FAI_CONFIGDIR
259        set -a
260        clean_exit() {
261            rm -f $stamp
262            [ -z "$targetdir" ] && return
263            [ -d $targetdir/proc/self ] && umount $targetdir/proc $targetdir/sys
264            [ -f /etc/init.d/udev ] && umount $targetdir/dev
265        }
266        set +a
267        trap 'clean_exit' EXIT
268    fi
269    
270  mkfifo $LOGDIR/logfifo  mkfifo $LOGDIR/logfifo
271  tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &  tee -a $LOGDIR/fai.log < $LOGDIR/logfifo &
# Line 215  tee -a $LOGDIR/fai.log < $LOGDIR/logfifo Line 273  tee -a $LOGDIR/fai.log < $LOGDIR/logfifo
273  fstart &> $LOGDIR/logfifo  fstart &> $LOGDIR/logfifo
274  rm $LOGDIR/logfifo  rm $LOGDIR/logfifo
275  sleep 1 # wait for tee to complete. One second should be ok  sleep 1 # wait for tee to complete. One second should be ok
   
276  # old code  # old code
277  # {  # {
278  # # a bash group command with { does not work on sparc  # # a bash group command with { does not work on sparc
# Line 227  sleep 1 # wait for tee to complete. One Line 284  sleep 1 # wait for tee to complete. One
284  # set_disk_info  # set_disk_info
285  # } > >( tee -a $LOGDIR/fai.log )  2>&1  # } > >( tee -a $LOGDIR/fai.log )  2>&1
286    
287  # override FAI_ACTION if a command line argument is given  [ "$action" ] && FAI_ACTION=$action
288  [ "$1" ] && FAI_ACTION=$1  unset action
 [ "$2" ] && targetdir=$2 # only used for dirinst  
   
289  task action 2>&1 | tee -a $LOGDIR/fai.log  task action 2>&1 | tee -a $LOGDIR/fai.log
290    
291  # not happy with this at all!  [ -L "/var/run/fai/current_config" ] && rm -f "/var/run/fai/current_config"
 [ "$FAI_CVSROOT" ] && rm -rf $FAI  
   
 [ -L "$rundir/current_config" ] && rm -f "$rundir/current_config"  
292    
293  echo "End of $0"  echo "End of $0"

Legend:
Removed from v.3726  
changed lines
  Added in v.3950

  ViewVC Help
Powered by ViewVC 1.1.5