#!/bin/bash - this is a sourced file but this header helps vim # $HeadURL$ $LastChangedRevision$ init_deb() { local ERRSTACK_REF="$1"; shift ade_inherit ROOTDIR || return $? local DIR # Sanity checks and derivations DIR=${ROOTDIR%/}/etc/apt/sources.d # Guts if [ -d $DIR ] && [ "X$(ls $DIR)" != X ]; then save_old_dir_contents "$ERRSTACK_REF" mv $DIR || return $? elif [ -d $DIR ]; then : elif [ -e $DIR ]; then ade_error "$ERRSTACK_REF" PAA_ERR_MISC "$DIR: exists but is not an empty directory" return $ADE_FAIL fi return $ADE_OK } access_deb() { local ERRSTACK_REF="$1"; shift local SPECIFIED_REPO SPECIFIED_RELEASE SPECIFIED_PORT SPECIFIED_SECTIONS SPECIFIED_URL local EXPANDED_URL ade_inherit ROOTDIR THIS_HOST || return $? # Argument processing [ $# = 5 ] || ade_internal "$ERRSTACK_REF" "access_deb: usage error (arg count $#)" SPECIFIED_REPO=$1 SPECIFIED_RELEASE=$2 SPECIFIED_PORT=$3 SPECIFIED_SECTIONS="$4" SPECIFIED_URL=$5 # No args for the time being; everything inherited. ade_debug "$ERRSTACK_REF" 10 "access_deb: SPECIFIED_REPO=$SPECIFIED_REPO, SPECIFIED_RELEASE=$SPECIFIED_RELEASE, SPECIFIED_PORT=$SPECIFIED_PORT, SPECIFIED_SECTIONS=$SPECIFIED_SECTIONS, SPECIFIED_URL=$SPECIFIED_URL" # Sanity checks and derivations detokenise "$ERRSTACK_REF" $SPECIFIED_URL EXPANDED_URL HOST=$THIS_HOST REPO=$SPECIFIED_REPO || return $? # Guts mkdir -p ${ROOTDIR%/}/etc/apt/sources.list.d if [ -f ${ROOTDIR%/}/etc/apt/sources.list.d/$SPECIFIED_REPO.list ]; then write_test_file "$ERRSTACK_REF" ${ROOTDIR%/}/etc/apt/sources.list.d/$SPECIFIED_REPO.list || return $? else write_test_dir "$ERRSTACK_REF" ${ROOTDIR%/}/etc/apt/sources.list.d || return $? fi { echo "deb $EXPANDED_URL $SPECIFIED_RELEASE $SPECIFIED_SECTIONS" } > ${ROOTDIR%/}/etc/apt/sources.list.d/$SPECIFIED_REPO.list return $ADE_OK } unaccess_deb() { local ERRSTACK_REF="$1"; shift ade_inherit ROOTDIR || return $? # Argument processing # No args for the time being; everything inherited. [ $# = 0 ] || ade_internal "$ERRSTACK_REF" "unaccess_deb: usage error (arg count $#)" ade_inherit REPO ade_debug "$ERRSTACK_REF" 10 "access_deb: REPO=$REPO" # Sanity checks and derivations # Guts rm -f ${ROOTDIR%/}/etc/apt/sources.list.d/$REPO.list return $ADE_OK } analyse_deb() { local ERRSTACK_REF="$1"; shift local SPECIFIED_FILE local NAME_REF ARCH_REF VERSION_REF # Process arguments [ $# = 4 ] || ade_internal "$ERRSTACK_REF" "analyse_deb: usage error (arg count $#)" SPECIFIED_FILE=$1 NAME_REF=$2 ARCH_REF=$3 VERSION_REF=$4 ade_inherit --allow-empty $NAME_REF $ARCH_REF $VERSION_REF # Sanity checks and derivations ade_validate_command "$ERRSTACK_REF" dpkg-deb || return $? # Guts DPKGDEB_OUTPUT="$(dpkg-deb -I $SPECIFIED_FILE)" # $'\n' is a real newline; this is the way to get it into a general string. [[ "$DPKGDEB_OUTPUT" =~ $'\n'\ [Pp]ackage:\ ([^$'\n']*)($|$'\n') ]] eval "$NAME_REF=\"\${BASH_REMATCH[1]}\"" [[ "$DPKGDEB_OUTPUT" =~ $'\n'\ [Aa]rchitecture:\ ([^$'\n']*)($|$'\n') ]] eval "$ARCH_REF=\"\${BASH_REMATCH[1]}\"" [[ "$DPKGDEB_OUTPUT" =~ $'\n'\ [Vv]ersion:\ ([^$'\n']*)($|$'\n') ]] eval "$VERSION_REF=\"\${BASH_REMATCH[1]}\"" for VAR in $NAME_REF $ARCH_REF $VERSION_REF; do eval "ade_debug \"\$ERRSTACK_REF\" 10 \"control_section_deb: $VAR=\$$VAR\"" eval "[ \"X\$$VAR\" != X ]" || { ade_error "$ERRSTACK_REF" PAA_ERR_MISC "$SPECIFIED_FILE: failed to collect some DEB info (is file an accessible DEB?)"; return $ADE_FAIL; } done return $ADE_OK } control_section_deb() { local ERRSTACK_REF="$1"; shift local SPECIFIED_REPO SPECIFIED_RELEASE SPECIFIED_PORT SPECIFIED_SECTION local FILE DIR PROGNAME ade_inherit SEPARATOR || return $? # Process arguments [ $# = 4 ] || ade_internal "$ERRSTACK_REF" "control_section_deb: usage error (arg count $#)" SPECIFIED_REPO=$1 SPECIFIED_RELEASE=$2 SPECIFIED_PORT=$3 SPECIFIED_SECTION=$4 # Sanity checks and derivations ade_get_progname "$ERRSTACK_REF" PROGNAME ade_write_sql "$ERRSTACK_REF" "select path from extendeds where repo == '$SPECIFIED_REPO';" REPOPATH || return $? ade_validate_command "$ERRSTACK_REF" dpkg-scanpackages || return $? # Initialise an overrides file and create the temporary pool. > /tmp/$PROGNAME.$$.overrides mkdir -p /tmp/$PROGNAME.$$.debian/pool # Construct overrides file and construct temporary pool with just selected DEBs in (to stop dpkg-scanpackages # from scanning *everything*) ade_write_sql "$ERRSTACK_REF" "select name,file,dir from controls where repo == '$SPECIFIED_REPO' and release == '$SPECIFIED_RELEASE' and port == '$SPECIFIED_PORT' and section == '$SPECIFIED_SECTION' order by name;" TUPLES || return $? while read TUPLE; do # Workaround for "no rows produces one line of output" bug. [ "X$TUPLE" != X ] || break # Unmunge (nothing) ade_split_string "$ERRSTACK_REF" "$TUPLE" "$SEPARATOR" NAME FILE DIR || return $? ade_blank_sql_null "$ERRSTACK_REF" NAME FILE DIR || return $? ade_debug "$ERRSTACK_REF" 10 "control_section_deb: NAME=$NAME, FILE=$FILE, DIR=$DIR" # Create overrides entry echo "$NAME optional $SPECIFIED_SECTION" >> /tmp/$PROGNAME.$$.overrides # Symlink package into the temporary root/pool # (Ordinarily the target does not exist already, but _latest_.deb # may exist already, so we need to quieten that down; hence 'ln -sf'.) ln -sf $REPOPATH/$DIR/$FILE /tmp/$PROGNAME.$$.debian/$DIR/$FILE done <<<"$TUPLES" # Run dpkg-scanpackages ( cd /tmp/$PROGNAME.$$.debian && \ # Previously we had 'dpkg-scanpackages --multiversion . ' here, but that # has recently started producing 'File: ' lines in the Packages file of the format # 'File: ./pool/whatever' rather than 'File: pool/whatever' and this confuses debmirror # (it downloads the file but then, when it sees 'pool/whatever' doesn't match './pool/whatever', # it considers it cruft and deletes it). dpkg-scanpackages --multiversion * /tmp/$PROGNAME.$$.overrides > /tmp/$PROGNAME.$$.dpkg-scanpackages.stdout 2>/tmp/$PROGNAME.$$.dpkg-scanpackages.stderr ) # Check dpkg-scanpackages output # Note that the stderr is compared against *two* error messages (a version # with 'dpkg-scanpackages: info:' prefix and version without. This is because # of differences between lenny's dpkg-scanpackages and squeezes. [[ $(cat /tmp/$PROGNAME.$$.dpkg-scanpackages.stderr) =~ ^(dpkg-scanpackages:\ info:|)\ Wrote\ [0-9][0-9]*\ entries\ to\ output\ Packages\ file\.$ ]] || { cat /tmp/$PROGNAME.$$.dpkg-scanpackages.stderr >&2 rm -f /tmp/$PROGNAME.$$.dpkg-scanpackages.stderr ade_error "$ERRSTACK_REF" PAA_ERR_MISC "'dpkg-scanpackages' failed" return $ADE_FAIL } # Relocate dpkg-scanpackages and compress rm -f /tmp/$PROGNAME.$$.dpkg-scanpackages.stderr mkdir -p $REPOPATH/dists/$RELEASE/$SPECIFIED_SECTION/binary-$SPECIFIED_PORT ( cd $REPOPATH/dists/$RELEASE/$SPECIFIED_SECTION/binary-$SPECIFIED_PORT && \ mv /tmp/$PROGNAME.$$.dpkg-scanpackages.stdout Packages && \ gzip -c Packages > Packages.gz && \ chmod a+r Packages* ) # Clean up rm -fr /tmp/$PROGNAME.$$.debian rm -f /tmp/$PROGNAME.$$.overrides return $ADE_OK } control_port_deb() { local ERRSTACK_REF="$1"; shift local SPECIFIED_REPO SPECIFIED_RELEASE SPECIFIED_PORT # Process arguments [ $# = 3 ] || ade_internal "$ERRSTACK_REF" "control_port_deb: usage error (arg count $#)" SPECIFIED_REPO=$1 SPECIFIED_RELEASE=$2 SPECIFIED_PORT=$3 # Sanity checks and derivations ade_write_sql "$ERRSTACK_REF" "select path from extendeds where repo == '$SPECIFIED_REPO';" REPOPATH || return $? ade_validate_command "$ERRSTACK_REF" apt-ftparchive || return $? # Guts ( cd $REPOPATH && \ apt-ftparchive contents . -o APT::FTPArchive::Release::Codename=$SPECIFIED_RELEASE -o APT::FTPArchive::Release::Architectures=$SPECIFIED_PORT | gzip > dists/$SPECIFIED_RELEASE/Contents-$SPECIFIED_PORT.gz && \ chmod a+r dists/$SPECIFIED_RELEASE/Contents-$SPECIFIED_PORT.gz ) || { ade_error "$ERRSTACK_REF" PAA_ERR_MISC "'apt-ftparchive contents' failed"; return $ADE_FAIL; } return $ADE_OK } control_release_deb() { local ERRSTACK_REF="$1"; shift local SPECIFIED_REPO SPECIFIED_RELEASE local SECTIONS PORTS TUPLE REPOPATH ORIGIN LABEL SIGNER ade_inherit SEPARATOR GPG_CMD || return $? # Process arguments [ $# = 2 ] || ade_internal "$ERRSTACK_REF" "control_release_deb: usage error (arg count $#)" SPECIFIED_REPO=$1 SPECIFIED_RELEASE=$2 # Sanity checks and derivations ade_write_sql "$ERRSTACK_REF" "select path,origin,label,signer from extendeds where repo == '$SPECIFIED_REPO';" TUPLE || return $? ade_split_string "$ERRSTACK_REF" "$TUPLE" "$SEPARATOR" REPOPATH ORIGIN LABEL SIGNER || return $? # 'apt-ftparchive release' will want the complete list of sections and ports. ade_write_sql "$ERRSTACK_REF" "select group_concat(section,' ') from sections where repo == '$SPECIFIED_REPO' and release == '$SPECIFIED_RELEASE';" SECTIONS || return $? ade_write_sql "$ERRSTACK_REF" "select group_concat(port,' ') from ports where repo == '$SPECIFIED_REPO' and release == '$SPECIFIED_RELEASE';" PORTS || return $? ade_debug "$ERRSTACK_REF" 10 "control_release_deb: SPECIFIED_REPO=$SPECIFIED_REPO, SPECIFIED_RELEASE=$SPECIFIED_RELEASE, REPOPATH=$REPOPATH, ORIGIN=$ORIGIN, LABEL=$LABEL, SIGNER=$SIGNER, SECTIONS=$SECTIONS, PORTS=$PORTS" ade_validate_command "$ERRSTACK_REF" apt-ftparchive || return $? # Guts ( cd $REPOPATH && \ apt-ftparchive release -o APT::FTPArchive::Release::Origin="$ORIGIN" -o APT::FTPArchive::Release::Label="$LABEL" -o APT::FTPArchive::Release::Components="$SECTIONS" -o APT::FTPArchive::Release::Suite=$SPECIFIED_RELEASE -o APT::FTPArchive::Release::Codename=$SPECIFIED_RELEASE -o APT::FTPArchive::Release::Architectures="$PORTS" dists/$SPECIFIED_RELEASE > dists/$SPECIFIED_RELEASE/Release && \ chmod a+r dists/$SPECIFIED_RELEASE/Release && \ rm -f $REPOPATH/dists/$SPECIFIED_RELEASE/Release.gpg && \ $GPG_CMD --batch --local-user "$SIGNER" --armor --detach-sign --sign --output dists/$SPECIFIED_RELEASE/Release.gpg dists/$SPECIFIED_RELEASE/Release && \ chmod a+r dists/$SPECIFIED_RELEASE/Release.gpg ) || { ade_error "$ERRSTACK_REF" PAA_ERR_MISC "'apt-ftparchive' release or '$GPG_CMD --sign' failed"; return $ADE_FAIL; } return $ADE_OK } control_repo_deb() { local ERRSTACK_REF="$1"; shift local SPECIFIED_REPO # Process arguments [ $# = 1 ] || ade_internal "$ERRSTACK_REF" "control_repo_deb: usage error (arg count $#)" SPECIFIED_REPO=$1 return $ADE_OK } reload_apache_deb() { local ERRSTACK_REF="$1"; shift ade_inherit ROOTDIR local OUTPUT # Process arguments [ $# = 0 ] || ade_internal "$ERRSTACK_REF" "reload_apache_deb: bad arg count ($#)" # Sanity checks and derivations # Guts if [ ! -x ${ROOTDIR%/}/etc/init.d/apache2 ]; then ade_error "$ERRSTACK_REF" PAA_ERR_MISC "${ROOTDIR%/}/etc/init.d/apache2: not found" return $ADE_FAIL elif ! OUTPUT=$(${ROOTDIR%/}/etc/init.d/apache2 reload 2>&1); then ade_error "$ERRSTACK_REF" PAA_ERR_MISC "apache reload failed (output was: $OUTPUT)" return $ADE_FAIL elif [ "X$OUTPUT" != "XReloading web server config: apache2." ]; then ade_warning "$ERRSTACK_REF" PAA_ERR_MISC "apache reload succeeded but did not produce expected output (output was: $OUTPUT)" fi return $ADE_OK }