diff options
-rwxr-xr-x | upgpkg | 122 |
1 files changed, 90 insertions, 32 deletions
@@ -3,57 +3,115 @@ # 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. +# Edited: Florian Pritz <flo@xinu.at> # I place this script in the public domain. -MYVERSION=0.1 -PROGNAME="upgpkg" +VERSION=0.4 -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 +# from makepkg +unset ALL_OFF BOLD BLUE GREEN RED YELLOW +if [[ -t 2 ]]; then + # prefer terminal safe colored and bold text when tput is supported + if tput setaf 0 &>/dev/null; then + ALL_OFF="$(tput sgr0)" + BOLD="$(tput bold)" + BLUE="${BOLD}$(tput setaf 4)" + GREEN="${BOLD}$(tput setaf 2)" + RED="${BOLD}$(tput setaf 1)" + YELLOW="${BOLD}$(tput setaf 3)" + else + ALL_OFF="\033[1;0m" + BOLD="\033[1;1m" + BLUE="${BOLD}\033[1;34m" + GREEN="${BOLD}\033[1;32m" + RED="${BOLD}\033[1;31m" + YELLOW="${BOLD}\033[1;33m" + fi fi +readonly ALL_OFF BOLD BLUE GREEN RED YELLOW die() { local message="$1" shift - printf "$message" "$@" + printf "$RED==> $(gettext "Error"):$ALL_OFF $(gettext "$message")\n" "$@" 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" +warn() { + local message="$1" + shift + printf "$YELLOW==> $(gettext "Warning"):$ALL_OFF $(gettext "$message")\n" "$@" +} + +scriptlet() { + if [ -f "upgpkg" ]; then + if [[ $(type -t upgpkg_$1) = "function" ]]; then + upgpkg_$1 || die "\"%s\" scriptlet failed" $1 + fi + fi +} + +help() { + echo "upgpkg $VERSION" + printf "$(gettext "usage: upgpkg [options] newver")\n" + printf "$(gettext " -h this help")\n" + printf "$(gettext " -g generate a template ./upgpkg file")\n" + exit 2 +} + +if [ -z "$1" ]; then + help fi -if [ -z "$BASEDIR" ]; then die "$(gettext "upgpkg: unable to locate BASEDIR in configuration.")"; fi +while getopts "gh" OPTION; do + case $OPTION in + g) + cat > upgpkg <<EOF +upgpkg_pre_upgrade() { + # You might want to remove old sources here + true +} -if [ -z "$1" ]; then printf "upgpkg %s\n" "$MYVERSION"; printf "$(gettext "usage: upgpkg package-name newver\n")"; exit; fi +upgpkg_build() { + makepkg +} +EOF + exit; + ;; + h) help; + esac +done -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 +[ ! -f PKGBUILD ] && die "No \"%s\" in %s" "PKGBUILD" "$PWD" -# Main code follows +if [ -f "upgpkg" ]; then + source ./upgpkg +fi -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" +scriptlet pre_upgrade + +if [[ $(vercmp $1 $pkgver) -le 0 ]]; then + warn "New version (%s) older or equal to current %s" "$1" "$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" + +sed -i "s/pkgver=.*$/pkgver=$1/g" PKGBUILD +sed -i "s/pkgrel=.*$/pkgrel=1/g" PKGBUILD +awk <PKGBUILD '$0 ~ /^(md5|sha[0-9]+)sums/ {i = 1; if(!run==1) {system("makepkg -g 2>/dev/null")}; run=1; }; !i {print}; $0 ~ /\)/ {i = 0}' | sponge PKGBUILD + +source PKGBUILD +if [ -f "upgpkg" ]; then + source ./upgpkg fi + +for i in $gpgsource; do + sigfile="$(basename "$i")" + if [[ $sigfile != $i ]]; then + wget -nv -O "$sigfile" "$i" + fi + gpg2 --verify "$sigfile" || die "Signature verification failed!" +done + +scriptlet build |