summaryrefslogtreecommitdiffstats
path: root/bin/pbuild.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbin/pbuild.sh314
1 files changed, 314 insertions, 0 deletions
diff --git a/bin/pbuild.sh b/bin/pbuild.sh
new file mode 100755
index 0000000..8dfd12e
--- /dev/null
+++ b/bin/pbuild.sh
@@ -0,0 +1,314 @@
+#!/bin/sh
+
+# Copyright (C) 2015 Daniel Baumann <mail@daniel-baumann.ch>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+case "$(basename ${0})" in
+ p*)
+ MODE="progress-linux"
+ ;;
+
+ b*)
+ MODE="bfh"
+ ;;
+esac
+
+PROGRAM="${0}"
+
+case "$(dpkg --print-architecture)" in
+# arm64)
+# CPUS="1"
+# export DEB_BUILD_OPTIONS=parallel=${CPUS}
+# ;;
+
+ *)
+ CPUS="$(nproc)"
+ export DEB_BUILD_OPTIONS=parallel=${CPUS}
+ ;;
+esac
+
+Parameters()
+{
+ LONG_OPTIONS="build:,distribution:,interactive,package:,tag:,"
+ OPTIONS="b:,d:,i,p:,t:,"
+
+ PARAMETERS="$(getopt --longoptions ${LONG_OPTIONS} --name=${PROGRAM} --options ${OPTIONS} --shell sh -- ${@})"
+
+ if [ "${?}" != "0" ]
+ then
+ echo "${PROGRAM}: getopt exit" >&2
+ exit 1
+ fi
+
+ eval set -- "${PARAMETERS}"
+
+ while true
+ do
+ case "${1}" in
+ -b|--build)
+ BUILD="${2}"
+ shift 2
+ ;;
+
+ -d|--distribution)
+ DISTRIBUTION="${2}"
+ shift 2
+ ;;
+
+ -i|--interactive)
+ INTERACTIVE="true"
+ shift 1
+ ;;
+
+ -p|--package)
+ PACKAGE="$(echo ${2} | sed -e 's|/$||g')"
+ shift 2
+ ;;
+
+ -t|--tag)
+ TAG="${2}"
+ shift 2
+ ;;
+
+ --)
+ shift
+ break
+ ;;
+
+ *)
+ echo "${PROGRAM}: getopt error" >&2
+ exit 1
+ ;;
+ esac
+ done
+}
+
+Parameters "${@}"
+
+if [ -z "${DISTRIBUTION}" ] || [ -z "${PACKAGE}" ]
+then
+ echo "Usage: ${PROGRAM} [-b|--build BUILD] -d|--distribution DISTRIBUTION -p|--package PACKAGE -t|--tag TAG" >&2
+ exit 1
+fi
+
+INTERACTIVE="${INTERACTIVE:=false}"
+
+if [ -e "${PACKAGE}" ]
+then
+ echo "${PACKAGE}: directory already exists"
+ exit 1
+fi
+
+if [ -z "${BUILD}" ]
+then
+ case "$(dpkg --print-architecture)" in
+ amd64) # FIXME
+ BUILD="source,binary-arch,binary-indep"
+ ;;
+
+ arm*|i386) # FIXME
+ BUILD="binary-arch"
+ ;;
+ esac
+fi
+
+TARGET="${PACKAGE}"
+
+case "${MODE}" in
+ progress-linux)
+ REPOSITORY="https://git.progress-linux.org/packages/${DISTRIBUTION}/${PACKAGE}"
+ BRANCH="progress-linux"
+ SERVER="https://apt.progress-linux.org"
+ ;;
+
+ bfh)
+ REPOSITORY="https://git.bfh.science/packages/${DISTRIBUTION}/${PACKAGE}"
+ BRANCH="bfh"
+ SERVER="https://apt.bfh.science"
+ ;;
+esac
+
+for BUILD in $(echo ${BUILD} | sed -e 's|,| |g')
+do
+ echo "################################################################################"
+ echo "Building ${BUILD} ($(dpkg --print-architecture)) package: ${PACKAGE} ${VERSION}"
+ echo "################################################################################"
+
+ case "${BUILD}" in
+ source)
+ if [ -n "${TAG}" ]
+ then
+ GIT_BRANCH="${TAG}"
+ git clone --branch ${GIT_BRANCH} "${REPOSITORY}" "${TARGET}"
+ else
+ GIT_BRANCH="${BRANCH}"
+ #git clone --depth 1 --no-single-branch --branch ${GIT_BRANCH} "${REPOSITORY}" "${TARGET}"
+ git clone --no-single-branch --branch ${GIT_BRANCH} "${REPOSITORY}" "${TARGET}"
+ fi
+
+ cd "${TARGET}"
+
+ VERSION="$(dpkg-parsechangelog | awk '/^Version: / { print $2 }')"
+
+ SOURCE_VERSION="$(echo ${VERSION} | awk -F: '{ print $2 }')"
+ SOURCE_VERSION="${SOURCE_VERSION:-${VERSION}}"
+
+ UPSTREAM_VERSION="$(echo ${SOURCE_VERSION} | awk -F- '{ $NF=""; print $0 }' | sed -e 's| |-|g' -e 's|-$||')"
+
+ if [ -z "${UPSTREAM_VERSION}" ] && echo "${SOURCE_VERSION}" | grep -qs '+progress[0-9]*'
+ then
+ UPSTREAM_VERSION="$(echo ${SOURCE_VERSION} | awk -F\\+progress '{ print $1 }')"
+ fi
+
+ if [ -z "${UPSTREAM_VERSION}" ] && echo "${SOURCE_VERSION}" | grep -qs '+bfh[0-9]*'
+ then
+ UPSTREAM_VERSION="$(echo ${SOURCE_VERSION} | awk -F\\+bfh '{ print $1 }')"
+ fi
+
+ rm -rf .git
+ mv debian ../
+ cd "${OLDPWD}"
+
+ mv "${TARGET}" "${TARGET}-${UPSTREAM_VERSION}"
+
+ for DISTRIBUTION in engywuck fuchur
+ do
+ if [ ! -e "${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz" ]
+ then
+ wget ${SERVER}/archive/$(echo ${DISTRIBUTION} | cut -d- -f 1)/${PACKAGE}/orig/${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz || true
+ if [ ! -e ${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz ]
+ then
+ wget ${SERVER}/archive/$(echo ${DISTRIBUTION} | cut -d- -f 1)-backports/${PACKAGE}/orig/${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz || true
+ if [ ! -e ${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz ]
+ then
+ wget ${SERVER}/archive/$(echo ${DISTRIBUTION} | cut -d- -f 1)-extras/${PACKAGE}/orig/${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz || true
+ if [ ! -e ${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz ]
+ then
+ wget ${SERVER}/archive/$(echo ${DISTRIBUTION} | cut -d- -f 1)-backports-extras/${PACKAGE}/orig/${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz || true
+ fi
+ fi
+ fi
+ fi
+ done
+
+ if [ ! -e "${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz" ]
+ then
+ echo "Creating ${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz ..."
+ tar cfJ "${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz" "${TARGET}-${UPSTREAM_VERSION}"
+ else
+ echo "Using existing ${TARGET}_${UPSTREAM_VERSION}.orig.tar.xz ..."
+ fi
+
+ mv debian "${TARGET}-${UPSTREAM_VERSION}"
+ dpkg-source -b "${TARGET}-${UPSTREAM_VERSION}"
+
+ rm -rf "${TARGET}-${UPSTREAM_VERSION}"
+ ;;
+
+ binary*)
+ rm -f /tmp/control
+ CONTROL="${REPOSITORY}/plain/debian/control"
+ wget -q ${CONTROL} -O /tmp/control
+
+ case "${BUILD}" in
+ binary-arch)
+ if ! grep -qs "^Architecture:.* any" /tmp/control && \
+ ! grep -qs "^Architecture:.* linux-any" /tmp/control && \
+ ! grep -qs "^Architecture:.* $(dpkg --print-architecture)" /tmp/control
+ then
+ echo "NO BINARY_ARCH, skipping."
+ continue
+ fi
+ ;;
+
+ binary-indep)
+ if ! grep -qs '^Architecture:.*all' /tmp/control
+ then
+ echo "NO BINARY_INDEP, skipping."
+ continue
+ fi
+ ;;
+ esac
+
+ if [ -n "${TAG}" ]
+ then
+ GIT_BRANCH="${TAG}"
+ git clone --branch ${GIT_BRANCH} "${REPOSITORY}" "${TARGET}"
+ else
+ GIT_BRANCH="${BRANCH}"
+ #git clone --depth 1 --no-single-branch --branch ${GIT_BRANCH} "${REPOSITORY}" "${TARGET}"
+ git clone --no-single-branch --branch ${GIT_BRANCH} "${REPOSITORY}" "${TARGET}"
+ fi
+
+ cd "${TARGET}"
+
+ rm -rf .git
+
+ VERSION="$(dpkg-parsechangelog | awk '/^Version: / { print $2 }')"
+
+ SOURCE_VERSION="$(echo ${VERSION} | awk -F: '{ print $2 }')"
+ SOURCE_VERSION="${SOURCE_VERSION:-${VERSION}}"
+
+ UPSTREAM_VERSION="$(echo ${SOURCE_VERSION} | awk -F- '{ $NF=""; print $0 }' | sed -e 's| |-|g' -e 's|-$||')"
+
+ SOURCE="${TARGET}-$(echo ${SOURCE_VERSION} | sed -e 's|~|_|g' -e 's|+|.|g')"
+
+ cd ..
+ mv "${TARGET}" "${SOURCE}"
+ cd "${SOURCE}"
+
+ # disable tests
+ for TARGET in dh_auto_test dh_auto_test-arch dh_auto_test-indep \
+ override_dh_auto_test override_dh_auto_test-arch override_dh_auto_test-indep \
+ execute_before_dh_auto_test execute_before_dh_auto_test-arch execute_before_dh_auto_test-indep \
+ execute_after_dh_auto_test execute_after_dh_auto_test-arch execute_after_dh_auto_test-indep
+ do
+ if grep -qs "^${TARGET}:" debian/rules
+ then
+ sed -i -e "s|^${TARGET}:|disabled_${TARGET}:|" debian/rules
+ else
+ echo "${TARGET}:" >> debian/rules
+ fi
+ done
+
+ case "${INTERACTIVE}" in
+ true)
+ echo "${PROGRAM}: WAITING... "
+ read waiting
+ ;;
+ esac
+
+ case "${BUILD}" in
+ binary-any)
+ dpkg-buildpackage -sa -us -uc
+ ;;
+
+ binary-arch)
+ dpkg-buildpackage -B -us -uc
+ ;;
+
+ binary-indep)
+ dpkg-buildpackage -A -us -uc
+ ;;
+ esac
+
+ cd "${OLDPWD}"
+
+ rm -rf "${SOURCE}"
+ ;;
+ esac
+done