~launchpad-pqm/launchpad/devel

4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
1
#!/bin/bash
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
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
4922.2.10 by Julian Edwards
Apply Barry's review comments.
27
# Config goes here.
11049.1.2 by Julian Edwards
Fix cronscripts that know too much about LPCONFIG
28
PRODUCTION_CONFIG=ftpmaster-publish
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
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
4922.2.10 by Julian Edwards
Apply Barry's review comments.
36
# Fix up a release file so it refers to packages in the -commercial pocket.
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
37
fixrelease() {
4922.2.10 by Julian Edwards
Apply Barry's review comments.
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"
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
56
}
57
4922.2.10 by Julian Edwards
Apply Barry's review comments.
58
# Fix the topmost Release file so that its referenced Release file sizes and
59
# checksums are correct.
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
60
fixtoprelease() {
4922.2.10 by Julian Edwards
Apply Barry's review comments.
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"
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
105
}
106
4922.2.10 by Julian Edwards
Apply Barry's review comments.
107
# cd into the real archive or die.
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
108
cd "$archiveurl/dists/" || exit 1
109
4922.2.10 by Julian Edwards
Apply Barry's review comments.
110
# We do this only for distroseries that we need to process.
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
111
for i in $compatreleases; do
4922.2.10 by Julian Edwards
Apply Barry's review comments.
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
4922.2.7 by Julian Edwards
Add script that generates the backwardly compatible commercial pocket for
132
done
133
134
exit 0