retrieve source packages via grml-live using SOURCES class
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 03-get-sources
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/03-get-sources
3 # Purpose:       download sources of Debian packages
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 [ -r /etc/grml/grml-live.conf ]  && . /etc/grml/grml-live.conf
10 [ -r /etc/grml/grml-live.local ] && . /etc/grml/grml-live.local
11
12 if ifclass SOURCES ; then
13   echo "Class SOURCES set, retrieving source packages."
14 else
15   echo "Class SOURCES not set, nothing to do."
16   exit 0
17 fi
18
19 set -u
20
21 PACKAGE_LIST=$(mktemp)
22
23 bailout() {
24   rm -f "${target}/grml-live/sources/errors.log"
25   rm -f "$PACKAGE_LIST"
26 }
27
28 $ROOTCMD dpkg-query -W -f='${Package}\n' > "${PACKAGE_LIST}"
29
30 if ! [ -r "${PACKAGE_LIST}" ] ; then
31   echo "Can not read ${PACKAGE_LIST}, can not download source packages as requested." >&2
32   bailout
33   exit 1
34 else
35   mkdir -p "${target}"/grml-live/sources
36
37   # needs to be done for each package to get:
38   # | Picking 'acpi-support' as source package instead of 'acpi-fakekey'
39   # instead of:
40   # | E: Unable to find a source package for acpi-fakekey
41   for package in $(grep -v '^#' ${PACKAGE_LIST}) ; do
42     cat << EOT | chroot "$target" /bin/bash
43 cd /grml-live/sources
44 apt-get --download-only source "$package" 2>>/grml-live/sources/errors.log
45 EOT
46   done
47
48   if grep -q . "${target}/grml-live/sources/errors.log" ; then
49     echo "Errors noticed while retrieving sources:" >&2
50     cat "${target}/grml-live/sources/errors.log" >&2
51     bailout
52     exit 1
53   fi
54
55 fi
56
57 bailout
58
59 ## END OF FILE #################################################################
60 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2