#!/bin/sh
. /usr/share/mgatools/functions
if [ $# != 4 ]
then
echo 'Usage: mga-move-backports-sync-mail distrorelease section srcname bugnumber' >&2
exit 1
fi
distrorelease="$1"
section="$2"
srcname="$3"
bugnumber="$4"
export SIG="https://bugs.mageia.org/show_bug.cgi?id=$4"
if ! inlist "$distrorelease" "$distroreleases"
then
echo "Incorrect distrorelease $distrorelease" >&2
exit 1
fi
if ! inlist "$section" "$distrosections"
then
echo "Incorrect section $section" >&2
exit 1
fi
for file in "$distribdir/$distrorelease/SRPMS/$section/backports_testing/"*.rpm
do
fname=$(rpm -qp --qf '%{NAME}' "$file")
if [ a"$fname" = a"$srcname" ]
then
srcpkg=$(basename "$file")
break
fi
done
if [ -z $srcpkg ]
then
echo "The package $srcname could not be found in $distrorelease/$section/backports_testing repository." >&2
exit 2
fi
# safety check
echo " This SRPM (and matching binarys) will be moved from backports_testing to backports: $srcpkg" >&2
read -p " Are you sure ? " yn >&2
case $yn in
[Yy]* ) continue;;
* ) exit;;
esac
function movepkg()
{
srcdir="$1"
destdir="$2"
srcpkg="$3"
output="$4"
for file in "$srcdir/"*.rpm
do
fname=$(rpm -qp --qf '%{SOURCERPM}' "$file")
if [ a"$fname" = a"$srcpkg" ]
then
$dryrun mv -v -f "$file" "$destdir" >> "$output"
echo "$(basename $file)
"
fi
done
}
echo ""
echo "moving binary and source rpms:"
mailcontent=$(mktemp)
for arch in $arches
do
echo ""
echo "$arch:
"
movepkg "$distribdir/$distrorelease/$arch/media/$section/backports_testing" "$distribdir/$distrorelease/$arch/media/$section/backports/" "$srcpkg" "$mailcontent"
movepkg "$distribdir/$distrorelease/$arch/media/debug/$section/backports_testing" "$distribdir/$distrorelease/$arch/media/debug/$section/backports/" "$srcpkg" "$mailcontent"
done
echo ""
echo "SRPMS:
"
echo "$srcpkg
"
echo ""
$dryrun mv -v -f "$distribdir/$distrorelease/SRPMS/$section/backports_testing/$srcpkg" "$distribdir/$distrorelease/SRPMS/$section/backports/" >> "$output"
$
mutt -e 'set from="Mageia Backports "' \
-e 'set signature="echo $SIG|"' \
-e 'set sig_dashes=no' \
backports-announce@ml.mageia.org -s "Package backport: Mga $1/$2: $3" \
-i $mailcontent
rm -f "$mailcontent"