~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to cronscripts/publishing/commercial-compat.sh

  • Committer: Curtis Hovey
  • Date: 2011-05-27 21:53:34 UTC
  • mto: This revision was merged to the branch mainline in revision 13136.
  • Revision ID: curtis.hovey@canonical.com-20110527215334-jqlkmt52nnl4bpeh
Moved launchpad.event into registry interfaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
4
# GNU Affero General Public License version 3 (see the file LICENSE).
 
5
 
 
6
# This script munges the partner component into a commercial pocket arrangement
 
7
# for backwards compatibility with dapper, edgy and feisty.
 
8
#
 
9
# After running, <distroseries>-commercial will appear under dists.
 
10
 
 
11
# LPCONFIG will come from the environment so this script can run unaltered
 
12
# on dogfood.
 
13
#
 
14
# Authors:
 
15
# Written by Fabio M Di Nitto, amended by Julian Edwards for production
 
16
# and dogfood compatibility.
 
17
#
 
18
 
 
19
if [ -z $LPCONFIG ]; then
 
20
    echo LPCONFIG must be set to run this script.
 
21
    exit 1
 
22
fi
 
23
 
 
24
# Exit immediately on errors.
 
25
set -e
 
26
 
 
27
# Config goes here.
 
28
PRODUCTION_CONFIG=ftpmaster-publish
 
29
if [ "$LPCONFIG" = "$PRODUCTION_CONFIG" ]; then
 
30
    archiveurl=/srv/launchpad.net/ubuntu-archive/ubuntu-partner
 
31
else
 
32
    archiveurl=/srv/launchpad.net/ppa/ubuntu-partner
 
33
fi
 
34
compatreleases="dapper edgy feisty"
 
35
 
 
36
# Fix up a release file so it refers to packages in the -commercial pocket.
 
37
fixrelease() {
 
38
    in="$1"
 
39
    out="$2"
 
40
 
 
41
    descr=$(cat "$in" |grep ^Version: | sed -e 's#Version: ##g')
 
42
 
 
43
    # Add -commercial suffix where required, force the component to main,
 
44
    # and set Origin: and Label: to Canonical.
 
45
    cat "$in" | sed \
 
46
        -e 's#^Archive:.*#&-commercial#g' \
 
47
        -e 's#^Component:.*#Component: main#g' \
 
48
        -e 's#^Origin:.*#Origin: Canonical#g' \
 
49
        -e 's#^Label:.*#Label: Canonical#g' \
 
50
        -e 's#^Suite:.*#&-commercial#g' \
 
51
        -e 's#^Codename:.*#&-commercial#g' \
 
52
        -e 's#^Components:.*#Components: main#g' \
 
53
        -e 's#^Description:.*#Description: Ubuntu '"$descr"' Commercial Software#g' \
 
54
        -e 's#partner/#main/#g' \
 
55
        > "$out"
 
56
}
 
57
 
 
58
# Fix the topmost Release file so that its referenced Release file sizes and
 
59
# checksums are correct.
 
60
fixtoprelease() {
 
61
    in="$1"
 
62
    out="$2"
 
63
    release="$3"
 
64
 
 
65
    hash=""
 
66
    blank=""
 
67
 
 
68
    # Here we read in a line, see what type of hash is being used, and then
 
69
    # the line ending in "Release" is re-written.  Comments cannot go
 
70
    # inside {} blocks so the four commands are explained here:
 
71
    #   filename= : this will get the filename relative to the top level.
 
72
    #   sum=      : this will calculate the new checksum according to which
 
73
    #               one we're processing at the moment.
 
74
    #   size=     : get the file's size.
 
75
    #   printf    : output to the new Release file in the right format.
 
76
    #
 
77
    cat "$in" | { while read line; do
 
78
        case "$line" in
 
79
            MD5Sum:)
 
80
                hash=md5
 
81
                blank=" "
 
82
                echo "MD5Sum:"
 
83
            ;;
 
84
            SHA1:)
 
85
                hash=sha1
 
86
                blank=" "
 
87
                echo "SHA1:"
 
88
            ;;
 
89
            SHA256:)
 
90
                hash=sha256
 
91
                blank=" "
 
92
                echo "SHA256:"
 
93
            ;;
 
94
            *Release)
 
95
                filename=$(echo $line | awk '{print $3}')
 
96
                sum="$(echo $(gpg --print-md $hash $i-commercial/$filename | cut -d ":" -f 2 | tr [A-Z] [a-z]) | sed -e 's/ //g')"
 
97
                size="$(ls -ls $i-commercial/$filename | awk '{print $6}')"
 
98
                printf " %s %*d %s\n" "$sum" 16 "$size" "$filename"
 
99
            ;;
 
100
            *)
 
101
                echo "$blank$line"
 
102
            ;;
 
103
        esac
 
104
    done; } > "$out"
 
105
}
 
106
 
 
107
# cd into the real archive or die.
 
108
cd "$archiveurl/dists/" || exit 1
 
109
 
 
110
# We do this only for distroseries that we need to process.
 
111
for i in $compatreleases; do
 
112
    if [ -d "$i" ]; then
 
113
        # Nuke the old commercial pocket.
 
114
        rm -rf "$i-commercial"
 
115
        # Clone with the new one to import all the Packages and dir structure.
 
116
        cp -rp "$i" "$i-commercial"
 
117
        # Nuke the old signature that would be invalid anyway.
 
118
        rm -f "$i-commercial/Release.gpg"
 
119
        # Rename section from partner to main.
 
120
        mv $i-commercial/partner $i-commercial/main
 
121
        # Fix all Release files.
 
122
        find "$i-commercial" -name "Release" | { while read line; do
 
123
            fixrelease $line $line.new
 
124
            mv $line.new $line
 
125
        done; }
 
126
        # Top level needs more love (*sums, file size)
 
127
        fixtoprelease "$i-commercial/Release" "$i-commercial/Release.new" "$i"
 
128
        mv "$i-commercial/Release.new" "$i-commercial/Release"
 
129
        # Sign the Release file
 
130
        gpg --armour --output "$i-commercial/Release.gpg" --detach-sign "$i-commercial/Release"
 
131
    fi
 
132
done
 
133
 
 
134
exit 0