+setupsimplenativepackage() {
+ local NAME="$1"
+ local ARCH="$2"
+ local VERSION="$3"
+ local RELEASE="${4:-unstable}"
+ local DEPENDENCIES="$5"
+ local DESCRIPTION="$6"
+ local SECTION="${7:-others}"
+ local DISTSECTION
+ if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
+ DISTSECTION="main"
+ else
+ DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
+ fi
+ local BUILDDIR=incoming/${NAME}-${VERSION}
+ mkdir -p ${BUILDDIR}/debian/source
+ cd ${BUILDDIR}
+ echo "* most suckless software product ever" > FEATURES
+ test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
+ test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
+
+ * Initial release
+
+ -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
+ test -e debian/control || echo "Source: $NAME
+Section: $SECTION
+Priority: optional
+Maintainer: Joe Sixpack <joe@example.org>
+Build-Depends: debhelper (>= 7)
+Standards-Version: 3.9.1
+
+Package: $NAME
+Architecture: $ARCH" > debian/control
+ test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
+ if [ -z "$DESCRIPTION" ]; then
+ echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
+ If you find such a package installed on your system,
+ YOU did something horribly wrong! They are autogenerated
+ und used only by testcases for APT and surf no other propose…" >> debian/control
+ else
+ echo "Description: $DESCRIPTION" >> debian/control
+ fi
+ test -e debian/compat || echo "7" > debian/compat
+ test -e debian/source/format || echo "3.0 (native)" > debian/source/format
+ test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
+ cd - > /dev/null
+}
+
+buildsimplenativepackage() {
+ local NAME="$1"
+ local ARCH="$2"
+ local VERSION="$3"
+ local RELEASE="${4:-unstable}"
+ local DEPENDENCIES="$5"
+ local DESCRIPTION="$6"
+ local SECTION="${7:-others}"
+ local DISTSECTION
+ if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
+ DISTSECTION="main"
+ else
+ DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
+ fi
+ setupsimplenativepackage "$NAME" "$ARCH" "$VERSION" "$RELEASE" "$DEPENDENCIES" "$DESCRIPTION" "$SECTION"
+ buildpackage "incoming/${NAME}-${VERSION}" "$RELEASE" "$DISTSECTION"
+ rm -rf "incoming/${NAME}-${VERSION}"
+}
+
+buildpackage() {
+ local BUILDDIR=$1
+ local RELEASE=$2
+ local SECTION=$3
+ msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
+ cd $BUILDDIR
+ if [ "$ARCH" = "all" ]; then
+ ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
+ fi
+ local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
+ local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
+ local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
+ cd - > /dev/null
+ for PKG in $PKGS; do
+ echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
+ done
+ for SRC in $SRCS; do
+ echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
+ done
+ msgdone "info"
+}
+
+buildaptarchive() {
+ if [ -d incoming ]; then
+ buildaptarchivefromincoming $*
+ else
+ buildaptarchivefromfiles $*
+ fi
+}
+
+createaptftparchiveconfig() {
+ local ARCHS="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#' | tr '\n' ' ')"
+ if [ -z "$ARCHS" ]; then
+ # the pool is empty, so we will operate on faked packages - let us use the configured archs
+ ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
+ fi
+ echo -n 'Dir {
+ ArchiveDir "' >> ftparchive.conf
+ echo -n $(readlink -f .) >> ftparchive.conf
+ echo -n '";
+ CacheDir "' >> ftparchive.conf
+ echo -n $(readlink -f ..) >> ftparchive.conf
+ echo -n '";
+ FileListDir "' >> ftparchive.conf
+ echo -n $(readlink -f pool/) >> ftparchive.conf
+ echo -n '";
+};
+Default {
+ Packages::Compress ". gzip bzip2 lzma";
+ Sources::Compress ". gzip bzip2 lzma";
+ Contents::Compress ". gzip bzip2 lzma";
+};
+TreeDefault {
+ Directory "pool/";
+ SrcDirectory "pool/";
+};
+APT {
+ FTPArchive {
+ Release {
+ Origin "joesixpack";
+ Label "apttestcases";
+ Suite "unstable";
+ Description "repository with dummy packages";
+ Architectures "' >> ftparchive.conf
+ echo -n "$ARCHS" >> ftparchive.conf
+ echo 'source";
+ };
+ };
+};' >> ftparchive.conf
+ for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
+ echo -n 'tree "dists/' >> ftparchive.conf
+ echo -n "$DIST" >> ftparchive.conf
+ echo -n '" {
+ Architectures "' >> ftparchive.conf
+ echo -n "$ARCHS" >> ftparchive.conf
+ echo -n 'source";
+ FileList "' >> ftparchive.conf
+ echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
+ echo -n '";
+ SourceFileList "' >> ftparchive.conf
+ echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
+ echo -n '";
+ Sections "' >> ftparchive.conf
+ echo -n "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')" >> ftparchive.conf
+ echo '";
+};' >> ftparchive.conf
+ done
+}
+
+buildaptftparchivedirectorystructure() {
+ local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
+ for DIST in $DISTS; do
+ local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
+ for SECTION in $SECTIONS; do
+ local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
+ for ARCH in $ARCHS; do
+ mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
+ done
+ mkdir -p dists/${DIST}/${SECTION}/source
+ mkdir -p dists/${DIST}/${SECTION}/i18n
+ done
+ done
+}
+
+insertpackage() {
+ local RELEASE="$1"
+ local NAME="$2"
+ local ARCH="$3"
+ local VERSION="$4"
+ local DEPENDENCIES="$5"
+ local ARCHS="$ARCH"
+ if [ "$ARCHS" = "all" ]; then
+ ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
+ fi
+ for BUILDARCH in $ARCHS; do
+ local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
+ mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
+ touch aptarchive/dists/${RELEASE}/main/source/Sources
+ local FILE="${PPATH}/Packages"
+ echo "Package: $NAME
+Priority: optional
+Section: other
+Installed-Size: 23356
+Maintainer: Joe Sixpack <joe@example.org>
+Architecture: $ARCH
+Version: $VERSION" >> $FILE
+ test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
+ echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
+ If you find such a package installed on your system,
+ YOU did something horribly wrong! They are autogenerated
+ und used only by testcases for APT and surf no other propose…
+" >> $FILE
+ done
+}
+
+buildaptarchivefromincoming() {
+ msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"