update to upstream 5.3.4
[automated-distro-installer] / fai / config / basefiles / mk-basefile
index 591a87836cce9293b5fd47ec9cd38c94efe2e2ed..6d6cfca3700791aa69ea37c7f89d627196800411 100755 (executable)
@@ -2,11 +2,8 @@
 
 # mk-basefile, create basefiles for some distributions
 #
-# Thomas Lange, Uni Koeln, 2011-2015
+# Thomas Lange, Uni Koeln, 2011-2016
 # 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://httpredir.debian.org/debian/
-MIRROR_DEBIAN=http://localmirror/debian/
 MIRROR_UBUNTU=http://mirror.netcologne.de/ubuntu/
 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_TRUSTY=dhcp3-client,dhcp3-common,info
-EXCLUDE_XENIAL=isc-dhcp-client,isc-dhcp-common,udhcpc,dibbler-client,dhcpcd5,info,tasksel,tasksel-data
+EXCLUDE_XENIAL=tasksel,tasksel-data
 
 INCLUDE_DEBIAN=aptitude
 
@@ -124,7 +120,7 @@ cleanup-rinse() {
 
 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
 }
 
 
@@ -158,60 +154,30 @@ slc() {
 }
 
 
-squeeze() {
-
-    local arch=$1
-
-    check
-    debootstrap --arch $arch --exclude=${EXCLUDE_SQUEEZE} squeeze $xtmp ${MIRROR_DEBIAN}
-    cleanup-deb
-    tarit
-}
-
-wheezy() {
-
-    local arch=$1
-
-    check
-    debootstrap --arch $arch --exclude=${EXCLUDE_WHEEZY} wheezy $xtmp ${MIRROR_DEBIAN}
-    cleanup-deb
-    tarit
-}
+debgeneric() {
 
-jessie() {
+    local DIST=$1
+    shift
+    local mirror=$1
 
-    local arch=$1
-
-    check
-    debootstrap --arch $arch --exclude=${EXCLUDE_JESSIE} --include=${INCLUDE_DEBIAN} jessie $xtmp ${MIRROR_DEBIAN}
-    cleanup-deb
-    tarit
-}
-
-trusty() {
+    if [[ $DIST =~ 64 ]]; then
+        arch=amd64
+    else
+        arch=i386
+    fi
 
-    local arch=$1
+    DIST=${DIST%%??}
+    dist=${DIST,,}
 
+    local exc="EXCLUDE_$DIST"
     check
-    debootstrap --arch $arch --exclude=${EXCLUDE_TRUSTY} --include=${INCLUDE_DEBIAN} trusty $xtmp ${MIRROR_UBUNTU}
+    debootstrap --arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror
     cleanup-deb
     tarit
 }
 
-xenial() {
-
-    local arch=$1
-
-    check
-    debootstrap --arch $arch --exclude=${EXCLUDE_XENIAL} --include=${INCLUDE_DEBIAN} xenial $xtmp ${MIRROR_UBUNTU}
-    cleanup-deb
-    tarit
-}
+prtdists() {
 
-
-unknown() {
-
-    echo "Unknown distribution. Aborting."
     echo "Available:
 
     CENTOS5_32   CENTOS5_64
@@ -225,27 +191,56 @@ unknown() {
     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
@@ -265,18 +260,16 @@ case "$target" in
     SLC6_32) slc i386 6 ;;
     SLC6_64) slc amd64 6 ;;
     SLC7_64) slc amd64 7 ;;
-    TRUSTY32) trusty i386 ;;
-    TRUSTY64) trusty 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 ;;
-    *) unknown ;;
+    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