blob: 57b3b93ff448378d70f5526ef059b432cd13b555 (
plain) (
tree)
|
|
#!/bin/sh
# apkgrel - display or bump pkgrel in APKBUILDs
# Copyright (c) 2012 Natanael Copa <ncopa@alpinelinux.org>
#
# Distributed under GPL-2
#
abuild_ver=@VERSION@
datadir=@datadir@
if ! [ -f "$datadir/functions.sh" ]; then
echo "$datadir/functions.sh: not found" >&2
exit 1
fi
. "$datadir/functions.sh"
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
[ -n "$only_clean_git" ] \
&& [ -n "$(git diff --name-only $f)" ] \
&& continue
[ -d "$f" ] && f="$f/APKBUILD"
old=$(do_show "$f")
setto=$(($old + 1))
do_set "$f" || return 1
done
}
do_verify() {
[ -n "$force" ] && return 0
local f= rc=0
for f in "$@"; do
[ -d "$f" ] && f="$f/APKBUILD"
if ! grep -q '^pkgrel=[0-9]' "$f"; then
echo "$f: Has no proper pkgrel" >&2
rc=1
fi
done
return $rc
}
do_nothing() {
return 0
}
usage() {
cat >&2 <<__EOF__
$prog $abuild_ver - display or bump pkgrel in APKBUILDs
Usage: $prog [-z|--zero] [-a|--add] [-g|--clean-git] [-s|--set NUM] [-t|--test] [-f|--force] DIR or APKBUILD...
Options:
-z, --zero Set pkgrel to 0
-a, --add Add 1 to current pkgrel
-g, --clean-git Only operate on APKBUILDs with clean git status
-s, --set NUM Set pkgrel to NUM
-t, --test Only verify that files have a valid pkgrel
-f, --force Operate on files without a valid pkgrel
-h, --help Show this help
__EOF__
}
cmd=do_show
force=
setto=
only_clean_git=
args=`getopt -o zags:tfqh --long zero,add,clean-git,set:,test,force,quiet,help -n "$prog" -- "$@"`
if [ $? -ne 0 ]; then
usage
exit 2
fi
eval set -- "$args"
while true; do
case $1 in
-z|--zero) setto=0; cmd=do_set;;
-a|--add) cmd=do_add;;
-g|--clean-git) only_clean_git=1;;
-s|--set) setto=$2; shift; cmd=do_set;;
-t|--test) cmd=do_nothing;;
-f|--force) force=1;;
-q|--quiet) quiet=1;; # noop
-h|--help) usage; exit;;
--) shift; break;;
*) exit 1;; # getopt error
esac
shift
done
if [ $# -eq 0 ]; then
usage
exit 2
fi
do_verify "$@" || exit 1
$cmd "$@"
|