summaryrefslogtreecommitdiffstats
path: root/mga-move-update
blob: a43605e43b8208494a97e33ca8879e3c51bee70d (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
#!/bin/sh

set -e

. /usr/share/mgatools/functions

if [ "$1" = "--dry-run" ]; then
    dryrun=echo
    shift
fi

nosync=
if [ "$1" = "--no-sync" ]; then
    nosync=yes
    shift
fi

noconfirm=
if [ "$1" = "--no-confirm" ]; then
    noconfirm=yes
    shift
fi

if [ $# != 3 ]; then
    echo "Usage: $0 [--dry-run] [--no-sync] [--no-confirm] <release> <section> <src-rpm-name>" >&2
    exit 1
fi

valid_release "$1"
valid_section "$2"

release="$1"
section="$2"
srcname="$3"

exactsrpm=
destination='updates'
[ 'cauldron' = "$release" ] && destination='release'

for file in "$distribdir/$release/SRPMS/$section/updates_testing/"*.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/updates_testing' repository." >&2
    exit 2
fi

oldsrcpkg=
if [ 'release' = "$destination" ]; 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/updates_testing' repository." >&2
        exit 2
    fi
fi


# Safety check
if [ -n "$exactsrpm" -a -z "$noconfirm" -o 'release' = "$destination" ]; then
    echo "This SRPM (and matching binaries) will be moved from 'updates_testing' to '$destination':"
    echo "- $srcpkg"
    echo
    if [ 'release' = "$destination" ]; 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' = "$destination" ]; 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/updates_testing" "$distribdir/$release/$arch/media/$section/$destination/" "$srcpkg" "$mailcontent" "$mailcommands"
    movepkg "$distribdir/$release/$arch/media/debug/$section/updates_testing" "$distribdir/$release/$arch/media/debug/$section/$destination/" "$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/updates_testing/$srcpkg" "$distribdir/$release/SRPMS/$section/$destination/" >>"$mailcommands" 2>&1

if [ -n "$dryrun" ]; then
    cat "$mailcontent" "$mailcommands"
else
    if [ -n "$nosync" ]; then
        echo >>"$mailcontent"
        echo "Warning: hdlist update+sync was not performed during this move" >>"$mailcontent"
        echo >>"$mailcontent"
        echo >>"$mailcontent"
    fi
    cat "$mailcommands" >>"$mailcontent"

    /usr/bin/mailx -s "mga-move-update $release $section $srcname" -S "from=$moveupdate_mailfrom" "$moveupdate_mailto" < "$mailcontent"

    if [ -z "$nosync" ]; then
        update_distro_hdlist "$release" "$section" "updates_testing"
        update_distro_hdlist "$release" "$section" "$destination"
        update_common_MD5SUM "$release"
        mirror_repository "$release"
    fi
fi
rm -f "$mailcontent" "$mailcommands"