~listen-devel/listen/listen.ppa

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
#!/bin/bash

set -e

working_path=$(cd $(dirname $0) ; pwd )
script_path=$working_path


cleanup(){
    rm -rf $working_path/{export,build}
}
usage(){
    echo "usage: $(basename $0) [-b branch] [-p] [-s] [-h] [-d distlist ]"
    exit 1
}




cleanup
rm -rf $working_path/out
mkdir -p $working_path/{build,out}

branch="lp:listen/0.6"
ppaurl="http://ppa.launchpad.net/listen-devel/ppa/ubuntu/"
ppa=
nosync=
dists="jaunty karmic"
maindist="karmic"
while getopts hpob:d: opt; do
    case $opt in
        d)
            dists="$OPTARG"
            maindist="$OPTARG"
            ;;
        b)
            branch="$OPTARG"
            ;;
        p)
            ppa=1
            ;;
        s)
            nosync=1
            ;;
        h)
            usage
            ;;
        *)
            echo "$opt incorrect"
            exit 0;
        ;;
    esac
done

if [ -z "$nosync" ] ; then


    echo "Releases from branch $branch ?"
    read



    echo "Extract $branch..."
    ssh-add -l >/dev/null || ssh-add
    bzr launchpad-login
    if [ ! -d $working_path/bzr/.bzr ]; then
        bzr branch $branch $working_path/bzr
        pushd $working_path/bzr > /dev/null
    else
        pushd $working_path/bzr > /dev/null
        bzr pull --overwrite
    fi


    version=$(bzr tags --sort="time" | tail -1  | awk '{print $1}')
    ubuntu_revision=0
    lastppa_revision=$(wget -O - -q "$ppaurl/dists/jaunty/main/source/Sources" | awk '/^Version: '$version'/{print $2;exit;}') | sed -n 's/.*~ppa//gp'
    [ -z "$lastppa_version" ] && lastppa_revision=0
    ppa_revision=$((lastppa_revision + 1))
    debversion=$version-$ubuntu_revision~ppa$ppa_revision
    src_version=$(sed -n 's/^VERSION[[:space:]]*=[[:space:]]*//gp' $working_path/bzr/Makefile)
    popd > /dev/null


    if [ "$src_version" != "$version" ]; then
        echo "Can't release $version, bzr tag and Makefile differ"
        cleanup
        exit 1
    fi
    echo "Releases informations:"
    echo "- Source branch: $branch"
    echo "- Tag/Source Version : $version/$(sed -n 's/^VERSION[[:space:]]*=[[:space:]]*//gp' $working_path/bzr/Makefile)"
    echo "- PPA Version : $debversion"
    echo 
    read

    bzr export $working_path/export $working_path/bzr

    make -C $working_path/export dists

    cp $working_path/export/dists/listen-*.tar.gz $working_path/out/
    gpg --armor --sign --detach-sig $working_path/out/listen-$version.tar.gz


else
    file=$(ls -1 $working_path/out/listen-*.tar.gz | sort -n | tail -1)
    version=$(echo ${file} | sed 's/^.*listen-\(.*\)\.tar\.gz$/\1/g')
    ubuntu_revision=0
    lastppa_revision=$(wget -O - -q "$ppaurl/dists/karmic/main/source/Sources" | awk '/^Version: '$version'/{print $2;exit;}') | sed -n 's/.*~ppa//gp'
    [ -z "$lastppa_version" ] && lastppa_revision=0
    ppa_revision=$((lastppa_revision + 2))
    debversion=$version-$ubuntu_revision~ppa$ppa_revision

    echo "Need check:"
    echo "- file: $file"
    echo "- version: $version"
    echo "- debversion: $debversion"
    read
    read
    mkdir -p $working_path/export/dists/
    cp ${file} $working_path/export/dists/
fi

for dist in $dists ; do
    rm $working_path/build -rf
    mkdir $working_path/build
    tar -xzf  $working_path/export/dists/listen-*.tar.gz -C $working_path/build
    cp -a $script_path/debian $working_path/build/listen*/
    pushd $working_path/build/listen*/ > /dev/null
    
    if [ "$dist" == "$maindist" ]; then
        vdist=""
    else
        vdist="~$dist"
    fi
    dch -v "$debversion$vdist" --distribution "$dist" --force-distribution "ppa build of listen $version"

    if [ "$ppa" ]; then
        debuild -S -sa
        pushd $working_path/build > /dev/null
        dput listenppa *_source.changes
        popd > /dev/null
    else
        debuild
        cp -f $working_path/build/*.deb $working_path/out/
    fi
    popd >/dev/null
done



cleanup