move basefiles out of config space

Thomas Neumann blacky+fai at fluffbunny.de
Wed Mar 21 18:48:43 CET 2012


 >> The extrbase hook? Or is there a better place?
 > Very good idea.

In a different country and a different FAI installation I used this 
"hooks/extrbase.DEFAULT" in place of the 'normal' one. The hook assumes 
an environment variable ${BASEFILE} or 
${DEBOOTSTRAP}/${DEBOOTSTRAP_OPTS} exists and downloads/extracts the 
specified basefile.Nonetheless it should suffice as a guideline. I used 
this hook to install Debian/Ubuntu/SuSE in 32 or 64bit without relying 
on a specific classname.

The mentioned quirks may or may not apply anymore. I wrote this hook 
about 3 to 4 years ago.

#! /bin/bash
# Focus:
#    - find correct base archive and extract it
#        or
#    - call debootstrap (debian-style dists only)
# Goal:
#    - chroot possible
#    - shell available



# I found it necessary to modify the default behaviour, because
# fai has some quirks I don't like.
#   - if base.tgz exists then always use it instead of bootstrapping
#   - find a valid base image via a class
#     this class is used nowhere else and doesn't have
#     other uses.
#  (- always state a Debian base archive is being extracted)
#   - fai barfs on debootstraps exit code 141
#     (this still needs a proper analysis)

# defined in $IDENTITYFILE (variables provided through class IDfile)
# $BASEFILE
# $DEBOOTSTRAP
# $DEBOOTSTRAP_OPTS

# final fallback
DefaultBASEFILE="${NFSROOT}/live/filesystem.dir/var/tmp/base.tgz"

## Sanity check
if [[ -z ${BASEFILE} ]] ; then
     if [[ -z ${DEBOOTSTRAP} || -z ${DEBOOTSTRAP_OPTS} ]] ; then
         echo "WARNING: Neither a base file nor debootstrap options 
defined!" >&2
         task_error 201
     fi
elif ! $(wget --spider -q $BASEFILE) ; then
     echo "WARNING: Custom basefile location is set, but basefile can't 
be found!" >&2
     echo "         missing file: $BASEFILE" >&2
     task_error 202
fi


# this code is copied from task_extrbase() found in
# <NFSROOT>/usr/lib/fai/subroutines-linux
# changes:
#   - don't lie about installing debian
#   - if IGNOREBASETGZ is set, the base.tgz is ignored
#   - regard debootstraps exit code 141 as valid

echo "Installing basic operating system."
echo "=================================="

# keeps track whether an appropriate base image was found or not
BASEFOUND=0

# use a software repository if it's available
if [[ -n ${BASEFILE} ]] ; then
     echo -e "  downloading & extracting\n  ${BASEFILE}"
     if $(wget --progress=dot:mega -O - ${BASEFILE} | tar xz -C 
${target}) ; then
         BASEFOUND=1
     else
         task_error 811
     fi
elif [ -r ${DefaultBASEFILE} ] ; then
     echo "  using ${DefaultBASEFILE}"
     if $(tar xzf ${DefaultBASEFILE} -C ${target}) ; then
         BASEFOUND=1
     else
         task_error 812
     fi
fi

if [[ $BASEFOUND == 0 ]] ; then
     if [[ -n ${DEBOOTSTRAP} && -n ${DEBOOTSTRAP_OPTS} ]] ; then
         echo "Calling debootstrap."
         call_debootstrap $DEBOOTSTRAP $DEBOOTSTRAP_OPTS
         RETVAL=$?
         [[ $verbose = 1 ]] && echo "debootstrap return value: $RETVAL"
         # debootstrap may complete with the following message:
         # "I: Base system installed successfully." but the return code 
is 141
         if [ $RETVAL = 141 ] ; then
             RETVAL=0
         fi
         task_error 801 $RETVAL
     else
         task_error 802
     fi
fi

### remove old fstab file and copy the one from $LOGDIR
fs=$FAI_ROOT/etc/fstab

# now we can copy fstab
[ -f $fs ] && mv $fs $fs.old
[ -f $LOGDIR/fstab ] && cp -p $LOGDIR/fstab $fs

# no need for task_extrbase() anymore, everything's set up
skiptask extrbase


More information about the linux-fai mailing list