diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2010-12-30 14:21:49 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2010-12-30 14:21:49 +0000 |
commit | dfac60a00be55a059b6883d7ba1182b8496297d7 (patch) | |
tree | b51689eeed1c8366a50a3c2a3369b8bf50c543a3 /apkgrel.in | |
parent | 21730b7864253f4da7bc35ad544693b193ace8f3 (diff) | |
download | abuild-dfac60a00be55a059b6883d7ba1182b8496297d7.tar.gz abuild-dfac60a00be55a059b6883d7ba1182b8496297d7.tar.bz2 abuild-dfac60a00be55a059b6883d7ba1182b8496297d7.tar.xz abuild-dfac60a00be55a059b6883d7ba1182b8496297d7.zip |
apkgrel: new tool for bumping pkgrel
Diffstat (limited to 'apkgrel.in')
-rw-r--r-- | apkgrel.in | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/apkgrel.in b/apkgrel.in new file mode 100644 index 0000000..b07f8bd --- /dev/null +++ b/apkgrel.in @@ -0,0 +1,75 @@ +#!/bin/sh + +program=${0##*/} + +do_show() { + awk -F= '$1 == "pkgrel" { print $2 }' "$@" +} + +do_set() { + sed -e "/^pkgrel=/s/=.*/=${setto:-0}/" \ + -i "$@" +} + +do_add () { + local f= old= + for f in "$@"; do + old=$(do_show "$f") + setto=$(($old + 1)) + do_set "$f" || return 1 + done +} + +do_verify() { + [ -n "$force" ] && return 0 + if ! grep -q '^pkgrel=[0-9]' "$@"; then + echo "The following files does not have proper pkgrel:" >&2 + grep -L '^pkgrel=[0-9]' "$@" >&2 + return 1 + fi + return 0 +} + +do_nothing() { + return 0 +} + +do_usage() { + cat <<__EOF__ +Usage: $program -a|-h|-s NUM|-t|-z [-f] FILE... +Commands: + -a Add 1 to current pkgrel + -h Show this help + -s Set pkgrel to NUM + -t Only verify that files are in proper format + -z Set pkgrel to 0 + +Options: + -f Force, even if given files are not in proper format + +__EOF__ +} + +cmd=do_show +force= +while getopts "afhs:tz" opt; do + case $opt in + a) cmd=do_add;; + f) force=1;; + h) cmd=do_usage;; + s) setto=$OPTARG; cmd=do_set;; + t) cmd=do_nothing;; + z) setto=0; cmd=do_set;; + esac +done + +shift $(( $OPTIND - 1)) + +if [ $# -eq 0 ]; then + do_usage + exit 1 +fi + +do_verify "$@" || exit 1 +$cmd "$@" + |