#!/bin/sh set -e case "$(basename ${0})" in d*) MODE="debian" ;; p*) MODE="progress-linux" ;; b*) MODE="bfh" ;; esac case "${MODE}" in debian) DOWNSTREAM_BRANCH="" ;; progress-linux) MAINTAINER="Progress Linux Maintainers " UPLOADERS="Daniel Baumann " BUGS="mailto:maintainers@lists.progress-linux.org" if echo ${PWD} | grep -qs engywuck-backports then VCS_BROWSER="https://git.progress-linux.org/packages/engywuck-backports" VCS_GIT="https://git.progress-linux.org/packages/engywuck-backports" elif echo ${PWD} | grep -qs fuchur-backports then VCS_BROWSER="https://git.progress-linux.org/packages/fuchur-backports" VCS_GIT="https://git.progress-linux.org/packages/fuchur-backports" elif echo ${PWD} | grep -qs graograman-backports then VCS_BROWSER="https://git.progress-linux.org/packages/graograman-backports" VCS_GIT="https://git.progress-linux.org/packages/graograman-backports" elif echo ${PWD} | grep -qs engywuck then VCS_BROWSER="https://git.progress-linux.org/packages/engywuck" VCS_GIT="https://git.progress-linux.org/packages/engywuck" elif echo ${PWD} | grep -qs fuchur then VCS_BROWSER="https://git.progress-linux.org/packages/fuchur" VCS_GIT="https://git.progress-linux.org/packages/fuchur" elif echo ${PWD} | grep -qs graograman then VCS_BROWSER="https://git.progress-linux.org/packages/graograman" VCS_GIT="https://git.progress-linux.org/packages/graograman" else echo "NO VCS detection" exit 1 fi DOWNSTREAM_BRANCH="progress-linux" ;; bfh) MAINTAINER="Team Linux \& Infrastructure Services " UPLOADERS="Daniel Baumann " BUGS="mailto:bfh-linux-users@lists.bfh.science" VCS_BROWSER="https://git.bfh.science/packages/buster-backports" VCS_GIT="https://git.bfh.science/packages/buster-backports" DOWNSTREAM_BRANCH="bfh" ;; esac RED="\033[1;33;31m" GREEN="\033[1;33;32m" YELLOW="\033[1;33;33m" BLUE="\033[1;33;34m" WHITE="\033[1;33;37m" NORMAL="\033[0m" PURPLE="\033[1;33;35m" IMPORT="${1}" case "${IMPORT}" in *.dsc|*.debian.tar.*) ;; *) echo "Usage: ${0} *.dsc" echo "Usage: ${0} debian.tar.*" exit 1 ;; esac case "${IMPORT}" in http*) IMPORT_TEMPDIR="$(mktemp -d)" cd "${IMPORT_TEMPDIR}" case "${IMPORT}" in *.dsc) dget -d "${IMPORT}" ;; *) wget "${IMPORT}" ;; esac cd "${OLDPWD}" IMPORT="${IMPORT_TEMPDIR}/$(basename ${IMPORT})" ;; esac PACKAGE="$(basename ${IMPORT} | awk -F_ '{ print $1 }')" case "${IMPORT}" in *.dsc) DEB_VERSION="$(awk '/^Version: / { print $2 }' ${IMPORT})" case "${DEB_VERSION}" in *-*) DEB_UPSTREAM_VERSION="$(echo ${DEB_VERSION} | awk -F- '{ $NF=""; print $0 }' | sed -e 's| |-|g' -e 's|-$||g')" ;; *) DEB_UPSTREAM_VERSION="${DEB_VERSION}" ;; esac ;; esac Add_initial_commit () { if [ ! -e .git ] then git init --shared fi if ! git log > /dev/null 2>&1 then echo echo "################################################################################" echo "git: adding initial commit" echo "################################################################################" git commit -a -s -S -m "Initial commit." --allow-empty fi } Create_upstream_branch () { CURRENT_BRANCH="$(git branch --show-current)" case "${CURRENT_BRANCH}" in master|main) if ! git branch | grep -qs upstream then echo echo "################################################################################" echo "git: adding upstream branch" echo "################################################################################" git branch -m ${CURRENT_BRANCH} upstream fi ;; esac } Switch_upstream_branch () { CURRENT_BRANCH="$(git branch --show-current)" if [ "${CURRENT_BRANCH}" != "upstream" ] && git branch | grep -qs upstream then echo echo "################################################################################" echo "git: switching to upstream branch" echo "################################################################################" git checkout upstream fi } Remove_everything () { echo echo "################################################################################" echo "git: removing all files" echo "################################################################################" echo -n "Removing files for new import..." find . -maxdepth 1 -mindepth 1 -and -not -name .git -print0 | xargs -0 -I '{}' rm -rf '{}' echo " done." } Unpack_upstream () { echo echo "################################################################################" echo "dpkg: unpacking upstream files" echo "################################################################################" TEMPDIR="$(mktemp -d -p . -u)" dpkg-source -x --no-copy --skip-debianization ${IMPORT} "${TEMPDIR}" rm -rf "${TEMPDIR}/debian" find "${TEMPDIR}" -type d -name ".git" -exec rm -rf {} \; || true DEBIAN_TAR="$(dirname $(readlink -f ${IMPORT}))/$(awk '/debian.tar.*$/ { print $3 }' ${IMPORT} | head -n1)" case "${DEBIAN_TAR}" in *.debian.tar.*) if [ -e "${DEBIAN_TAR}" ] then # this includes upstream additions outside debian/ into the upstream branch cd "${TEMPDIR}" tar xf "${DEBIAN_TAR}" rm -rf debian rm -rf .git cd "${OLDPWD}" fi ;; esac find "${TEMPDIR}" -maxdepth 1 -mindepth 1 -print0 | xargs -0 -I '{}' mv '{}' . rmdir "${TEMPDIR}" } Add_upstream_version () { echo echo "################################################################################" echo "git: adding upstream version" echo "################################################################################" # FIXME git-upstream-add ${DEB_UPSTREAM_VERSION} } Create_debian_branch () { echo echo "################################################################################" echo "git: creating debian branch" echo "################################################################################" CURRENT_BRANCH="$(git branch --show-current)" if [ "${CURRENT_BRANCH}" = "upstream" ] && ! git branch | grep -qs debian then git branch debian fi } Switch_debian_branch () { CURRENT_BRANCH="$(git branch --show-current)" if [ "${CURRENT_BRANCH}" != "debian" ] && git branch | grep -qs debian then echo echo "################################################################################" echo "git: switching to debian branch" echo "################################################################################" git checkout debian fi } Unpack_debian () { echo echo "################################################################################" echo "dpkg: unpacking debian files" echo "################################################################################" TEMPDIR="$(mktemp -d -p . -u)" dpkg-source -x --no-copy --skip-patches ${IMPORT} ${TEMPDIR} find "${TEMPDIR}" -type d -name ".git" -exec rm -rf {} \; || true find "${TEMPDIR}" -maxdepth 1 -mindepth 1 -print0 | xargs -0 -I '{}' mv '{}' . rmdir ${TEMPDIR} } Add_debian_version () { echo echo "################################################################################" echo "git: adding debian version" echo "################################################################################" # FIXME git-debian-add } Create_downstream_branch () { echo echo "################################################################################" echo "git: create ${DOWNSTREAM_BRANCH} branch" echo "################################################################################" CURRENT_BRANCH="$(git branch --show-current)" if [ "${CURRENT_BRANCH}" = "debian" ] && ! git branch | grep -qs ${DOWNSTREAM_BRANCH} then git checkout -b ${DOWNSTREAM_BRANCH} fi } Update_maintainer_field () { if [ -e debian/templates/control.source.in ] then CONTROL="debian/templates/control.source.in" elif [ -e debian/control.in ] then CONTROL="debian/control.in" else CONTROL="debian/control" fi if ! grep -qs "^XSBC-Original-Maintainer: ${MAINTAINER}$" "${CONTROL}" then echo echo "################################################################################" echo "git: updating maintainer field" echo "################################################################################" if grep -qs "^Uploaders:" "${CONTROL}" then # sorting maintainer and uploaders fields ORIGINAL_MAINTAINER="$(grep '^Maintainer:' ${CONTROL})" # remove original maintainer field TEMPFILE="$(mktemp -p .)" grep -v "^Maintainer:" "${CONTROL}" > "${TEMPFILE}" rm -f "${CONTROL}" mv "${TEMPFILE}" "${CONTROL}" # readd original maintainer field sed -i -e "s|^\(Uploaders.*\)$|${ORIGINAL_MAINTAINER}\n\1|" \ "${CONTROL}" fi sed -i -e "s|^Maintainer:|Maintainer: ${MAINTAINER}\nXSBC-Original-Maintainer:|" "${CONTROL}" git commit -a -s -S -m "Updating maintainer field." fi if [ -n "$(grep -s -r "^Maintainer:" debian | grep -v ^debian\/control)" ] then echo "WARNING: additional 'Maintainer:' fields outside debian/control{,.in} found!" fi } Update_uploaders_field () { if [ -e debian/templates/control.source.in ] then CONTROL="debian/templates/control.source.in" elif [ -e debian/control.in ] then CONTROL="debian/control.in" else CONTROL="debian/control" fi # FIXME: single uploader on one line, no multi-line if ! grep -qs "^XSBC-Uploaders: ${UPLOADERS}$" "${CONTROL}" then echo echo "################################################################################" echo "git: updating uploaders field" echo "################################################################################" sed -i -e "s|^\(Maintainer:.*$\)|\1\nXSBC-Uploaders: ${UPLOADERS}|" \ -e "s|^Uploaders:|XSBC-Original-Uploaders:|" \ "${CONTROL}" git commit -a -s -S -m "Updating uploaders field." fi if [ -n "$(grep -s -r "^Uploaders:" debian | grep -v ^debian\/control)" ] then echo "WARNING: additional 'Uploaders:' fields outside debian/control{,.in} found!" fi } Update_bugs_field () { if [ -e debian/templates/control.source.in ] then CONTROL="debian/templates/control.source.in" elif [ -e debian/control.in ] then CONTROL="debian/control.in" else CONTROL="debian/control" fi if ! grep -qs "^Bugs: ${BUGS}$" "${CONTROL}" then echo echo "################################################################################" echo "git: updating bugs field" echo "################################################################################" # remove original bugs fields TEMPFILE="$(mktemp -p .)" grep -v "^Bugs:" "${CONTROL}" > "${TEMPFILE}" rm -f "${CONTROL}" mv "${TEMPFILE}" "${CONTROL}" # add new bugs field if grep -qs "^XSBC-Original-Uploaders:" "${CONTROL}" then NEXT_FIELD_AFTER_UPLOADERS="$(grep -v '^ ' ${CONTROL} | grep -v '^ ' | grep -A1 -m1 '^XSBC-Original-Uploaders:' | tail -n1 | awk -F: '{ print $1 }')" else NEXT_FIELD_AFTER_UPLOADERS="$(grep -v '^ ' ${CONTROL} | grep -v '^ ' | grep -A1 -m1 '^XSBC-Original-Maintainer:' | tail -n1 | awk -F: '{ print $1 }')" fi case "${NEXT_FIELD_AFTER_UPLOADERS}" in Package:*) LAST_LINE_OF_SOURCE_BLOCK="$(grep -B2 -m1 '^Package:' ${CONTROL} | head -n1)" sed -i -e "s|\(^${LAST_LINE_OF_SOURCE_BLOCK}$\)|\1\nBugs: ${BUGS}|" \ "${CONTROL}" ;; *) sed -i -e "s|^\(${NEXT_FIELD_AFTER_UPLOADERS}\)|Bugs: ${BUGS}\n\1|" \ "${CONTROL}" ;; esac git commit -a -s -S -m "Updating bugs field." if [ $(grep -c "^Bugs:" ${CONTROL}) -gt 1 ] then echo "WARNING: duplicates of 'Bugs:' fields in debian/control{,.in} found!" fi fi } Update_vcs_fields () { if [ -e debian/templates/control.source.in ] then CONTROL="debian/templates/control.source.in" elif [ -e debian/control.in ] then CONTROL="debian/control.in" else CONTROL="debian/control" fi if ! grep -qs "^Vcs-Browser: ${VCS_BROWSER}/${PACKAGE}$" "${CONTROL}" && \ ! grep -qs "^Vcs-Git: ${VCS_BROWSER}/${PACKAGE}$" "${CONTROL}" then echo echo "################################################################################" echo "git: updating vcs fields" echo "################################################################################" sed -i -e 's|^Vcs-browser|Vcs-Browser|' \ -e 's|^Vcs-git|Vcs-Git|' \ "${CONTROL}" # replace original vcs fields sed -i -e 's|^Vcs-|XSBC-Original-Vcs-|g' \ "${CONTROL}" if ! grep -qs "^XSBC-Original-Vcs-" "${CONTROL}" then # no vcs in original file LAST_LINE_OF_SOURCE_BLOCK="$(grep -B2 -m1 '^Package:' ${CONTROL} | head -n1)" sed -i -e "s|\(^${LAST_LINE_OF_SOURCE_BLOCK}.*$\)|\1\nVcs-Browser: ${VCS_BROWSER}/${PACKAGE}\nVcs-Git: ${VCS_GIT}/${PACKAGE}|" \ "${CONTROL}" else # vcs fields in original file ORIGINAL_VCS_BROWSER="$(grep '^XSBC-Original-Vcs-Browser' ${CONTROL})" TEMPFILE="$(mktemp -p . -u)" grep -v "^XSBC-Original-Vcs-Browser" "${CONTROL}" > "${TEMPFILE}" rm -f "${CONTROL}" mv "${TEMPFILE}" "${CONTROL}" # FIXME: handle cases where only Vcs-Browser is there, but no Vcs-Git ORIGINAL_VCS_OTHER="$(grep '^XSBC-Original-Vcs' ${CONTROL})" sed -i -e "s|^\(XSBC-Original-Vcs-.*\)$|Vcs-Browser: ${VCS_BROWSER}/${PACKAGE}\nVcs-Git: ${VCS_GIT}/${PACKAGE}\n${ORIGINAL_VCS_BROWSER}\n\1|" \ "${CONTROL}" fi fi if [ -n "$(git status --porcelain)" ] then git commit -a -s -S -m "Updating vcs fields." fi } Update_source_format () { if ! grep -qs '^3.0 (quilt)' debian/source/format then echo echo "################################################################################" echo "git: updating source format" echo "################################################################################" mkdir -p debian/source echo "3.0 (quilt)" > debian/source/format git add . git commit -a -s -S -m "Updating source format." fi } echo "################################################################################" echo "git: importing ${IMPORT}" echo "################################################################################" case "${IMPORT}" in *.debian.tar.*) git checkout debian rm -rf debian tar xf ${IMPORT_TEMPDIR}/*.debian.tar.* git-debian-add git checkout - rm -rf "${IMPORT_TEMPDIR}" exit 0 ;; esac Add_initial_commit Create_upstream_branch Switch_upstream_branch Remove_everything Unpack_upstream Add_upstream_version Create_debian_branch Switch_debian_branch Remove_everything Unpack_debian Add_debian_version if [ -n "${IMPORT_TEMPDIR}" ] then rm -rf "${IMPORT_TEMPDIR}" fi # progress-linux / bfh if [ -n "${DOWNSTREAM_BRANCH}" ] then Create_downstream_branch Update_maintainer_field Update_uploaders_field Update_bugs_field Update_vcs_fields Update_source_format if [ -e debian/control.in ] || [ -e debian/templates/control.source.in ] || [ -e debian/control.md5sum ] then echo "################################################################################" echo "${RED}WARNING:${NORMAL} debian/control.in exists," echo "likely the debian files need to be regenerated (manually)." echo "################################################################################" fi if [ "$(grep -rs '^Maintainer:' debian | wc -l )" -gt 1 ] then echo "################################################################################" echo "${RED}WARNING:${NORMAL} more than one Maintainer field exists," echo "likely further debian files need to be changed (manually)." echo "################################################################################" fi fi