| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -e |
| 4 |
set -u |
| 5 |
|
| 6 |
# make sure we have the sbin directories in our PATH to find piuparts ootb |
| 7 |
PATH="${PATH}:/sbin:/usr/local/sbin:/usr/sbin" |
| 8 |
|
| 9 |
if [ "$#" -lt 1 ] ; then |
| 10 |
echo "Usage: $0 <debian_package(s).deb>" >&2 |
| 11 |
exit 1 |
| 12 |
fi |
| 13 |
|
| 14 |
if [ -z "${distribution:-}" ] ; then |
| 15 |
# default to the currently running distribution to avoid hardcoding |
| 16 |
# a distribution which might not be supported by the running system |
| 17 |
distribution=$(lsb_release --short --codename 2>/dev/null) |
| 18 |
[ -n "${distribution}" ] || distribution="sid" # fallback to "sid" iff lsb_release fails |
| 19 |
echo "*** distribution variable is unset, using distribution $distribution ***" |
| 20 |
fi |
| 21 |
|
| 22 |
if [ -z "${architecture:-}" ] ; then |
| 23 |
architecture=$(dpkg --print-architecture) |
| 24 |
echo "*** architecture variable is unset, using system architecture [$architecture] ***" |
| 25 |
fi |
| 26 |
|
| 27 |
if [ -n "${SCRIPTSDIR:-}" ] ; then |
| 28 |
echo "*** SCRIPTSDIR variable is set to $SCRIPTSDIR - using for piuparts run ***" |
| 29 |
scriptsdir="$SCRIPTSDIR" |
| 30 |
else |
| 31 |
scriptsdir_path="/etc/piuparts/scripts/" |
| 32 |
if [ -d "${scriptsdir_path}" ]; then |
| 33 |
echo "*** SCRIPTSDIR variable is NOT set - using default [/etc/piuparts/scripts/] for piuparts run ***" |
| 34 |
scriptsdir="${scriptsdir_path}" |
| 35 |
else |
| 36 |
# Some old piuparts do not ship a scripts dir |
| 37 |
scriptsdir="" |
| 38 |
fi |
| 39 |
fi |
| 40 |
|
| 41 |
if [ -n "${PIUPARTS_TMPDIR:-}" ] ; then |
| 42 |
echo "*** PIUPARTS_TMPDIR is set to $PIUPARTS_TMPDIR - using for piuparts run ***" |
| 43 |
piuparts_tmpdir="$PIUPARTS_TMPDIR" |
| 44 |
fi |
| 45 |
|
| 46 |
create_base_tgz() { |
| 47 |
[ -r /var/cache/pbuilder/base-${distribution}-${architecture}.tgz ] && return 0 |
| 48 |
|
| 49 |
if [ -n "${MIRROR:-}" ] ; then |
| 50 |
echo "*** MIRROR variable is set [$MIRROR], using it ***" |
| 51 |
else |
| 52 |
if lsb_release --id 2>/dev/null | grep -q Ubuntu ; then |
| 53 |
MIRROR='http://archive.ubuntu.com/ubuntu' |
| 54 |
else |
| 55 |
MIRROR='http://deb.debian.org/debian' |
| 56 |
fi |
| 57 |
echo "*** Using mirror $MIRROR ***" |
| 58 |
fi |
| 59 |
|
| 60 |
if [ -n "${COMPONENTS:-}" ] ; then |
| 61 |
echo "*** COMPONENTS is set [$COMPONENTS], using for debootstrapping ***" |
| 62 |
components="$COMPONENTS" |
| 63 |
elif lsb_release --id 2>/dev/null | grep -q Ubuntu ; then |
| 64 |
components='main,universe,restricted,multiverse' |
| 65 |
echo "*** Ubuntu detected, using components $components ***" |
| 66 |
else |
| 67 |
components='main,contrib,non-free' |
| 68 |
echo "*** COMPONENTS is unset and looks like Debian - therefore using components $components ***" |
| 69 |
fi |
| 70 |
unset "COMPONENTS" # ensure it's unset so debootstrap doesn't fail, see GH issue 145 |
| 71 |
|
| 72 |
tmpdir=$(mktemp -d) |
| 73 |
|
| 74 |
if [ -n "${DEBOOTSTRAP_OPTIONS:-}" ] ; then |
| 75 |
echo "*** DEBOOTSTRAP_OPTIONS is set [$DEBOOTSTRAP_OPTIONS], using for debootstrapping ***" |
| 76 |
fi |
| 77 |
|
| 78 |
debootstrap --variant=minbase \ |
| 79 |
--components="$components" \ |
| 80 |
--arch="$architecture" \ |
| 81 |
${DEBOOTSTRAP_OPTIONS:-} \ |
| 82 |
"$distribution" \ |
| 83 |
"$tmpdir" \ |
| 84 |
"$MIRROR" |
| 85 |
|
| 86 |
( |
| 87 |
cd "$tmpdir" |
| 88 |
tar acf /var/cache/pbuilder/base-${distribution}-${architecture}.tgz * |
| 89 |
rm -rf ./* |
| 90 |
) |
| 91 |
} |
| 92 |
|
| 93 |
if [ -n "${SKIP_BASE_TGZ:-}" ] ; then |
| 94 |
echo "*** SKIP_BASE_TGZ is set, not using building/using /var/cache/pbuilder/base-${distribution}-${architecture}.tgz ***" |
| 95 |
else |
| 96 |
create_base_tgz |
| 97 |
basetgz="--basetgz=/var/cache/pbuilder/base-${distribution}-${architecture}.tgz" |
| 98 |
fi |
| 99 |
|
| 100 |
# option not available with piuparts 0.38 |
| 101 |
if piuparts --help 2>/dev/null | grep -q -- '--warn-on-leftovers-after-purge' ; then |
| 102 |
warn_on_leftovers_after_purge_option="--warn-on-leftovers-after-purge" |
| 103 |
fi |
| 104 |
|
| 105 |
# logrotate test is kind of useless until http://bugs.debian.org/582630 is solved |
| 106 |
if piuparts --help 2>/dev/null | grep -q -- '--skip-logrotatefiles-test' ; then |
| 107 |
skip_logrotatefiles_test_option="--skip-logrotatefiles-test" |
| 108 |
fi |
| 109 |
|
| 110 |
piuparts_version=$(piuparts --version 2>/dev/null | awk '{print $2}') |
| 111 |
if dpkg --compare-versions $piuparts_version lt 0.43 ; then |
| 112 |
echo "*************************************************************************" |
| 113 |
echo "*** WARNING - piuparts version $piuparts_version is not recent enough ***" |
| 114 |
echo "*** You might run into problems, please consider upgrading piuparts ***" |
| 115 |
echo "*************************************************************************" |
| 116 |
fi |
| 117 |
|
| 118 |
piuparts \ |
| 119 |
-d "${distribution}" \ |
| 120 |
${warn_on_leftovers_after_purge_option:-} \ |
| 121 |
${skip_logrotatefiles_test_option:-} \ |
| 122 |
--log-file='piuparts.txt' \ |
| 123 |
${scriptsdir:+--scriptsdir "$scriptsdir"} \ |
| 124 |
${piuparts_tmpdir:+--tmpdir="$piuparts_tmpdir"} \ |
| 125 |
${MIRROR:+--mirror="$MIRROR"} \ |
| 126 |
${basetgz:-} \ |
| 127 |
"$@" |