#!/bin/sh # Copyright (C) 2015 Daniel Baumann # # 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 . 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="auto,build:,distribution:,interactive,nocheck,package:,tag:,upload," OPTIONS="a,b:,d:,i,n,p:,t:,u," 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 -a|--auto) AUTO="true" shift 1 ;; -b|--build) BUILD="${2}" shift 2 ;; -d|--distribution) DISTRIBUTION="${2}" shift 2 ;; -i|--interactive) INTERACTIVE="true" shift 1 ;; -n|--nocheck) NOCHECK="true" shift 1 ;; -p|--package) PACKAGE="$(echo ${2} | sed -e 's|/$||g')" shift 2 ;; -t|--tag) TAG="${2}" shift 2 ;; -u|--upload) UPLOAD="true" shift ;; --) 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[,TAG,...]" >&2 exit 1 fi INTERACTIVE="${INTERACTIVE:=false}" if [ -e "${PACKAGE}" ] then echo "${PACKAGE}: directory already exists" exit 1 fi TAGS="$(echo ${TAG} | sed -e 's|,| |g')" 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 TAG in ${TAGS} HEAD do # if no tag is specified, build head. # if a tag is specified, don't (additionally) build head if [ "${TAG}" = "HEAD" ] then if [ -z "${TAGS}" ] then TAG="" else continue fi fi 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}" # upload case "${UPLOAD}" in true) FILES="$(sed -e '1,/^Files:$/ d' ${TARGET}_${SOURCE_VERSION}.dsc | sed -e '/^[0-1a-zA-Z]/,$d' | awk '{ print $3 }')" rsync -aP "${FILES}" ${TARGET}_${SOURCE_VERSION}.dsc apt.progress-linux.org::upload rm -f "${FILES}" ${TARGET}_${SOURCE_VERSION}.dsc ;; esac ;; 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}" case "${NOCHECK}" in true) # disable tests for RULE 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 "^${RULE}:" debian/rules then sed -i -e "s|^${RULE}:|disabled_${RULE}:|" debian/rules else echo "${RULE}:" >> debian/rules fi done ;; esac case "${AUTO}" in true) case "${DISTRIBUTION}" in engywuck-backports) if grep -qs 'debhelper (>= 13' debian/control || \ grep -qs 'debhelper-compat (= 13' debian/control then sudo apt install -t engywuck-backports -y debhelper fi ;; esac sudo apt build-dep -y . ;; esac 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}" # upload case "${UPLOAD}" in true) FILES="$(sed -e '1,/^Files:$/ d' ${TARGET}_${SOURCE_VERSION}_*.changes | sed -e '/^[0-1a-zA-Z]/,$d' | awk '{ print $5 }')" rsync -aP "${FILES}" ${TARGET}_${SOURCE_VERSION}_*.changes rm -f "${FILES}" ${TARGET}_${SOURCE_VERSION}_*.changes ;; esac ;; esac done done