Merge remote-tracking branch 'origin/github/pr/145'
[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 if ifclass SOURCES ; then
10   echo "Class SOURCES set, retrieving source packages."
11 else
12   echo "Class SOURCES not set, nothing to do."
13   exit 0
14 fi
15
16 set -u
17
18 PACKAGE_LIST=$(mktemp)
19
20 bailout() {
21   rm -f "${target}/grml-live/sources/errors.log"
22   rm -f "$PACKAGE_LIST"
23 }
24
25 $ROOTCMD apt-get update
26
27 $ROOTCMD dpkg-query -W -f='${Package}\n' > "${PACKAGE_LIST}"
28
29 if ! [ -r "${PACKAGE_LIST}" ] ; then
30   echo "Can not read ${PACKAGE_LIST}, can not download source packages as requested." >&2
31   bailout
32   exit 1
33 else
34   mkdir -p "${target}"/grml-live/sources
35
36   # needs to be done for each package to get:
37   # | Picking 'acpi-support' as source package instead of 'acpi-fakekey'
38   # instead of:
39   # | E: Unable to find a source package for acpi-fakekey
40   for package in $(grep -v '^#' ${PACKAGE_LIST}) ; do
41     cat << EOT | chroot "$target" /bin/bash
42 cd /grml-live/sources
43 apt-get --download-only source "$package" 2>>/grml-live/sources/errors.log
44 EOT
45   done
46
47   if grep -q '^E:' "${target}/grml-live/sources/errors.log" ; then
48     echo "Errors noticed while retrieving sources:" >&2
49     cat "${target}/grml-live/sources/errors.log" >&2
50     bailout
51     exit 1
52   elif grep -q '^W:' "${target}/grml-live/sources/errors.log" ; then
53     echo "Warnings noticed while retrieving sources (not failing the build though):"
54     cat "${target}/grml-live/sources/errors.log"
55   elif grep -q '.' "${target}/grml-live/sources/errors.log" ; then
56     echo "Unclassified problems noticed while retrieving sources:" >&2
57     cat "${target}/grml-live/sources/errors.log" >&2
58     bailout
59     exit 1
60   fi
61
62 fi
63
64 bailout
65
66 ## END OF FILE #################################################################
67 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2