summaryrefslogtreecommitdiffstats
path: root/mga-move-pkg
blob: 143d410c01548a77f3c93a39f3f0052b1171e9b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/sh

set -e

LOCALDIR="$(dirname $0)"
if [ -d "$LOCALDIR/.git" -a -f "$LOCALDIR/functions" ]; then
  . "$LOCALDIR/functions"
else
  . /usr/share/mgatools/functions
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 <bug>] <release> <section> <src-rpm-name>" >&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 [ -z "$exactsrpm" -o -z "$noconfirm" ]; 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 -n 1 -p "Are you sure? [Y/n] " yn
    [ -n "$yn" ] && echo
    [ -z "$yn" -o "Y" = "$yn" ] && yn=y
    [ "y" != "$yn" ] && exit
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
    echo
    echo "Raw Commands:"
    cat "$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 <buildsystem-daemon@mageia.org>"' \
                     -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 "$0 $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"