#!/bin/bash set -x set -u export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' rm -f piuparts.tap [ -d artifacts ] || { echo "Error: directory 'artifacts' does not exist." >&2 ; exit 1 ; } [ -d sources.list.d ] || { echo "Error: directory 'sources.list.d' does not exist." >&2 ; exit 1 ; } [ -n "${distribution:-}" ] || { echo "Error: variable 'distribution' is unset." >&2 ; exit 1 ; } # support overwriting on command line, e.g. for debugging [ -n "${PIUPARTS_BASEDIR:-}" ] || PIUPARTS_BASEDIR="$(sudo mktemp --dry-run -d --tmpdir=/var/cache/pbuilder/ --suffix=_piuparts_basetmp)" [ -n "${PIUPARTS_TMPDIR:-}" ] || PIUPARTS_TMPDIR="$(sudo mktemp -d --tmpdir=/var/cache/pbuilder/ --suffix=_piuparts_tmp)" [ -n "${SCRIPTSDIR:-}" ] || SCRIPTSDIR="$PWD/source/scripts/" [ -n "${architecture:-}" ] || architecture="$(dpkg --print-architecture)" [ -n "${mirror:-}" ] || mirror='http://debian.sipwise.com/debian' echo "*** Executing $0 ***" echo "*** Using $PIUPARTS_BASEDIR as \$PIUPARTS_BASEDIR ***" echo "*** Using $PIUPARTS_TMPDIR as \$PIUPARTS_TMPDIR ***" echo "*** Using $SCRIPTSDIR as \$SCRIPTSDIR ***" echo "*** Using $architecture as \$architecture ***" echo "*** Using $distribution as \$distribution ***" echo "*** Using $mirror as \$mirror ***" # set up sources.list, apt-preferences,... as needed prepare_environment() { # do not operate on original to avoid modifications and problems with simultaneous runs echo "*** Creating copy of /var/cache/pbuilder/base-${distribution}-${architecture}.cow ***" sudo cp -a "/var/cache/pbuilder/base-${distribution}-${architecture}.cow" "$PIUPARTS_BASEDIR" echo "*** Setting up sources.list ***" sudo cp sources.list.d/sources.list "$PIUPARTS_BASEDIR"/etc/apt/sources.list sudo cp sources.list.d/builddeps.list "$PIUPARTS_BASEDIR"/etc/apt/sources.list.d/ echo "*** Setting up apt_preferences ***" if [ -f sources.list.d/preferences ] ; then sudo cp sources.list.d/preferences "$PIUPARTS_BASEDIR"/etc/apt/preferences else cat << EOF | sudo tee "$PIUPARTS_BASEDIR"/etc/apt/preferences Package: * Pin: release o=Sipwise Pin-Priority: 990 Package: * Pin: release o=The Sipwise VoIP platform Pin-Priority: 990 EOF fi } # build the actual piuparts command line if piuparts --help 2>&1 | grep -- --update-retries ; then UPDATE_RETRIES="--update-retries=3" else if command -v figlet &>/dev/null ; then echo "*** WARN ***" | figlet fi echo "*** WARN: the installed piuparts version does not support the --update-retries=... option. See TT#16502 ***" fi piuparts_cmdline="sudo piuparts \ --warn-on-leftovers-after-purge --skip-logrotatefiles-test --log-file=piuparts.txt \ --distribution=$distribution --mirror=$mirror --keep-sources-list \ --scriptsdir=$SCRIPTSDIR --tmpdir=$PIUPARTS_TMPDIR \ --existing-chroot=$PIUPARTS_BASEDIR ${UPDATE_RETRIES:-} \ -i /etc/localtime" echo "*** Using '$piuparts_cmdline' as piuparts_cmdline ***" # wrapper for CE vs PRO vs CARRIER packages # shellcheck disable=SC2046 ce_pro_carrier() { echo "*** Running for CE packages ***" if find artifacts/ -type f ! -name \*-pro\* ! -name \*-carrier\* | grep -q '.' ; then $piuparts_cmdline $(find artifacts/ -type f ! -name \*-pro\* ! -name \*-carrier\*) || true fi echo "*** Running for PRO packages ***" if find artifacts/ -type f ! -name \*-ce\* ! -name \*-carrier\* | grep -q '.' ; then $piuparts_cmdline $(find artifacts/ -type f ! -name \*-ce\* ! -name \*-carrier\*) || true fi echo "*** Running for CARRIER packages ***" if find artifacts/ -type f ! -name \*-pro\* ! -name \*-ce\* | grep -q '.' ; then $piuparts_cmdline $(find artifacts/ -type f ! -name \*-pro\* ! -name \*-ce\*) || true fi } # ngcp-support specific workaround ngcp_support_packages() { for package in artifacts/*.deb ; do echo "*** Running ngcp-support specific package $package ***" $piuparts_cmdline "$package" || true done } # ngcp-license-client specific workaround to handle conflicting binary packages ngcp_license_client() { for package in artifacts/*.deb ; do echo "*** Running ngcp-license-client specific package $package ***" $piuparts_cmdline "$package" || true done } RUN_CE_PRO_CARRIER=false # by default assume we don't have ce/pro/carrier specific packages find artifacts/ -name '*-carrier-*' -or -name '*-carrier_*' | grep -q '.' && RUN_CE_PRO_CARRIER=true find artifacts/ -name '*-pro-*' -or -name '*-pro_*' | grep -q '.' && RUN_CE_PRO_CARRIER=true find artifacts/ -name '*-ce-*' -or -name '*-ce_*' | grep -q '.' && RUN_CE_PRO_CARRIER=true RUN_NGCP_SUPPORT_PACKAGES=false # by default assume we don't have the ngcp-support* packages to deal with find artifacts/ -name 'ngcp-support-access*' -or -name 'ngcp-support-noaccess*' | grep -q '.' && RUN_NGCP_SUPPORT_PACKAGES=true RUN_LICENSE_CLIENT=false # by default assume we don't have the ngcp-license-client* packages to deal with find artifacts/ -name 'ngcp-license-client*' | grep -q '.' && RUN_LICENSE_CLIENT=true # prepare environment for piuparts prepare_environment if [ "$RUN_NGCP_SUPPORT_PACKAGES" = "true" ] ; then echo "*** Found ngcp-support specific packages, executing ngcp_support_packages ***" ngcp_support_packages elif [ "$RUN_CE_PRO_CARRIER" = "true" ] ; then echo "*** Found ce/pro/carrier specific packages, executing ce_pro_carrier ***" ce_pro_carrier elif [ "$RUN_LICENSE_CLIENT" = "true" ] ; then echo "*** Found ngcp-license-client* packages, executing ngcp_license_client ***" ngcp_license_client else echo "*** No ce/pro/carrier specific packages found, executing for all artifacts/*.deb files ***" $piuparts_cmdline artifacts/*.deb || true fi # generate TAP output echo "*** Generating TAP output ***" piuparts_tap --ignore-broken-symlinks piuparts.txt > piuparts.tap # cleanup echo "*** Cleaning up ***" sudo rmdir "$PIUPARTS_TMPDIR" sudo rm -rf "$PIUPARTS_BASEDIR"