summaryrefslogtreecommitdiffstats
path: root/upgpkg
diff options
context:
space:
mode:
Diffstat (limited to 'upgpkg')
-rwxr-xr-xupgpkg59
1 files changed, 59 insertions, 0 deletions
diff --git a/upgpkg b/upgpkg
new file mode 100755
index 0000000..0a2b203
--- /dev/null
+++ b/upgpkg
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# upgpkg: Upgrades package versions in PKGBUILD and starts build.
+# Author: Abhishek Dasgupta <abhidg@gmail.com>
+# Thanks to cactus, profjim and daenyth for all the sed help!
+# Requires: pkgtools.
+
+# I place this script in the public domain.
+
+MYVERSION=0.1
+PROGNAME="upgpkg"
+
+if [ -r /usr/share/pkgtools/functions ]; then
+ source /usr/share/pkgtools/functions
+else
+ printf "$(gettext "upgpkg: Unable to source function file!\n")" >&2
+ exit 1
+fi
+
+die() {
+ local message="$1"
+ shift
+ printf "$message" "$@"
+ exit 1
+}
+
+if [ -r /etc/pkgtools/newpkg.conf ]; then
+ source /etc/pkgtools/newpkg.conf
+fi
+if [ -r "${HOME}/.pkgtools/newpkg.conf" ]; then
+ source "${HOME}/.pkgtools/newpkg.conf"
+fi
+
+if [ -z "$BASEDIR" ]; then die "$(gettext "upgpkg: unable to locate BASEDIR in configuration.")"; fi
+
+if [ -z "$1" ]; then printf "upgpkg %s\n" "$MYVERSION"; printf "$(gettext "usage: upgpkg package-name newver\n")"; exit; fi
+
+if [ ! -d "$BASEDIR/$1" ]; then die "$(gettext "upgpkg: package %s not in %s.\n")" "$1" "$BASEDIR"; fi
+if [ -z "$2" ]; then die "$(gettext "upgpkg: no new version specified for %s\n")" "$1"; fi
+
+# Main code follows
+
+cd "$BASEDIR/$1"
+sed -ri '/md5sums[ ]?\=/{:a; /\)/d; N; ba;}' PKGBUILD || die "upgpkg: could not bump pkgver of $1\n"
+source PKGBUILD
+
+if [ $(vercmp $2 $pkgver) -gt 0 ]; then
+ sed -i "s/pkgver=.*$/pkgver=$2/g" PKGBUILD
+ sed -i "s/pkgrel=.*$/pkgrel=1/g" PKGBUILD
+ makepkg -g >> PKGBUILD
+else
+ die "$(gettext "upgpkg: %s - new version (%s) older or equal to current %s\n")" "$1" "$2" "$pkgver"
+fi
+makepkg -m
+if [ $? -gt 0 ]; then
+ sed -i "s/pkgver=.*$/pkgver=$pkgver/g" PKGBUILD
+ sed -i "s/pkgrel=.*$/pkgrel=$pkgrel/g" PKGBUILD
+ die "$(gettext "upgpkg: %s - build failed for %s, reverting to %s\n")" "$1" "$2" "$pkgver"
+fi