2010-12-30 14:21:49 +00:00
|
|
|
#!/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
|
2012-02-13 07:36:05 +00:00
|
|
|
[ -n "$only_clean_git" ] \
|
|
|
|
&& [ -n "$(git diff --name-only $f)" ] \
|
|
|
|
&& continue
|
|
|
|
[ -d "$f" ] && f="$f/APKBUILD"
|
2010-12-30 14:21:49 +00:00
|
|
|
old=$(do_show "$f")
|
|
|
|
setto=$(($old + 1))
|
|
|
|
do_set "$f" || return 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
do_verify() {
|
|
|
|
[ -n "$force" ] && return 0
|
2012-02-13 07:36:05 +00:00
|
|
|
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
|
2010-12-30 14:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2012-02-13 07:36:05 +00:00
|
|
|
-g Only do the change on files that have clean git status
|
2010-12-30 14:21:49 +00:00
|
|
|
-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=
|
2012-02-13 07:36:05 +00:00
|
|
|
while getopts "afghs:tz" opt; do
|
2010-12-30 14:21:49 +00:00
|
|
|
case $opt in
|
|
|
|
a) cmd=do_add;;
|
2012-02-13 07:36:05 +00:00
|
|
|
g) only_clean_git=1;;
|
2010-12-30 14:21:49 +00:00
|
|
|
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 "$@"
|
|
|
|
|