Browse files

add binary addons build scripts

  • Loading branch information...
1 parent 655a84e commit 65e80b577ec6a5344d75cda048fa85de466203ab @wsnipex wsnipex committed Jun 10, 2013
Showing with 459 additions and 0 deletions.
  1. +11 −0 addons-ppa.sh
  2. +283 −0 build-xbmc-addons.sh
  3. +165 −0 update-addon-repo.sh
View
11 addons-ppa.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+#ADDONS=${ADDONS:-"visualization.waveform visualization.goom visualization.spectrum screensavers.rsxs"} \
+CLEANUP_AFTER="True" \
+TAG=${TAG:-"1"} \
+BRANCH="master" \
+DISTS="saucy raring quantal precise" \
+PPA_UPLOAD="True" \
+PPA="wsnipex-xbmc-addons-unstable" \
+./build-xbmc-addons.sh
+
View
283 build-xbmc-addons.sh
@@ -0,0 +1,283 @@
+#!/bin/bash
+#
+# Copyright (C) 2013 wsnipex, Team XBMC
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2 of the License,
+# or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+
+BRANCH=${BRANCH:-"master"}
+TAG=${TAG:-"1"}
+WORK_DIR=${WORKSPACE:-$(pwd)}
+[[ $(which lsb_release) ]] && DISTS=${DISTS:-$(lsb_release -cs)} || DISTS=${DISTS:-"stable"}
+ARCHS=${ARCHS:-$(dpkg --print-architecture)}
+BUILDER=${BUILDER:-"debuild"}
+DEBUILD_OPTS=${DEBUILD_OPTS:-""}
+PDEBUILD_OPTS=${PDEBUILD_OPTS:-""}
+PBUILDER_BASE=${PBUILDER_BASE:-"/var/cache/pbuilder"}
+DPUT_TARGET=${DPUT_TARGET:-"local"}
+PPA_UPLOAD=${PPA_UPLOAD:-"False"}
+PPA=${PPA:-"wsnipex-xbmc-addons-unstable"}
+URGENCY=${URGENCY:-"low"}
+REBUILD=${REBUILD:-"False"}
+CREATE_ZIP=${CREATE_ZIP:-"False"}
+CREATE_TGZ=${CREATE_TGZ:-"False"}
+ZIP_OUTPUT_DIR=${ZIP_OUTPUT_DIR:-$WORK_DIR}
+CLEANUP_AFTER=${CLEANUP_AFTER:-"False"}
+GITHUB_USER=${GITHUB_USER:-"cptspiff"}
+META_REPO=${META_REPO:-"https://github.com/cptspiff/xbmc-visualizations"}
+ADDON_FILTER=${ADDON_FILTER:-"visualization.milkdrop gameclient.snes9x"}
+
+# Define a default list to cope with addons not yet in the meta repo.
+# The ones existing in the meta repo will overwrite the defaults
+declare -A ALL_ADDONS=(
+ ["visualization.waveform"]="https://github.com/$GITHUB_USER/visualization.waveform"
+ ["visualization.goom"]="https://github.com/$GITHUB_USER/visualization.goom"
+ ["visualization.spectrum"]="https://github.com/$GITHUB_USER/visualization.spectrum"
+ ["visualization.projectm"]="https://github.com/$GITHUB_USER/visualization.projectm"
+ ["visualization.fishbmc"]="https://github.com/$GITHUB_USER/visualization.fishbmc"
+ ["gameclient.snes9x"]="https://github.com/$GITHUB_USER/gameclient.snes9x"
+ ["screensavers.rsxs"]="https://github.com/$GITHUB_USER/screensavers.rsxs"
+ ["xbmc-platform"]="https://github.com/$GITHUB_USER/xbmc-platform"
+ ["pvr.demo"]="https://github.com/$GITHUB_USER/pvr.demo"
+ ["pvr.iptvsimple"]="https://github.com/$GITHUB_USER/pvr.iptvsimple"
+ ["pvr.njoy"]="https://github.com/$GITHUB_USER/pvr.njoy"
+ ["pvr.argustv"]="https://github.com/$GITHUB_USER/pvr.argustv"
+ ["pvr.hts"]="https://github.com/$GITHUB_USER/pvr.hts"
+ ["pvr.dvbviewer"]="https://github.com/$GITHUB_USER/pvr.dvbviewer"
+ ["pvr.vuplus"]="https://github.com/$GITHUB_USER/pvr.vuplus"
+ ["pvr.mythtv.cmyth"]="https://github.com/$GITHUB_USER/pvr.mythtv.cmyth"
+ ["pvr.mediaportal.tvserver"]="https://github.com/$GITHUB_USER/pvr.mediaportal.tvserver"
+ ["pvr.nextpvr"]="https://github.com/$GITHUB_USER/pvr.nextpvr"
+ ["pvr.vdr.vnsi"]="https://github.com/$GITHUB_USER/pvr.vdr.vnsi"
+)
+
+declare -A PPAS=(
+ ["nightly"]='ppa:team-xbmc/xbmc-nightly'
+ ["unstable"]='ppa:team-xbmc/unstable'
+ ["stable"]='ppa:team-xbmc/ppa'
+ ["wsnipex-nightly"]='ppa:wsnipex/xbmc-nightly'
+ ["wsnipex-xbmc-addons-unstable"]='ppa:wsnipex/xbmc-addons-unstable'
+)
+
+
+#------------------------------------------------------------------------------------------------------------#
+
+function usage {
+ echo "$0: this script builds xbmc addon debian packages."
+ echo "The build is controlled by ENV variables, which van be overridden as appropriate:"
+ echo "BUILDER is either debuild(default) or pdebuild(needs a proper pbuilder setup)"
+ echo "If CREATE_ZIP is True, addons are compiled directly and packaged as zip files"
+ checkEnv
+ exit 2
+}
+
+function checkEnv {
+ echo "#------ build environment ------#"
+ echo "Building following addons: $ADDONS"
+ echo "Using Meta Repo: $META_REPO"
+ echo "WORK_DIR: $WORK_DIR"
+ [[ -n $TAG ]] && echo "TAG: $TAG"
+ echo "DISTS: $DISTS"
+ echo "ARCHS: $ARCHS"
+ echo "CONFIGURATION: $Configuration"
+ [[ "$CREATE_ZIP" == "True" ]] && echo "Creating ZIPs only" && return
+ [[ "$CREATE_TGZ" == "True" ]] && echo "Creating tarballs only" && return
+ echo "BUILDER: $BUILDER"
+
+ if ! [[ $(which $BUILDER) ]]
+ then
+ echo "Error: can't find ${BUILDER}, consider using full path to [debuild|pdebuild]"
+ exit 1
+ fi
+
+ if [[ "$BUILDER" =~ "pdebuild" ]]
+ then
+ if ! [[ -d $PBUILDER_BASE ]] ; then echo "Error: $PBUILDER_BASE does not exist"; exit 1; fi
+ echo "PBUILDER_BASE: $PBUILDER_BASE"
+ echo "PDEBUILD_OPTS: $PDEBUILD_OPTS"
+ else
+
+ if [[ "$PPA_UPLOAD" == "True" ]]
+ then
+ echo "PPA_UPLOAD: $PPA_UPLOAD"
+ echo "PPA: $PPA"
+ rm -rf $WORK_DIR/watch/$PPA >/dev/null 2>&1
+ echo "URGENCY: $URGENCY"
+ echo "REBUILD: $REBUILD"
+ [[ "$DPUT_TARGET" == "local" ]] && DPUT_TARGET=${PPAS["$PPA"]}
+ [[ -z $DEBUILD_OPTS ]] && DEBUILD_OPTS="-S"
+ [[ -z $DPUT_TARGET ]] && echo "ERROR: empty PPA, refusing build" && exit 4
+ fi
+ fi
+ echo "DEBUILD_OPTS: $DEBUILD_OPTS"
+ echo "DPUT_TARGET: $DPUT_TARGET"
+ echo "#-------------------------------#"
+
+}
+
+function getAllAddons {
+ local name
+ local url
+
+ wget -T 10 -t 5 $META_REPO/raw/master/.gitmodules -O addon-list
+ while read -r name url
+ do
+ ALL_ADDONS[$name]=$url
+ done < <(cat addon-list | paste - - - | awk '{gsub("git:", "https:"); print $5, $8}')
+
+ ADDONS=${ADDONS:-${!ALL_ADDONS[@]}}
+}
+
+function prepareBuild {
+ for addon in ${ADDONS[*]}
+ do
+ [[ "$ADDON_FILTER" =~ "$addon" ]] && echo "WARNING: found $addon in ADDON_FILTER, skipping build" && continue
+ cd $WORK_DIR || exit 1
+ echo "\n#-------------------------------------------------------#"
+ echo "INFO: building $addon"
+ url=${ALL_ADDONS["$addon"]}
+ [ -d ${addon}.tmp ] && rm -rf ${addon}.tmp
+ mkdir ${addon}.tmp && cd ${addon}.tmp || exit 1
+ wget -T 10 -t 5 $url/archive/${BRANCH}.tar.gz
+ ! [ -r ${BRANCH}.tar.gz ] && echo "ERROR: download of ${BRANCH}.tar.gz failed" && continue
+ tar xzf ${BRANCH}.tar.gz
+ if [[ "$CREATE_ZIP" == "True" ]]
+ then
+ createZipPackages
+ elif [[ "$CREATE_TGZ" == "True" ]]
+ then
+ createTgzPackages
+ else
+ getPackageDetails
+ if [[ "$REBUILD" == "True" ]]
+ then
+ orig=$(echo ${PPAS["$PPA"]} | sed -e 's%/%/+archive/%' -e 's%ppa:%https://launchpad.net/~%')
+ wget -T 10 -t 5 ${orig}/+files/${PACKAGENAME}_${PACKAGEVERSION}.orig.tar.gz
+ else
+ mv ${BRANCH}.tar.gz ${PACKAGENAME}_${PACKAGEVERSION}.orig.tar.gz
+ fi
+ cd ${addon}-${BRANCH}
+ sed -e "s/#PACKAGEVERSION#/${PACKAGEVERSION}/g" -e "s/#TAGREV#/${TAG}/g" debian/changelog.in > debian/changelog.tmp
+ buildDebianPackages
+ [[ "$PPA_UPLOAD" == "True" ]] && cd .. && uploadPkg
+ fi
+ done
+}
+
+function createZipPackages {
+ cd ${addon}-${BRANCH}
+ cmake -DCMAKE_BUILD_TYPE=Release -DPACKAGE_ZIP=ON -DBUILD_SHARED_LIBS=1 && make package
+ mv ${addon}*.zip $ZIP_OUTPUT_DIR
+}
+
+function createTgzPackages {
+ cd ${addon}-${BRANCH}
+ cmake -DCMAKE_BUILD_TYPE=Release -DPACKAGE_TGZ=ON -DBUILD_SHARED_LIBS=1 && make package
+ mv ${addon}*.tar.gz $ZIP_OUTPUT_DIR
+}
+
+function getPackageDetails {
+ PACKAGENAME=$(awk '{if(NR==1){ print $1}}' ${addon}-${BRANCH}/debian/changelog.in)
+ addonxml=$(find ${addon}-${BRANCH} -name addon.xml)
+ if [ -f ${addon}-${BRANCH}/${addon}/addon.xml ]
+ then
+ PACKAGEVERSION=$(awk -F'=' '!/<?xml/ && /version/ && !/>/ {gsub("\"",""); print $2}' ${addon}-${BRANCH}/${addon}/addon.xml)
+ elif [ -n "$addonxml" ]
+ then
+ # some addons don't follow the file system structure 100%, try our best to find an addon.xml
+ PACKAGEVERSION=$(awk -F'=' '!/<?xml/ && /version/ && !/>/ {gsub("\"",""); VER=$2} END {print VER}' ${addon}-${BRANCH}/${addon:0:5}*/addon.xml)
+ else
+ # try CmakeLists as a final effort
+ PACKAGEVERSION=$(grep -E "PROPERTIES.*VERSION" ${addon}-${BRANCH}/CMakeLists.txt | grep -oE "[0-9\.]+")
+ fi
+
+ [[ -z $PACKAGEVERSION ]] && echo "ERROR: could not determine version of $addon" && break
+}
+
+function buildDebianPackages {
+ for dist in $DISTS
+ do
+ sed "s/#DIST#/${dist}/g" debian/changelog.tmp > debian/changelog
+ dch --release -u $URGENCY ""
+ for arch in $ARCHS
+ do
+ echo "building: DIST=$dist ARCH=$arch"
+ if [[ "$BUILDER" =~ "pdebuild" ]]
+ then
+ DIST=$dist ARCH=$arch $BUILDER $PDEBUILD_OPTS
+ [ $? -eq 0 ] && uploadPkg || exit 1
+ else
+ $BUILDER $DEBUILD_OPTS
+ [ $? -eq 0 ] && [[ "$PPA_UPLOAD" == "True" ]] && createPpaCheckFiles
+ fi
+ done
+ done
+}
+
+function createPpaCheckFiles {
+ local builtpackage
+ local zipname
+ local watchdir="$WORK_DIR/watch/${PPA}/${dist}"
+ local watchfile="${watchdir}.addon.list"
+ mkdir -p $watchdir
+ grep Package debian/control | sed 's/Package: //g' | while read builtpackage
+ do
+ echo "${builtpackage} ${PACKAGEVERSION}-${TAG}~${dist}" >> $watchfile
+ zipname=$(echo ${builtpackage} | sed -e "s/xbmc-//" -e "s/-/\./g")
+ [ -d ${zipname} ] && zip ${zipname}.zip ${zipname}/* && mv ${zipname}.zip $watchdir
+ done
+
+}
+
+function uploadPkg {
+ if [[ "$BUILDER" =~ "pdebuild" ]]
+ then
+ local changes="${PACKAGENAME}_${PACKAGEVERSION}-${TAG}~${dist}_${arch}.changes"
+ PKG="${PBUILDER_BASE}/${dist}-${arch}/result/${changes}"
+ echo "INFO: signing package"
+ debsign $PKG
+ echo "INFO: uploading $PKG to $DPUT_TARGET"
+ dput $DPUT_TARGET $PKG
+ UPLOAD_DONE=$?
+ elif [[ "$PPA_UPLOAD" == "True" ]]
+ then
+ local changes="${PACKAGENAME}_${PACKAGEVERSION}-${TAG}*.changes"
+ echo "INFO: uploading $changes to $DPUT_TARGET"
+ dput $DPUT_TARGET $changes
+ UPLOAD_DONE=$?
+ else
+ echo "INFO: Build produced following packages:"
+ ls -l *.deb
+ fi
+}
+
+function cleanup {
+ cd $WORK_DIR || exit 1
+ for addon in ${ADDONS[*]}
+ do
+ rm -rf ${addon}.tmp
+ done
+}
+
+###
+# main
+###
+if [[ $1 = "-h" ]] || [[ $1 = "--help" ]]
+then
+ usage
+ exit
+fi
+
+checkEnv
+getAllAddons
+prepareBuild
+[[ "$CLEANUP_AFTER" == "True" ]] && [[ $UPLOAD_DONE -eq 0 ]] && cleanup
+
View
165 update-addon-repo.sh
@@ -0,0 +1,165 @@
+#!/bin/bash
+#
+# Copyright (C) 2013 wsnipex, Team XBMC
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2 of the License,
+# or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+
+PPA=${PPA:-"auto"}
+DISTS=${DISTS:-"saucy raring quantal precise"}
+ARCHS="i386 amd64"
+WORK_DIR=${WORKSPACE:-$(pwd)}
+WATCH=${WATCH:-"$WORK_DIR/watch"}
+
+# Sync with build-xbmc-addons.sh
+declare -A PPAS=(
+ ["nightly"]='ppa:team-xbmc/xbmc-nightly'
+ ["unstable"]='ppa:team-xbmc/unstable'
+ ["stable"]='ppa:team-xbmc/ppa'
+ ["wsnipex-nightly"]='ppa:wsnipex/xbmc-nightly'
+ ["wsnipex-xbmc-addons-unstable"]='ppa:wsnipex/xbmc-addons-unstable'
+)
+
+declare -A REPOS=(
+ ["nightly"]='ftp://nightlyrepo.xbmc.org'
+ ["unstable"]='ftp://unstablerepo.xbmc.org'
+ ["stable"]='ftp://stablerepo.xbmc.org'
+ ["wsnipex-nightly"]='ftp://nightlyrepo.xbmc.org'
+ ["wsnipex-xbmc-addons-unstable"]='ftp://foobar.wsnipex'
+)
+
+declare -A PPAPACKAGES_i386
+declare -A PPAPACKAGES_amd64
+
+function checkPpaVersion {
+ for arch in $ARCHS
+ do
+ PACKAGES=$(echo ${PPAS["$PPA"]}"/ubuntu/dists/#dist#/main/binary-#arch#/Packages" | sed -e 's%ppa:%http://ppa.launchpad.net/%' -e "s/#dist#/$DIST/" -e "s/#arch#/$arch/")
+ wget $PACKAGES -O Packages.${PPA}.${DIST}.${arch} >/dev/null 2>&1
+ while read -r pack vers
+ do
+ [[ $arch == "i386" ]] && PPAPACKAGES_i386[$pack]=$vers || PPAPACKAGES_amd64[$pack]=$vers
+ done < <( grep -E "Package|Version" Packages.${PPA}.${DIST}.${arch} | sed -e 's/Package: //g' -e 's/Version: //g' | paste - - )
+ done
+}
+
+function verifyBuild {
+ cd $WATCH/$PPA || exit 1
+ for DIST in $DISTS
+ do
+ checkPpaVersion
+ [ -r ${DIST}.addon.list ] || continue
+ echo ; echo "$(date "+%F %T") checking uploads in PPA: $PPA dist: $DIST"
+ echo "#------------------------------------------------------------------------#"
+ while read PACKAGE VERSION
+ do
+ echo -n "Package: $PACKAGE Version: $VERSION PPA_VERSION: ${PPAPACKAGES_i386["$PACKAGE"]:-"none"}"
+ if [[ "${PPAPACKAGES_i386["$PACKAGE"]}" == "$VERSION" ]] && [[ "${PPAPACKAGES_amd64["$PACKAGE"]}" == "$VERSION" ]]
+ then
+ echo " Upload: verified"
+ zipname=$(echo $PACKAGE | sed -e "s/xbmc-//" -e "s/-/\./g")".zip"
+ uploadAddonXml
+ [[ $UPLOAD_DONE == "True" ]] && removeFromList
+ else
+ echo " Upload: failed"
+ checkSuperseded
+ unset PACKAGE VERSION
+ fi
+ done < <(cat ${DIST}.addon.list)
+ done
+}
+
+function uploadAddonXml {
+ UPLOAD_DONE="False"
+ if [ -r $DIST/$zipname ]
+ then
+ echo "Uploading $zipname to ${REPOS["$PPA"]}"
+ #TODO: some FTP/HTTP foo
+ [ $? -eq 0 ] && UPLOAD_DONE="True"
+ else
+ echo "Error $zipname not found, removing from list"
+ removeFromList
+ fi
+}
+
+function removeFromList {
+ sed -i "/^$PACKAGE.*/d" ${DIST}.addon.list
+ #rm $DIST/$zipname
+ unset zipname
+ local filesize=$(wc -l ${DIST}.addon.list)
+ [ ${filesize:0:1} -eq 0 ] && rm ${DIST}.addon.list
+}
+
+function checkSuperseded {
+ if [[ "${PPAPACKAGES_i386["$PACKAGE"]}" ]] && [[ "${PPAPACKAGES_i386["$PACKAGE"]}" == "${PPAPACKAGES_amd64["$PACKAGE"]}" ]]
+ then
+ dpkg --compare-versions ${PPAPACKAGES_i386["$PACKAGE"]} gt $VERSION
+ if [ $? -eq 0 ]
+ then
+ echo "Version in PPA greater then ${VERSION}, removing superseded package from list"
+ removeFromList
+ fi
+ elif [[ "${PPAPACKAGES_i386["$PACKAGE"]}" ]] || [[ "${PPAPACKAGES_amd64["$PACKAGE"]}" ]]
+ then
+ echo "Error: package has different versions in i386 and amd64"
+ echo "i386: ${PPAPACKAGES_i386["$PACKAGE"]} amd64: ${PPAPACKAGES_amd64["$PACKAGE"]}"
+ fi
+}
+
+function cleanup {
+ if [ -d $WATCH/$PPA ]
+ then
+ cd $WATCH || exit 1
+ local addonfiles=$(ls $PPA/*.addon.list 2>/dev/null)
+ if [ -z "$addonfiles" ]
+ then
+ echo "All Addons in $PPA successfully processed, removing directory"
+ rm -rf $PPA
+ fi
+ fi
+
+ local ppadirs=$(ls -d $WATCH/* 2>/dev/null)
+ if [ -z "$ppadirs" ]
+ then
+ echo "All PPAs successfully processed, removing watch dir"
+ cd .. && rm -rf $WATCH
+ fi
+}
+
+###
+# Main
+###
+if ! [ -d $WATCH ]
+then
+ echo "Watch dir not found"
+ exit 0
+fi
+
+if [[ "$PPA" == "auto" ]]
+then
+ for PPA in ${!PPAS[*]}
+ do
+ [[ -d $WATCH/$PPA ]] && verifyBuild || continue
+ cleanup
+ done
+ cleanup
+else
+ if [[ -d $WATCH/$PPA ]]
+ then
+ verifyBuild
+ else
+ echo "$WATCH/$PPA does not exist"
+ exit 1
+ fi
+ cleanup
+fi
+
+

0 comments on commit 65e80b5

Please sign in to comment.