Skip to content

Commit

Permalink
xxadopt: add -o flag to orphan
Browse files Browse the repository at this point in the history
  • Loading branch information
Piraty committed Mar 18, 2024
1 parent ddb0e15 commit 35e6490
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions xxadopt
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
#!/bin/sh
# xxadopt [-f] PKG.. - adopt packages

[ "$1" = "-f" ] && _force=1 && shift || _force=0

if [ "$#" -lt 1 ] ; then
printf 'Usage: %s [-f] PKG..\n' "$(basename "$0")" >&2
exit 1
# xxadopt [-f|-o] PKG.. - adopt packages
#
# -f : (force) adopt even if it's not orphaned
# -o : orphan the package

set -eu

_force=
_orphan=
if [ "$1" = "-f" ]; then
_force=1
shift
elif [ "$1" = "-o" ]; then
_orphan=1
shift
fi

cd "$(xdistdir)" || exit 1
cd "$(xdistdir)"

# make sure all templates exist
templates=
fail=
for pkg in "$@" ; do
if [ -f "srcpkgs/$pkg/template" ] ; then
for pkg in "$@"; do
if [ -f "srcpkgs/$pkg/template" ]; then
t="srcpkgs/$pkg/template"
elif [ -f "$pkg/template" ] ; then
elif [ -f "$pkg/template" ]; then
t="$pkg/template"
elif [ -f "$pkg" ] ; then
elif [ -f "$pkg" ]; then
t="$pkg"
else
printf 'ERROR: could not find template for: %s\n' "$pkg" 2>&1
Expand All @@ -29,21 +37,27 @@ for pkg in "$@" ; do
done
[ -n "$fail" ] && exit 1

if [ "$_orphan" ]; then
new_maintainer="Orphaned <[email protected]>"
else
new_maintainer="$(git config user.name) <$(git config user.email)>"
fi

# patch templates
for t in $templates ; do
for t in $templates; do
pkg="$(printf '%s' "$t" | cut -d/ -f2)"

if [ "$_force" = "0" ] && ! grep -q -i "^maintainer=.*orphan@voidlinux.*" "$t" ; then
printf -- 'Skipping package (not orphaned): %s\n' "$pkg" >&2
if [ -z "$_force" ] && [ -z "$_orphan" ] && ! grep -q -i "^maintainer=.*orphan@voidlinux.*" "$t"; then
printf -- 'Skip package (not orphaned): %s\n' "$pkg" >&2
continue
fi

hash_pre="$(md5sum "$t")"
sed -i "$t" \
-e "/^maintainer=/s/=.*/=\"$(git config user.name) <$(git config user.email)>\"/"
-e "/^maintainer=/s/=.*/=\"${new_maintainer}\"/"
hash_post="$(md5sum "$t")"

[ "$hash_pre" != "$hash_post" ] && \
printf -- 'Package adopted: %s\n' "$pkg" || \
printf -- 'Package remains unchanged: %s\n' "$pkg" >&2
[ "$hash_pre" != "$hash_post" ] &&
printf -- 'Changed: %s (%s)\n' "$pkg" "$new_maintainer" ||
printf -- 'Unchanged: %s\n' "$pkg" >&2
done

0 comments on commit 35e6490

Please sign in to comment.