# mk-basefile, create basefiles for some distributions
#
-# Thomas Lange, Uni Koeln, 2011-2015
+# Thomas Lange, Uni Koeln, 2011-2017
# based on the Makefile implementation of Michael Goetze
-#
-# Usage example: fai-mk-basefile -J SQUEEZE64
-# This will create a SQUEEZE64.tar.xz basefile.
# Supported distributions (each i386/amd64):
# Debian GNU/Linux
# Define your local mirros here
# For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
MIRROR_DEBIAN=http://http.us.debian.org/debian
-#MIRROR_DEBIAN=http://localmirror/debian/
MIRROR_UBUNTU=http://mirror.netcologne.de/ubuntu/
MIRROR_TRISQUEL=http://mirror.fsf.org/trisquel/
MIRROR_CENTOS=http://mirror.netcologne.de/
-#MIRROR_CENTOS=http://localmirror
-#MIRROR_SLC=http://localmirror
EXCLUDE_SQUEEZE=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data
-EXCLUDE_WHEEZY=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data
-EXCLUDE_JESSIE=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data
+EXCLUDE_WHEEZY=info,tasksel,tasksel-data
+EXCLUDE_JESSIE=tasksel,tasksel-data
+EXCLUDE_STRETCH=tasksel,tasksel-data
EXCLUDE_BELENOS=dhcp3-client,dhcp3-common,info
EXCLUDE_TRUSTY=dhcp3-client,dhcp3-common,info
-EXCLUDE_XENIAL=isc-dhcp-client,isc-dhcp-common,udhcpc,dibbler-client,dhcpcd5,info,tasksel,tasksel-data
+EXCLUDE_FLIDAS=tasksel,tasksel-data
+EXCLUDE_XENIAL=tasksel,tasksel-data
INCLUDE_DEBIAN=aptitude
tarit() {
- tar --xattrs --selinux --acl --one-file-system -C $xtmp -cf - . | $zip > $target.$ext
+ tar $attributes --one-file-system -C $xtmp -cf - . | $zip > $target.$ext
}
}
-squeeze() {
-
- local arch=$1
-
- check
- debootstrap --arch $arch --exclude=${EXCLUDE_SQUEEZE} squeeze $xtmp ${MIRROR_DEBIAN}
- cleanup-deb
- tarit
-}
+debgeneric() {
-wheezy() {
-
- local arch=$1
-
- check
- debootstrap --arch $arch --exclude=${EXCLUDE_WHEEZY} wheezy $xtmp ${MIRROR_DEBIAN}
- cleanup-deb
- tarit
-}
-
-jessie() {
-
- local arch=$1
-
- check
- debootstrap --arch $arch --exclude=${EXCLUDE_JESSIE} --include=${INCLUDE_DEBIAN} jessie $xtmp ${MIRROR_DEBIAN}
- cleanup-deb
- tarit
-}
-
-stretch() {
-
- local arch=$1
-
- check
- debootstrap --arch $arch --exclude=${EXCLUDE_JESSIE} --include=${INCLUDE_DEBIAN} stretch $xtmp ${MIRROR_DEBIAN}
- cleanup-deb
- tarit
-}
-
-trusty() {
-
- local arch=$1
-
- check
- debootstrap --arch $arch --exclude=${EXCLUDE_TRUSTY} --include=${INCLUDE_DEBIAN} trusty $xtmp ${MIRROR_UBUNTU}
- cleanup-deb
- tarit
-}
-
-xenial() {
-
- local arch=$1
-
- check
- debootstrap --arch $arch --exclude=${EXCLUDE_XENIAL} --include=${INCLUDE_DEBIAN} xenial $xtmp ${MIRROR_UBUNTU}
- cleanup-deb
- tarit
-}
+ local DIST=$1
+ shift
+ local mirror=$1
+ if [[ $DIST =~ 64 ]]; then
+ arch=amd64
+ else
+ arch=i386
+ fi
-belenos() {
- ln -sf gutsy /usr/share/debootstrap/scripts/belenos
- local arch=$1
+ DIST=${DIST%%??}
+ dist=${DIST,,}
+ local exc="EXCLUDE_$DIST"
check
- debootstrap --arch $arch --exclude=${EXCLUDE_BELENOS} --include=${INCLUDE_DEBIAN} belenos $xtmp ${MIRROR_TRISQUEL}
+ debootstrap --arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror
cleanup-deb
tarit
}
-unknown() {
+prtdists() {
- echo "Unknown distribution. Aborting."
echo "Available:
CENTOS5_32 CENTOS5_64
SQUEEZE32 SQUEEZE64
WHEEZY32 WHEEZY64
JESSIE32 JESSIE64
+ STRETCH32 STRETCH64
"
- exit 99
}
+usage() {
+
+ cat <<EOF
+mk-basefile, create minimal base files for a Linux distritubtion
+
+ Copyright (C) 2011-2016 by Thomas Lange
+
+Usage: mk-basefile [OPTION] ... DISTRIBUTION
+
+ -s Show list of supported linux distributions
+ -a Add xtattrs, acl and selinux properties to the tar file.
+ -d DIR Use DIR for creating the temporary subtree structure.
+ -z Use gzip for compressing the tar file.
+ -J Use xz for compressing the tar file.
+ -k Keep the temporary subtree structure, do not remove it.
+ -h Print help.
+
+ Usage example: mk-basefile -J STRETCH64
+ This will create a STRETCH64.tar.xz basefile.
+
+EOF
+ exit 0
+}
# main routine
ext=tar
zip=cat
-tmpdir=/var/tmp
+attributes=
+cleanup=1
-while getopts zJd: opt ; do
+while getopts ashzJd:k opt ; do
case "$opt" in
- d) tmpdir=$OPTARG ;;
+ a) attributes="--xattrs --selinux --acl" ;;
+ d) export TMPDIR=$OPTARG ;;
z) zip="gzip -9"; ext=tar.gz ;;
J) zip="xz -8" ext=tar.xz ;;
+ k) cleanup=0 ;;
+ h) usage ;;
+ s) prtdists ; exit 0;;
+ ?) exit 3 ;; # error in option parsing
esac
done
shift $(($OPTIND - 1))
-xtmp=$(mktemp -d $tmpdir/basefiles.XXXXXXXX)
+xtmp=$(mktemp --tmpdir -d basefiles.XXXXXXXX)
if [ $? -eq 1 ]; then
echo "mktemp failed. Aborting."
exit 2
fi
+chmod 755 $xtmp
target=$1 # also the name of the output file
SLC6_32) slc i386 6 ;;
SLC6_64) slc amd64 6 ;;
SLC7_64) slc amd64 7 ;;
- TRUSTY32) trusty i386 ;;
- TRUSTY64) trusty amd64 ;;
- BELENOS64) belenos amd64 ;;
- XENIAL32) xenial i386 ;;
- XENIAL64) xenial amd64 ;;
- SQUEEZE32) squeeze i386 ;;
- SQUEEZE64) squeeze amd64 ;;
- WHEEZY32) wheezy i386 ;;
- WHEEZY64) wheezy amd64 ;;
- JESSIE32) jessie i386 ;;
- JESSIE64) jessie amd64 ;;
- STRETCH64) stretch amd64 ;;
- *) unknown ;;
+ BELENOS*|FLIDAS*)
+ debgeneric $target $MIRROR_TRISQUEL ;;
+ TRUSTY*|XENIAL*)
+ debgeneric $target $MIRROR_UBUNTU ;;
+ SQUEEZE*|WHEEZY*|JESSIE*|STRETCH*)
+ debgeneric $target $MIRROR_DEBIAN ;;
+ *) echo "Unknown distribution. Aborting."
+ prtdists
+ exit 99 ;;
esac
# cleanup
-rm -rf $xtmp
+if [ $cleanup -eq 1 ]; then
+ rm -rf $xtmp
+fi