2010-12-30 14:21:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-07-05 04:21:12 +00:00
|
|
|
# apkgrel - display or bump pkgrel in APKBUILDs
|
|
|
|
# Copyright (c) 2012 Natanael Copa <ncopa@alpinelinux.org>
|
|
|
|
#
|
2020-10-23 14:39:18 +00:00
|
|
|
# Distributed under GPL-2.0-only
|
2013-07-05 04:21:12 +00:00
|
|
|
#
|
|
|
|
|
2013-10-25 07:26:05 +00:00
|
|
|
program_version=@VERSION@
|
2019-11-07 11:28:37 +00:00
|
|
|
sharedir=${ABUILD_SHAREDIR:-@sharedir@}
|
2013-07-05 04:21:16 +00:00
|
|
|
|
2019-11-07 11:21:32 +00:00
|
|
|
if ! [ -f "$sharedir/functions.sh" ]; then
|
|
|
|
echo "$sharedir/functions.sh: not found" >&2
|
2013-07-05 04:21:16 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-11-07 11:21:32 +00:00
|
|
|
. "$sharedir/functions.sh"
|
2013-07-05 04:21:16 +00:00
|
|
|
|
2010-12-30 14:21:49 +00:00
|
|
|
|
2013-07-05 04:21:34 +00:00
|
|
|
show_plain() {
|
|
|
|
# we source the APKBUILD and show last pkgrel that's read
|
|
|
|
# if this script is invoked with --force, this needn't pass "do_verify"
|
|
|
|
( . "$1" && echo "$pkgrel" )
|
|
|
|
}
|
|
|
|
|
|
|
|
show_pretty() {
|
|
|
|
(
|
|
|
|
. "$1" || exit 1
|
2013-07-05 04:21:37 +00:00
|
|
|
[ -n "$pkgname" ] || die "no \$pkgname for $1"
|
2013-07-05 04:21:34 +00:00
|
|
|
printf '%s: r%s\n' "$pkgname" "${pkgrel:-?}"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2010-12-30 14:21:49 +00:00
|
|
|
do_show() {
|
2013-07-05 04:21:34 +00:00
|
|
|
local f=
|
|
|
|
# show_pretty is more informative, but would change the output format of this script
|
|
|
|
for f; do show_plain "$f"; done
|
2010-12-30 14:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_set() {
|
|
|
|
sed -e "/^pkgrel=/s/=.*/=${setto:-0}/" \
|
|
|
|
-i "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
do_add () {
|
|
|
|
local f= old=
|
2013-07-05 04:21:35 +00:00
|
|
|
for f; do
|
2012-02-13 07:36:05 +00:00
|
|
|
[ -n "$only_clean_git" ] \
|
2022-05-13 05:48:15 +00:00
|
|
|
&& [ -n "$(git diff --name-only -- "${f%/*}")" ] \
|
2012-02-13 07:36:05 +00:00
|
|
|
&& continue
|
2013-07-05 04:21:34 +00:00
|
|
|
old=$(show_plain "$f")
|
2013-07-05 04:21:36 +00:00
|
|
|
case $old in
|
|
|
|
[0-9]*) setto=$((old + 1));;
|
|
|
|
*) setto=0;;
|
|
|
|
esac
|
2010-12-30 14:21:49 +00:00
|
|
|
do_set "$f" || return 1
|
2013-07-05 04:21:13 +00:00
|
|
|
done
|
2010-12-30 14:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_verify() {
|
|
|
|
[ -n "$force" ] && return 0
|
2012-02-13 07:36:05 +00:00
|
|
|
local f= rc=0
|
2013-07-05 04:21:35 +00:00
|
|
|
for f; do
|
2012-02-13 07:36:05 +00:00
|
|
|
if ! grep -q '^pkgrel=[0-9]' "$f"; then
|
2013-07-05 04:21:37 +00:00
|
|
|
error "no proper \$pkgrel for $f"
|
2012-02-13 07:36:05 +00:00
|
|
|
rc=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return $rc
|
2010-12-30 14:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_nothing() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-07-05 04:21:19 +00:00
|
|
|
usage() {
|
2022-12-01 16:25:06 +00:00
|
|
|
cat <<-__EOF__
|
2016-08-20 13:16:48 +00:00
|
|
|
$program $program_version - display or bump pkgrel in APKBUILDs
|
2022-12-01 16:25:06 +00:00
|
|
|
usage: $program [-z|--zero] [-a|--add] [-g|--clean-git] [-s|--set NUM]
|
2016-08-20 13:16:48 +00:00
|
|
|
[-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 (implies
|
|
|
|
--add)
|
|
|
|
-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
|
2010-12-30 14:21:49 +00:00
|
|
|
|
2016-08-20 13:16:48 +00:00
|
|
|
__EOF__
|
2010-12-30 14:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd=do_show
|
|
|
|
force=
|
2013-07-05 04:21:19 +00:00
|
|
|
setto=
|
|
|
|
only_clean_git=
|
|
|
|
|
2016-08-20 14:11:44 +00:00
|
|
|
args=$(getopt -o zags:tfqh --long zero,add,clean-git,set:,test,force,quiet,help \
|
|
|
|
-n "$program" -- "$@")
|
2013-07-05 04:21:19 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2022-12-01 16:25:06 +00:00
|
|
|
usage >&2
|
2013-07-05 04:21:19 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
eval set -- "$args"
|
|
|
|
while true; do
|
|
|
|
case $1 in
|
|
|
|
-z|--zero) setto=0; cmd=do_set;;
|
|
|
|
-a|--add) cmd=do_add;;
|
2013-07-05 04:21:33 +00:00
|
|
|
-g|--clean-git) # verify that we're in a git tree
|
|
|
|
git rev-parse 2>/dev/null || die "not in a git tree"
|
|
|
|
cmd=do_add
|
|
|
|
only_clean_git=1;;
|
2013-07-05 04:21:19 +00:00
|
|
|
-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
|
2010-12-30 14:21:49 +00:00
|
|
|
esac
|
2013-07-05 04:21:19 +00:00
|
|
|
shift
|
2010-12-30 14:21:49 +00:00
|
|
|
done
|
|
|
|
if [ $# -eq 0 ]; then
|
2022-12-01 16:25:06 +00:00
|
|
|
usage >&2
|
2013-07-05 04:21:19 +00:00
|
|
|
exit 2
|
2010-12-30 14:21:49 +00:00
|
|
|
fi
|
|
|
|
|
2013-07-05 04:21:38 +00:00
|
|
|
# normalize $@ into paths to APKBUILDs
|
|
|
|
[ "$(echo "$@" | wc -l)" -eq 1 ] || die "can't handle paths with embedded newlines"
|
|
|
|
args=$(for a; do p=$(any_buildscript "$a") || die "can't find APKBUILD for $a"; echo "$p"; done)
|
|
|
|
[ $? -eq 0 ] || exit 1
|
|
|
|
oldifs=$IFS
|
|
|
|
IFS=$'\n'
|
|
|
|
set -- $args
|
|
|
|
IFS=$oldifs
|
|
|
|
|
2010-12-30 14:21:49 +00:00
|
|
|
do_verify "$@" || exit 1
|
|
|
|
$cmd "$@"
|