| 1 |
#!/bin/sh
|
| 2 |
|
| 3 |
# this script is avilable under the terms of the GNU GPL.
|
| 4 |
# author: Henning Sprang - henning@sprang.de
|
| 5 |
|
| 6 |
# TODO: put this info in a --help / -h function!
|
| 7 |
# this script should help to create base system images for use in FAI
|
| 8 |
# installations.
|
| 9 |
# even if debboostrap seems to have scripts for multiple different
|
| 10 |
# debian-based distributions, it most often does not succeed, for example to
|
| 11 |
# create etch base system from sarge, create debian base system from ubuntu,
|
| 12 |
# etc.
|
| 13 |
# in the end, you need the actual derbootstrap of this distribution.
|
| 14 |
#
|
| 15 |
# thsi script should help lazy people (so, at least myself :) ) to make it
|
| 16 |
# easy to create them anyway, also without installing and re-installing the
|
| 17 |
# currently needed deboostrap system.
|
| 18 |
#
|
| 19 |
# we have multiple possibilities:
|
| 20 |
# - download a ready made base system image for the
|
| 21 |
# distribution wanted from a default location, or one given at the command
|
| 22 |
# line
|
| 23 |
# - create a new base system with
|
| 24 |
# - a debootstrap downloaded from the default location
|
| 25 |
# - a debootstrap downloaded from a given location
|
| 26 |
#
|
| 27 |
# TODO: add the possibility to just download a readily created base image?
|
| 28 |
# TODO: add a script for centOS/redhat and other systems minimal image
|
| 29 |
# creation!
|
| 30 |
|
| 31 |
|
| 32 |
PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
|
| 33 |
|
| 34 |
# TODO: base bootstrapper dir should be defined in (not yet existing)
|
| 35 |
# generic config file)
|
| 36 |
BOOTSTRAP_DIR=/var/lib/fai-distributions/bootstrappers/$DISTRIBUTION
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
if [ `id -u` -ne 0 ]; then
|
| 41 |
echo "Run this program as root."
|
| 42 |
exit 9
|
| 43 |
fi
|
| 44 |
|
| 45 |
while getopts vc:f:d:n opt ; do
|
| 46 |
case "$opt" in
|
| 47 |
d)
|
| 48 |
DISTRIBUTION=$OPTARG
|
| 49 |
;;
|
| 50 |
c)
|
| 51 |
cfdir=$OPTARG
|
| 52 |
;;
|
| 53 |
v)
|
| 54 |
verbose=1 ;
|
| 55 |
v=-v
|
| 56 |
set -x
|
| 57 |
;;
|
| 58 |
f)
|
| 59 |
cfg=$OPTARG
|
| 60 |
;;
|
| 61 |
n)
|
| 62 |
NATIVE_DEBOOTSTRAP=true
|
| 63 |
;;
|
| 64 |
?)
|
| 65 |
echo error in option parsing
|
| 66 |
exit 5
|
| 67 |
;; # error in option parsing
|
| 68 |
esac
|
| 69 |
done
|
| 70 |
|
| 71 |
set -e
|
| 72 |
|
| 73 |
# source fai.conf and make-fai-nfsroot.conf
|
| 74 |
[ -z "$cfdir" ] && cfdir=/etc/fai
|
| 75 |
if [ ! -d "$cfdir" ]; then
|
| 76 |
echo "$cfdir is not a directory"
|
| 77 |
exit 6
|
| 78 |
fi
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
[ "$verbose" ] && echo "Using configuration files from directory $cfdir"
|
| 83 |
if [ -n "$cfg" ]; then
|
| 84 |
. $cfdir/$cfg
|
| 85 |
else
|
| 86 |
. $cfdir/fai.conf
|
| 87 |
fi
|
| 88 |
|
| 89 |
if [ -z $DISTRIBUTION ]; then
|
| 90 |
echo "error: must give distribution for which base tgz should be built - exiting"
|
| 91 |
exit 1
|
| 92 |
fi
|
| 93 |
|
| 94 |
. /etc/fai-distributions/${DISTRIBUTION}.conf
|
| 95 |
|
| 96 |
if [ -z "$FAI_CONFIGDIR" ]; then
|
| 97 |
echo "\$FAI_CONFIGDIR is not set. Please check your settings in $cfdir/fai.conf."
|
| 98 |
exit 4
|
| 99 |
fi
|
| 100 |
|
| 101 |
if [ ! -d $FAI_CONFIGDIR ]; then
|
| 102 |
echo "need a working nfsroot - run fai-setup or make-fai-nfsroot"
|
| 103 |
exit 1
|
| 104 |
fi
|
| 105 |
|
| 106 |
|
| 107 |
# cleanup dir if it already exists!
|
| 108 |
if [ -d $BOOTSTRAP_DIR ]; then
|
| 109 |
rm -r $BOOTSTRAP_DIR
|
| 110 |
fi
|
| 111 |
|
| 112 |
mkdir -p $BOOTSTRAP_DIR
|
| 113 |
|
| 114 |
if [ -z $NATIVE_DEBOOTSTRAP ]; then
|
| 115 |
cd $BOOTSTRAP_DIR
|
| 116 |
|
| 117 |
wget $BOOTSTRAP_ARCHIVE/$BOOTSTRAP_PACKAGE
|
| 118 |
|
| 119 |
# extact debootstrap archive
|
| 120 |
dpkg-deb -x $BOOTSTRAP_PACKAGE .
|
| 121 |
|
| 122 |
cd -
|
| 123 |
fi
|
| 124 |
|
| 125 |
# TODO: put into generic config file
|
| 126 |
FAI_TMP_BASEDIR=/tmp/fai/distributions
|
| 127 |
|
| 128 |
if [ -d $FAI_TMP_BASEDIR ]; then
|
| 129 |
echo "deleting FAI_TMP_BASEDIR $FAI_TMP_BASEDIR"
|
| 130 |
rm -r $FAI_TMP_BASEDIR
|
| 131 |
fi
|
| 132 |
|
| 133 |
mkdir -p $FAI_TMP_BASEDIR
|
| 134 |
|
| 135 |
# TODO: put into (not yet existing)general config file for fai-distributions
|
| 136 |
TMP_CHROOT_DIR=`mktemp -d $FAI_TMP_BASEDIR/${DISTRIBUTION}_debootstrap.XXXXXX`
|
| 137 |
|
| 138 |
echo "TMPDIR is $TMP_CHROOT_DIR"
|
| 139 |
|
| 140 |
|
| 141 |
# from here, it's debian/dpkg specific! - for additional distributions, we
|
| 142 |
# need a decision here and call something else!
|
| 143 |
|
| 144 |
# call debootstrap as neccessary
|
| 145 |
# TODO: put into config file (for each distribution)!
|
| 146 |
|
| 147 |
[ -z $DEBOOTSTRAP_EXCLUDE ] || {
|
| 148 |
DEBOOTSTRAP_OPTIONS="--exclude=$DEBOOTSTRAP_EXCLUDE"
|
| 149 |
}
|
| 150 |
|
| 151 |
[ -z $DEBOOTSTRAP_INCLUDE ] || {
|
| 152 |
DEBOOTSTRAP_OPTIONS="$DEBOOTSTRAP_OPTIONS --include=$DEBOOTSTRAP_INCLUDE"
|
| 153 |
}
|
| 154 |
|
| 155 |
DEBOOTSTRAP_OPTIONS="$DEBOOTSTRAP_OPTIONS --arch $DEBOOTSTRAP_ARCH \
|
| 156 |
$DEBOOTSTRAP_DIST_NAME \
|
| 157 |
$TMP_CHROOT_DIR \
|
| 158 |
$MIRROR_LOCATION"
|
| 159 |
|
| 160 |
cd `dirname $0`
|
| 161 |
|
| 162 |
|
| 163 |
if [ -z $NATIVE_DEBOOTSTRAP ]; then
|
| 164 |
#export DEBOOTSTRAP_DIR=$BOOTSTRAP_DIR/usr/lib/debootstrap/
|
| 165 |
export DEBOOTSTRAP_DIR=$BOOTSTRAP_DIR/usr/share/debootstrap/
|
| 166 |
DEBOOTSTRAP_BASE=$BOOTSTRAP_DIR
|
| 167 |
fi
|
| 168 |
|
| 169 |
echo run $DEBOOTSTRAP_BASE/usr/sbin/debootstrap $DEBOOTSTRAP_OPTIONS
|
| 170 |
$DEBOOTSTRAP_BASE/usr/sbin/debootstrap $DEBOOTSTRAP_OPTIONS
|
| 171 |
|
| 172 |
chroot $TMP_CHROOT_DIR apt-get clean
|
| 173 |
|
| 174 |
|
| 175 |
# Debian specific stuff ends here
|
| 176 |
|
| 177 |
echo "Creating $DISTRIBUTION.tar.gz"
|
| 178 |
|
| 179 |
cd $TMP_CHROOT_DIR
|
| 180 |
|
| 181 |
[ -d $FAI_CONFIGDIR/basefiles ] || {
|
| 182 |
mkdir $FAI_CONFIGDIR/basefiles
|
| 183 |
}
|
| 184 |
|
| 185 |
echo "packing bae image from pwd: `pwd`"
|
| 186 |
tar cfz $FAI_CONFIGDIR/basefiles/$DISTRIBUTION.tar.gz .
|
| 187 |
|
| 188 |
chroot $TMP_CHROOT_DIR umount /dev
|
| 189 |
chroot $TMP_CHROOT_DIR umount /.dev
|
| 190 |
|
| 191 |
# cleanup
|
| 192 |
echo "cleaning up TMP_CHROOT_DIR $TMP_CHROOT_DIR"
|
| 193 |
rm -rf $TMP_CHROOT_DIR
|