#!/bin/sh set -e . /usr/share/mgatools/functions if [ "$1" = "--dry-run" ]; then dryrun=echo shift fi sync= if [ "$1" = "--sync" ]; then sync=yes shift fi noconfirm= if [ "$1" = "--no-confirm" ]; then noconfirm=yes shift fi backport= if [ "$1" = "--backports" ]; then shift backport=$1 shift fi if [ $# != 3 ]; then echo "Usage: $0 [--dry-run] [--sync] [--no-confirm] [--backport ]
" >&2 exit 1 fi valid_release "$1" valid_section "$2" release="$1" section="$2" srcname="$3" exactsrpm= sourcesubsection='updates_testing' destinationsubsection='updates' if [ 'cauldron' = "$release" ]; then if [ -n "$backport" ]; then echo "Error: Cannot use --backport with cauldron" >&2 exit 1 fi destinationsubsection='release' fi if [ -n "$backport" ]; then sourcesubsection='backports_testing' destinationsubsection='backports' fi for file in "$distribdir/$release/SRPMS/$section/$sourcesubsection/"*.rpm; do pkg=$(rpm -qp --qf '%{NAME}' "$file") # Check exact match bfile=$(basename "$file") if [ "$bfile" = "$srcname" ]; then exactsrpm=y srcname=$pkg srcpkg=$bfile break fi # Check for src package name if [ "$pkg" = "$srcname" ]; then srcpkg=$bfile break fi done if [ -z "$srcpkg" ]; then echo "The package '$srcname' could not be found in the '$release/$section/$sourcesubsection' repository." >&2 exit 2 fi oldsrcpkg= if [ 'release' = "$destinationsubsection" ]; then # In cauldron we also have to move the old version from release to ~schedbot/old/ # We know srcname is a %{name} now. for file in "$distribdir/$release/SRPMS/$section/release/"*.rpm; do pkg=$(rpm -qp --qf '%{NAME}' "$file") if [ "$pkg" = "$srcname" ]; then oldsrcpkg=$bfile break fi done # (cg) Is this a valid check? What if it's a new package introduced first into testing # Ultimately this is not very likely, so ignore it for now. if [ -z "$oldsrcpkg" ]; then echo "The package '$srcname' could not be found in the '$release/$section/$sourcesubsection' repository." >&2 exit 2 fi fi # Safety check if [ -n "$exactsrpm" -a -z "$noconfirm" -o 'release' = "$destinationsubsection" ]; then echo "This SRPM (and matching binaries) will be moved from '$sourcesubsection' to '$destinationsubsection':" echo "- $srcpkg" echo if [ 'release' = "$destinationsubsection" ]; then echo "This SRPM (and matching binaries) will be moved from 'release' to '\~schedbot/old':" echo "- $oldsrcpkg" echo fi read -p "Are you sure? [Y/n] " yn [ -z "$yn" ] yn=y case $yn in [Yy]*) continue;; *) exit;; esac fi function movepkg() { srcdir="$1" destdir="$2" srcpkg="$3" content="$4" commands="$5" for file in "$srcdir/"*.rpm; do srpm=$(rpm -qp --qf '%{SOURCERPM}' "$file") if [ "$srpm" = "$srcpkg" ]; then echo " $(basename $file)" | tee -a "$content" $dryrun mv -v -f "$file" "$destdir" >>"$commands" 2>&1 fi done } mailcontent=$(mktemp) mailcommands=$(mktemp) if [ 'release' = "$destinationsubsection" ]; then echo "" echo "Moving binary and source rpms:" | tee -a "$mailcontent" for arch in $arches; do echo "- $arch:" | tee -a "$mailcontent" movepkg "$distribdir/$release/$arch/media/$section/release" "/var/lib/schedbot/old/" "$oldsrcpkg" "$mailcontent" "$mailcommands" movepkg "$distribdir/$release/$arch/media/debug/$section/release" "/var/lib/schedbot/old/" "$oldsrcpkg" "$mailcontent" "$mailcommands" done echo "- source:" | tee -a "$mailcontent" echo " $oldsrcpkg" | tee -a "$mailcontent" echo >> "$mailcontent" echo >> "$mailcontent" $dryrun mv -v -f "$distribdir/$release/SRPMS/$section/release/$oldsrcpkg" "/var/lib/schedbot/old/" >>"$mailcommands" 2>&1 fi echo "" echo "Moving binary and source rpms:" | tee -a "$mailcontent" for arch in $arches; do echo "- $arch:" | tee -a "$mailcontent" movepkg "$distribdir/$release/$arch/media/$section/$sourcesubsection" "$distribdir/$release/$arch/media/$section/$destinationsubsection/" "$srcpkg" "$mailcontent" "$mailcommands" movepkg "$distribdir/$release/$arch/media/debug/$section/$sourcesubsection" "$distribdir/$release/$arch/media/debug/$section/$destinationsubsection/" "$srcpkg" "$mailcontent" "$mailcommands" done echo "- source:" | tee -a "$mailcontent" echo " $srcpkg" | tee -a "$mailcontent" echo >> "$mailcontent" echo >> "$mailcontent" $dryrun mv -v -f "$distribdir/$release/SRPMS/$section/$sourcesubsection/$srcpkg" "$distribdir/$release/SRPMS/$section/$destinationsubsection/" >>"$mailcommands" 2>&1 if [ -n "$dryrun" ]; then cat "$mailcontent" "$mailcommands" else if [ -z "$sync" ]; then echo >>"$mailcontent" echo "Warning: hdlist update+sync was not performed during this move" >>"$mailcontent" echo >>"$mailcontent" echo >>"$mailcontent" fi if [ -n "$backport" ]; then export SIG="https://bugs.mageia.org/show_bug.cgi?id=$backport" $dryrun 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 $release/$section: $srcname" \ -i "$mailcontent" fi cat "$mailcommands" >>"$mailcontent" /usr/bin/mailx -s "mga-move-update $release $section $srcname" -S "from=$moveupdate_mailfrom" "$moveupdate_mailto" < "$mailcontent" if [ -n "$sync" ]; then update_distro_hdlist "$release" "$section" "$sourcesubsection" update_distro_hdlist "$release" "$section" "$destinationsubsection" update_common_MD5SUM "$release" mirror_repository "$release" fi fi rm -f "$mailcontent" "$mailcommands"