summaryrefslogtreecommitdiffstats
path: root/bin/pupdate.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbin/pupdate.sh265
1 files changed, 265 insertions, 0 deletions
diff --git a/bin/pupdate.sh b/bin/pupdate.sh
new file mode 100755
index 0000000..463b5af
--- /dev/null
+++ b/bin/pupdate.sh
@@ -0,0 +1,265 @@
+#!/bin/sh
+
+set -e
+
+case "$(basename ${0})" in
+ p*)
+ MODE="progress-linux"
+ ;;
+
+ b*)
+ MODE="bfh"
+ ;;
+esac
+
+case "${MODE}" in
+ progress-linux)
+ DOWNSTREAM_BRANCH="progress-linux"
+ ;;
+
+ bfh)
+ 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"
+
+DSC="${1}"
+
+case "${DSC}" in
+ *.dsc)
+ ;;
+
+ *)
+ echo "Usage: ${0} DSC"
+ exit 1
+ ;;
+esac
+
+case "${DSC}" in
+ http*)
+ DSC_TEMPDIR="$(mktemp -d)"
+
+ cd "${DSC_TEMPDIR}"
+ dget -d "${DSC}"
+ cd "${OLDPWD}"
+
+ DSC="${DSC_TEMPDIR}/$(basename ${DSC})"
+ ;;
+esac
+
+PACKAGE="$(basename ${DSC} | awk -F_ '{ print $1 }')"
+DEB_VERSION="$(awk '/^Version: / { print $2 }' ${DSC})"
+
+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
+
+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 ${DSC} "${TEMPDIR}"
+ rm -rf "${TEMPDIR}/debian"
+ find "${TEMPDIR}" -type d -name ".git" -exec rm -rf {} \; || true
+
+ DEBIAN_TAR="$(dirname $(readlink -f ${DSC}))/$(awk '/debian.tar.*$/ { print $3 }' ${DSC} | 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}
+}
+
+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 ${DSC} ${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
+}
+
+Switch_downstream_branch ()
+{
+ CURRENT_BRANCH="$(git branch --show-current)"
+
+ if [ "${CURRENT_BRANCH}" != "${DOWNSTREAM_BRANCH}" ] && git branch | grep -qs ${DOWNSTREAM_BRANCH}
+ then
+ echo
+ echo "################################################################################"
+ echo "git: switching to downstream branch"
+ echo "################################################################################"
+
+ git checkout ${DOWNSTREAM_BRANCH}
+ fi
+}
+
+Merge_upstream_version ()
+{
+ git cherry-pick -n upstream
+ git commit -a -s -S -m "Merging upstream version ${DEB_UPSTREAM_VERSION}."
+}
+
+Merge_debian_version ()
+{
+ git cherry-pick -n debian
+ git commit -a -s -S -m "Merging debian version ${DEB_VERSION}."
+}
+
+echo "################################################################################"
+echo "git: importing ${DSC}"
+echo "################################################################################"
+
+GIT_UPSTREAM_VERSION="$(git tag | awk -F/ '/^upstream\// { print $2 }' | sort -rV | head -n1 | sed -e 's|%|:|g' -e 's|_|~|g')"
+
+if [ "${DEB_UPSTREAM_VERSION}" != "${GIT_UPSTREAM_VERSION}" ]
+then
+ Switch_upstream_branch
+
+ Remove_everything
+ Unpack_upstream
+ Add_upstream_version
+
+ MERGE_UPSTREAM="true"
+fi
+
+GIT_DEBIAN_VERSION="$(git tag | awk -F/ '/^debian\// { print $2 }' | sort -rV | head -n1 | sed -e 's|%|:|g' -e 's|_|~|g')"
+
+if [ "${DEB_VERSION}" != "${GIT_DEBIAN_VERSION}" ]
+then
+ Switch_debian_branch
+
+ case "${MERGE_UPSTREAM}" in
+ true)
+ Merge_upstream_version
+ ;;
+ esac
+
+ Remove_everything
+ Unpack_debian
+ Add_debian_version
+
+ MERGE_DEBIAN="true"
+fi
+
+if [ -n "${DSC_TEMPDIR}" ]
+then
+ rm -rf "${DSC_TEMPDIR}"
+fi
+
+if [ "${MERGE_DEBIAN}" = "true" ]
+then
+ Switch_downstream_branch
+
+ case "${MERGE_UPSTREAM}" in
+ true)
+ Merge_upstream_version
+ ;;
+ esac
+
+ Merge_debian_version
+fi