retrieve source packages via grml-live using SOURCES class
[grml-live.git] / grml-live
index 18248ec..04b30bb 100755 (executable)
--- a/grml-live
+++ b/grml-live
@@ -60,6 +60,7 @@ Usage: $PN [options, see as follows]
    -s <suite>              Debian suite; values: etch, lenny, squeeze, sid
    -t <template_directory> place of the templates
    -u                      update existing chroot instead of rebuilding it from scratch
+   -U <username>           arrange output to be owned by specified username
    -v <version_number>     specify version number of the release
    -V                      increase verbosity in the build process
    -z                      use ZLIB instead of LZMA/XZ compression
@@ -148,6 +149,7 @@ umount_all() {
    umount $CHROOT_OUTPUT/sys  2>/dev/null || /bin/true
    umount $CHROOT_OUTPUT/dev/pts 2>/dev/null || /bin/true
    umount $CHROOT_OUTPUT/dev 2>/dev/null || /bin/true
+   umount "${CHROOT_OUTPUT}/grml-live/sources/" 2>/dev/null || /bin/true
    [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
 }
 # }}}
@@ -163,8 +165,19 @@ bailout() {
   if [ -n "$PACK_ARTIFACTS" ]; then
     log "Cleaning up"
     einfo "Cleaning up"
-    [ -n "${CHROOT_OUTPUT}" -a -d "${CHROOT_OUTPUT}" ] && rm -r "${CHROOT_OUTPUT}"
     [ -n "${BUILD_OUTPUT}"  -a -d "${BUILD_OUTPUT}"  ] && rm -r "${BUILD_OUTPUT}"
+    [ -n "${CHROOT_OUTPUT}" -a -d "${CHROOT_OUTPUT}" ] && rm -r "${CHROOT_OUTPUT}"
+    eend 0
+  fi
+  if [ -n "$CHOWN_USER" ]; then
+    log "Setting ownership"
+    einfo "Setting ownership"
+    [ -n "${OUTPUT}"         -a -d "${OUTPUT}"         ] && chown -R "${CHOWN_USER}:" "${OUTPUT}"
+    [ -n "${BUILD_OUTPUT}"   -a -d "${BUILD_OUTPUT}"   ] && chown -R "${CHOWN_USER}:" "${BUILD_OUTPUT}"
+    [ -n "${CHROOT_OUTPUT}"  -a -d "${CHROOT_OUTPUT}"  ] && chown -R "${CHOWN_USER}:" "${CHROOT_OUTPUT}"
+    [ -n "${ISO_OUTPUT}"     -a -d "${ISO_OUTPUT}"     ] && chown -R "${CHOWN_USER}:" "${ISO_OUTPUT}"
+    [ -n "${LOG_OUTPUT}"     -a -d "${LOG_OUTPUT}"     ] && chown -R "${CHOWN_USER}:" "${LOG_OUTPUT}"
+    [ -n "${CHROOT_ARCHIVE}" -a -f "${CHROOT_ARCHIVE}" ] && chown -R "${CHOWN_USER}:" "${CHROOT_ARCHIVE}"
     eend 0
   fi
   log "------------------------------------------------------------------------------"
@@ -274,7 +287,7 @@ fi
 # }}}
 
 # command line parsing {{{
-while getopts "a:C:c:d:D:g:i:I:o:r:s:t:v:AbBFnNquVz" opt; do
+while getopts "a:C:c:d:D:g:i:I:o:r:s:t:U:v:AbBFnNquVz" opt; do
   case "$opt" in
     a) ARCH="$OPTARG" ;;
     A) PACK_ARTIFACTS=1 ;;
@@ -297,6 +310,7 @@ while getopts "a:C:c:d:D:g:i:I:o:r:s:t:v:AbBFnNquVz" opt; do
     v) VERSION="$OPTARG" ;;
     F) FORCE=1 ;;
     u) UPDATE=1 ;;
+    U) CHOWN_USER="$OPTARG" ;;
     V) VERBOSE="-v" ;;
     z) SQUASHFS_ZLIB=1 ;;
     ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;;
@@ -386,6 +400,7 @@ if [ -z "$FORCE" ] ; then
    [ -n "$CHROOT_INSTALL" ]      && echo "  Install files from directory to chroot:  $CHROOT_INSTALL"
    [ -n "$BOOTID" ]              && echo "  Boot identifier:   $BOOTID"
    [ -n "$NO_BOOTID" ]           && echo "  Skipping bootid feature."
+   [ -n "$CHOWN_USER" ]          && echo "  Output owner:      $CHOWN_USER"
    [ -n "$DEFAULT_BOOTOPTIONS" ] && echo "  Adding default bootoptions: \"$DEFAULT_BOOTOPTIONS\""
    [ -n "$FAI_ARGS" ]            && echo "  Additional arguments for FAI: $FAI_ARGS"
    [ -n "$LOGFILE" ]             && echo "  Logging to file:   $LOGFILE"
@@ -416,10 +431,10 @@ fi
 if [ -n "${PACK_ARTIFACTS}" ]; then
   echo "Wiping old artifacts"
   [ -n "${CHROOT_OUTPUT}"  -a -d "${CHROOT_OUTPUT}"  ] && rm -r "${CHROOT_OUTPUT}"
-  [ -n "${CHROOT_ARCHIVE}" -a -d "${CHROOT_ARCHIVE}" ] && rm -r "${CHROOT_ARCHIVE}"
   [ -n "${BUILD_OUTPUT}"   -a -d "${BUILD_OUTPUT}"   ] && rm -r "${BUILD_OUTPUT}"
   [ -n "${ISO_OUTPUT}"     -a -d "${ISO_OUTPUT}"     ] && rm -r "${ISO_OUTPUT}"
   [ -n "${LOG_OUTPUT}"     -a -d "${LOG_OUTPUT}"     ] && rm -r "${LOG_OUTPUT}"
+  [ -n "${CHROOT_ARCHIVE}" -a -f "${CHROOT_ARCHIVE}" ] && rm "${CHROOT_ARCHIVE}"
 fi
 # }}}
 
@@ -524,9 +539,14 @@ $GRML_LIVE_SOURCES" | \
 else
   cat >> "$SOURCES_LIST_OUTPUT" << EOF
 # generated by grml-live
-deb http://deb.grml.org/            grml-stable  main
-deb http://deb.grml.org/            grml-testing main
-deb http://cdn.debian.net/debian $SUITE  main contrib non-free
+deb     http://deb.grml.org/            grml-stable  main
+deb-src http://deb.grml.org/            grml-stable  main
+
+deb     http://deb.grml.org/            grml-testing main
+deb-src http://deb.grml.org/            grml-testing main
+
+deb     http://cdn.debian.net/debian $SUITE  main contrib non-free
+deb-src http://cdn.debian.net/debian $SUITE  main contrib non-free
 EOF
 fi
 
@@ -612,6 +632,9 @@ else
          mount --bind "${MIRROR_DIRECTORY}" "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
       fi
 
+      mkdir -p "${OUTPUT}/grml_sources/" "${CHROOT_OUTPUT}/grml-live/sources/"
+      mount --bind "${OUTPUT}/grml_sources/" "${CHROOT_OUTPUT}/grml-live/sources/"
+
       # tell dpkg to use "unsafe io" during the build
       [ -d "$CHROOT_OUTPUT/etc/dpkg/dpkg.cfg.d" ] || mkdir -p "$CHROOT_OUTPUT/etc/dpkg/dpkg.cfg.d"
       echo force-unsafe-io > "$CHROOT_OUTPUT/etc/dpkg/dpkg.cfg.d/unsafe-io"