aboutsummaryrefslogtreecommitdiff
path: root/tools/Linux/packaging/debian/xbmc-get-orig-source
blob: ee791912fbbfe5bbcc5ddc7d50a4ccaf225d37f0 (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/sh

# This script is used to download the upstream source for xbmc and
# generate it into an orig source tarball for Debian.

USAGE="\n\
This script is used to generate the orig tarball used in building\n\
Debian packages for xbmc. This script will create an orig tarball for\n\
Debian/Ubuntu official archive by default.
Usage: xbmc-get-orig-source [OPTION]\n\
\n\
 -h, --help                 Display this help message.\n\
 --remove-upstream-tarball  Remove the upstream source tarball.\n\
 --make-debian-snapshot     Make tarball for official Debian/Ubuntu archive\n\
                            using latest SVN revision.\n\
 --make-ppa                 Make tarball for XBMC's PPA\n\
 --make-ppa-snapshot        Make tarball for XBMC's PPA using latest SVN\n\
                            revision.\n\
 --use-revision [REV]       Use revision specified in [REV].\n\
 --perform-ppa-upload       Perform PPA upload of the resulting source.\n\
 --dput-host <HOST>         The dput host to use (default team-xbmc-svn-ppa).\n"

# Loop that parses options passed to script
while [ "$#" -gt "0" ]
do
    case "$1" in
        --remove-upstream-tarball)
            REMOVE_UPSTREAM_TARBALL=1
            shift
            ;;
        --make-debian-snapshot)
            LATEST_SVN=1
            shift
            ;;
        --make-ppa)
            PPA_ORIG_TARBALL=1
            shift
            ;;
        --make-ppa-snapshot)
            PPA_ORIG_TARBALL=1
            LATEST_SVN=1
            shift
            ;;
        --use-revision)
            SVN_REVISION="$2"
            shift; shift
            ;;
        --perform-ppa-upload)
            PERFORM_PPA_UPLOAD=1
            shift
            ;;
        --dput-host)
            DPUT_HOST="$2"
            shift; shift
            ;;
        -h|--help|*)
            echo "${USAGE}"
            exit 1
            ;;
    esac
done

# Common variables used to ease maintenance of this script
XBMC_TARBALL=""
XBMC_TARBALL_CHECKSUM=""
if [ -z $SVN_REVISION ]; then
  SVN_REVISION="33746"
fi
EPOCH="2"
XBMC_VERSION="10.0~svn$SVN_REVISION~deb1"
XBMC_SVN_URL="http://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk"
DEB_REVISION="1"
UBUNTU_SUITES="maverick lucid karmic jaunty hardy"
if [ -z $DPUT_HOST ]; then
  DPUT_HOST="team-xbmc-svn-ppa"
fi

# export xbmc source
get_sources() {
    if [ -n "$LATEST_SVN" ]; then
        SVN_REVISION="$(svn info $XBMC_SVN_URL | \
                        grep "Last Changed Rev" | \
                        sed -e 's/^[^0-9]\+//')"
        XBMC_VERSION="10.0~svn$SVN_REVISION~deb1"
    fi
    svn export -r$SVN_REVISION $XBMC_SVN_URL xbmc-$XBMC_VERSION
}

# This will prepare the sources to create a tarball from
prepare_orig_tarball() {
    # Run bootstrap
    cd xbmc-$XBMC_VERSION
    ./bootstrap
    cd ..

    if [ -z "$PPA_ORIG_TARBALL" ]; then
        # Remove non-free components
        echo "Removing non-free components"
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/dvdplayer/Codecs/libdvd/libdvdcss
        rm -rf xbmc-$XBMC_VERSION/xbmc/xbmc/lib/UnrarXLib
        rm -rf xbmc-$XBMC_VERSION/xbmc/xbmc/lib/libXBMS

        # Remove components not needed for Linux when using external libs
        echo "Removing components not needed for Linux when using external libs"
        rm -rf xbmc-$XBMC_VERSION/lib/bzip2
        rm -rf xbmc-$XBMC_VERSION/lib/enca
        rm -rf xbmc-$XBMC_VERSION/lib/freetype
        rm -rf xbmc-$XBMC_VERSION/lib/fribidi
        rm -rf xbmc-$XBMC_VERSION/lib/libass
        rm -rf xbmc-$XBMC_VERSION/lib/libcdio
        rm -rf xbmc-$XBMC_VERSION/lib/libcrystalhd
        rm -rf xbmc-$XBMC_VERSION/lib/libcurl-OSX
        rm -rf xbmc-$XBMC_VERSION/lib/libiconv
        rm -rf xbmc-$XBMC_VERSION/lib/liblame
        rm -rf xbmc-$XBMC_VERSION/lib/libmicrohttpd
        rm -rf xbmc-$XBMC_VERSION/lib/libmodplug
        rm -rf xbmc-$XBMC_VERSION/lib/librtmp
        rm -rf xbmc-$XBMC_VERSION/lib/libSDL-OSX
        rm -rf xbmc-$XBMC_VERSION/lib/libssh_win32
        rm -rf xbmc-$XBMC_VERSION/lib/pcre
        rm -rf xbmc-$XBMC_VERSION/libmicrohttpd_win32
        rm -rf xbmc-$XBMC_VERSION/libmysql_win32
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/dvdplayer/Codecs/liba52
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/dvdplayer/Codecs/libdts
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/dvdplayer/Codecs/libfaad2
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/dvdplayer/Codecs/libmad
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/dvdplayer/Codecs/libmpeg2
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/paplayer/FLACCodec/flac-1.2.1
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/paplayer/ogg
        rm -rf xbmc-$XBMC_VERSION/xbmc/cores/paplayer/vorbisfile
        rm -rf xbmc-$XBMC_VERSION/xbmc/lib/boost
        rm -rf xbmc-$XBMC_VERSION/xbmc/lib/libenca
        rm -rf xbmc-$XBMC_VERSION/xbmc/lib/libmms
        rm -rf xbmc-$XBMC_VERSION/xbmc/lib/libPython/Python
        rm -rf xbmc-$XBMC_VERSION/xbmc/lib/libsamplerate
        rm -rf xbmc-$XBMC_VERSION/xbmc/lib/zlib
    fi

    # Remove temp files and other cruft from source tarball
    # The find command snippet here was taken from debhelper's dh_clean command
    # with some modification to delete more unneeded files.
    echo "Removing temp files and other cruft from source tarball"
    find xbmc-$XBMC_VERSION \( \( -type f -a \
        \( -name '#*#' -o -name '.*~' -o -name '*~' -o -name DEADJOE \
        -o -name '*.orig' -o -name '*.rej' -o -name '*.bak' \
        -o -name '.*.orig' -o -name .*.rej -o -name '.SUMS' \
        -o -name TAGS -o \( -path '*/.deps/*' -a -name '*.P' \) \
        -o -name config.status -o -name config.cache -o -name config.log \
        \) -exec rm -f "{}" \; \) -o \
        \( -type d -a -name autom4te.cache -prune -exec rm -rf "{}" \; \) \)
    rm xbmc-$XBMC_VERSION/.gitignore

    # Remove empty directories
    echo "Removing empty directories"
    find xbmc-$XBMC_VERSION -type d -empty -delete
}

# Function to create tarball
create_tarball() {
    echo "Create orig tarball"
    tar -czf xbmc_$XBMC_VERSION.orig.tar.gz \
        xbmc-$XBMC_VERSION/
}

# Function that performs a PPA upload. It will ensure the version is less than
# the version specified in <XBMC_VERSION>-<DEB_REVISION> and upload a package
# for each supported Ubuntu suite.
perform_ppa_upload() {
    echo "Performing PPA upload."
    cd xbmc-$XBMC_VERSION
    cp -r tools/Linux/packaging/debian .
    for SUITE in $UBUNTU_SUITES; do
      local N="1";

      # Update changelog for uploads to PPA.
      dch --force-distribution -D $SUITE \
        -b -v "${EPOCH}:${XBMC_VERSION}-${DEB_REVISION}~0${SUITE}${N}" \
        "Upload to XBMC PPA for Ubuntu $SUITE." 2>/dev/null

      # Create source package
      if [ "$SUITE" = "lucid" ]; then
        # First suite should always include source tarball
        dpkg-buildpackage -rfakeroot -us -uc -S -sa
      else
        # source format 3.0 (quilt) not supported in suites < lucid
        echo "1.0" >debian/source/format
        dpkg-buildpackage -rfakeroot -us -uc -S -sd
      fi

      # Clean changelog
      perl -e 'local $/;
        my @records, $fh;
        open $fh, "<", "debian/changelog";
        @records = split /^\b/msxg, <$fh>;
        close $fh;
        open $fh, ">", "debian/changelog";
        shift @records;
        foreach my $record (@records)
        {
          print $fh "$record";
        }'

      # Sign source package and upload.
      local SOURCE_CHANGES="xbmc_${XBMC_VERSION}-${DEB_REVISION}~0${SUITE}${N}_source.changes"
      cd ..
      debsign "$SOURCE_CHANGES"
      dput "$DPUT_HOST" "$SOURCE_CHANGES"
      cd xbmc-$XBMC_VERSION
    done
}

get_sources
prepare_orig_tarball
create_tarball
if [ -n $PERFORM_PPA_UPLOAD ]; then
  perform_ppa_upload
fi