Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 286 lines (250 sloc) 9.52 KB
#!/bin/bash
# This script is used to download the upstream source for xbmc and
# generate it into an orig source tarball for Debian.
# Common variables used to ease maintenance of this script
XBMC_MAJOR_VERSION="12.0"
EPOCH="2"
PPA_REVISION="1"
XBMC_GIT_URL="git://github.com/xbmc/xbmc.git"
DEFAULT_XBMC_BRANCH="master"
UBUNTU_SUITES=("oneiric" "precise" "quantal")
XBMC_SOURCE="./xbmc"
# This is the where the XBMC source repo should be cloned. You can use a local
# tree if you have one. Origin will be updated, but it is otherwise read-only.
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 from\n\
the tip of master for the nightly PPA archive by default.
Usage: xbmc-get-orig-source [OPTION]\n\
\n\
-h, --help Display this help message\n\
--remove-nonfree Remove non-free libs before creating archive\n\
--remove-libs Remove libs not necessary for Linux build\n\
--remove-external-libs Remove optional external libs. When used,\n\
XBMC must be built with --enable-external-libraries\n\
--minimal This acts as a short hand for --remove-nonfree,\n\
--remove-libs, and --remove-external-libs.\n\
--revision [REV] Build XBMC from the revision specified in [REV]\n\
If not specified, HEAD will be used\n\
--branch [BRANCH] Build XBMC from the tip of [BRANCH]\n\
If not specified, master will be used\n\
--stable Use stable naming convention and omit git revision\n\
TODO: Not yet implemented!\n\
--ppa-upload [HOST] Perform PPA upload of the resulting source\n\
--git-url [URL] Specify a url to clone. Default is $XBMC_GIT_URL\n"
# Loop that parses options passed to script
while [ "$#" -gt "0" ]; do
case "$1" in
--remove-nonfree)
REMOVE_NONFREE=1
shift
;;
--remove-libs)
REMOVE_LIBS=1
shift
;;
--remove-external-libs)
REMOVE_EXTERNAL=1
shift
;;
--minimal)
REMOVE_NONFREE=1
REMOVE_LIBS=1
REMOVE_EXTERNAL=1
shift
;;
--revision)
REVISION="$2"
shift; shift
;;
--branch)
BRANCH="$2"
shift; shift
;;
--stable)
STABLE="1"
shift
;;
--ppa-upload)
DPUT_HOST="$2"
shift; shift
;;
--git-url)
XBMC_GIT_URL="$2"
shift; shift
;;
-h|--help|*)
echo -e "${USAGE}"
exit 1
;;
esac
done
if [[ ! -z "${BRANCH}" && ! -z "${REVISION}" ]]; then
echo -e "${USAGE}"
echo -e "\nError: \"--use-branch\" and \"--use-revision\" may not be combined\n"
exit 1
fi
if [ -z "${BRANCH}" ]; then BRANCH="${DEFAULT_XBMC_BRANCH}"; fi
if [ "${BRANCH:0:7}" != "origin/" ]; then BRANCH="origin/${BRANCH}"; fi
if [ -z "${REVISION}" ]; then REVISION="${BRANCH}"; fi
# export xbmc source
get_sources() {
local origin_url="$(GIT_DIR="${XBMC_SOURCE}/.git" git config remote.origin.url)"
if [ -n "${origin_url}" ]; then
echo "Refetching sources from ${origin_url}"
GIT_DIR="${XBMC_SOURCE}/.git" git fetch origin
else
echo "Cloning sources from ${XBMC_GIT_URL}"
git clone --no-checkout "${XBMC_GIT_URL}" "${XBMC_SOURCE}"
fi
GIT_REV_DATE=$(GIT_DIR="${XBMC_SOURCE}/.git" git log --abbrev=7 -1 --pretty=format:"%h %ci" ${REVISION} | awk '{gsub("-", "");print $2"."$1}')
if [ "$STABLE" = "1" ]; then
XBMC_VERSION="${XBMC_MAJOR_VERSION}"
else
XBMC_VERSION="${XBMC_MAJOR_VERSION}~git${GIT_REV_DATE}"
fi
BUILDDIR="xbmc-${XBMC_VERSION}"
mkdir -p "${BUILDDIR}"
GIT_DIR="${PWD}/${XBMC_SOURCE}/.git" GIT_WORK_TREE="${BUILDDIR}" git reset --hard "${REVISION}"
#Check out the specified revision into our build dir. We keep these separate so that a git clean
# will not remove the .git dir. This way we don't end up re-cloning for each build.
#As of 1.7.1, git has a bug that prevents a hard reset with a relative GIT_DIR. Hack around using $PWD.
}
# This will prepare the sources to create a tarball from
prepare_orig_tarball() {
pushd ${BUILDDIR} >/dev/null
./bootstrap
if [ -z "$REMOVE_EXTERNAL" ]; then
curl -Ls --output lib/addons/script.module.pil/Imaging-1.1.7.tar.gz http://www.effbot.org/downloads/Imaging-1.1.7.tar.gz
fi
popd >/dev/null
if [ ! -z "$REMOVE_NONFREE" ]; then
# Remove non-free components
echo "Removing non-free components"
find ${BUILDDIR} -iname *dvdcss* -exec rm -rf "{}" \;
find ${BUILDDIR} -iname *unrar* -exec rm -rf "{}" \;
fi
if [ ! -z "$REMOVE_LIBS" ]; then
echo "Removing components not needed for Linux"
# Remove components not needed for Linux
rm -rf ${BUILDDIR}/lib/afpfs-ng
rm -rf ${BUILDDIR}/lib/libass
rm -rf ${BUILDDIR}/lib/libbluray
rm -rf ${BUILDDIR}/lib/libcec
rm -rf ${BUILDDIR}/lib/liblame
rm -rf ${BUILDDIR}/lib/libmad
rm -rf ${BUILDDIR}/lib/libmicrohttpd
rm -rf ${BUILDDIR}/lib/libmodplug
rm -rf ${BUILDDIR}/lib/libmpeg2
rm -rf ${BUILDDIR}/lib/libnfs
rm -rf ${BUILDDIR}/lib/librtmp
rm -rf ${BUILDDIR}/lib/libshairport
rm -rf ${BUILDDIR}/lib/taglib
rm -rf ${BUILDDIR}/lib/win32
find ${BUILDDIR} \( \( -iname *.so -o -iname *.exe -o -iname *.lib \
-o -iname *.dll -o -iname *.dylib -o -iname *.a \
\) -exec rm -rf "{}" \; \)
fi
if [ ! -z "$REMOVE_EXTERNAL" ]; then
echo "Removing components not needed for Linux when using external libs"
# Remove components not needed for Linux when using external libs
# rm -rf ${BUILDDIR}/lib/ffmpeg
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 ${BUILDDIR} \( \( -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 ${BUILDDIR}/.gitignore
# Remove empty directories
echo "Removing empty directories"
find ${BUILDDIR} -type d -empty -delete
}
# Function to create tarball
create_tarball() {
echo "Creating orig tarball"
tar -czf xbmc_$XBMC_VERSION.orig.tar.gz ${BUILDDIR}
}
# Function that creates source packages. It will ensure the version is less
# than the version specified in <XBMC_VERSION>-<PPA_REVISION> and upload a
# package for each supported Ubuntu suite if desired.
create_source_packages() {
if [ -n "${DPUT_HOST}" ]; then
echo "Performing PPA upload."
for (( iter = 0 ; iter < ${#UBUNTU_SUITES[@]} ; iter++ )); do
#nasty hack. Export this so we can use build-deps for the right version
export XBMC_UBUNTU_PPA_VERSION=${UBUNTU_SUITES[$iter]}
# Create debian/control
perl -p \
-e 's{#BUILD_DEPENDS#}{qx(sh var_info BUILD_DEPENDS_PPA)}ge;' \
< control.in > $(echo debian/control.in | sed 's/\.in$//')
XBMC_UBUNTU_PPA_VERSION=
# Place appropriate rules file in debian directory
cp -f rules.ppa debian/rules
# Replace debian directory in build dir
rm -rf "${BUILDDIR}/debian"
cp -r ./debian "${BUILDDIR}"
pushd ${BUILDDIR} >/dev/null
# Update changelog for uploads to PPA.
dch --force-distribution -D ${UBUNTU_SUITES[$iter]} \
-b -v "${EPOCH}:${XBMC_VERSION}-0ubuntu1~ppa${PPA_REVISION}~${UBUNTU_SUITES[$iter]}" \
"Upload to XBMC PPA for Ubuntu ${UBUNTU_SUITES[$iter]}." 2>/dev/null
# Create source package
if [[ "${UBUNTU_SUITES[$iter]}:1:0" < "l" ]]; then
# source format 3.0 (quilt) not supported in suites < lucid
echo "1.0" >debian/source/format
fi
if [ "$iter" = "0" ]; then
# First suite should always include source tarball
dpkg-buildpackage -rfakeroot -us -uc -S -sa
else
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.
popd >/dev/null
local SOURCE_CHANGES="xbmc_${XBMC_VERSION}-0ubuntu1~ppa${PPA_REVISION}~${UBUNTU_SUITES[$iter]}_source.changes"
debsign "$SOURCE_CHANGES"
dput "${DPUT_HOST}" "${SOURCE_CHANGES}"
done
else
# Create debian/control
perl -p \
-e 's{#BUILD_DEPENDS#}{qx(sh var_info BUILD_DEPENDS)}ge;' \
< control.in > $(echo debian/control.in | sed 's/\.in$//')
# Place appropriate rules file in debian directory
cp -f rules.distro debian/rules
# Replace debian directory in build dir
rm -rf "${BUILDDIR}/debian"
cp -r ./debian "${BUILDDIR}"
pushd ${BUILDDIR} >/dev/null
dch --force-distribution -D "UNRELEASED" \
-b -v "${EPOCH}:${XBMC_VERSION}-1" \
"TEST PACKAGE! NOT MEANT FOR RELEASE." 2>/dev/null
# Create source package
dpkg-buildpackage -rfakeroot -us -uc -S -sa
popd >/dev/null
fi
}
get_sources
prepare_orig_tarball
create_tarball
create_source_packages