--- /dev/null
+#!/bin/bash
+
+# copyright 2012 Holger Levsen <holger@layer-acht.org>
+# GPL2 licenced
+
+# Quick and dirty hack for master branch on 2014-09-12 by bdrung
+
+set -e
+set -x
+export
+
+#
+# Define default settings
+#
+export DIST=squeeze
+export PB_SUITE=$DISTRIBUTION
+export TARGET_BASE=/srv/storage-kernels
+
+# get the last build number of the given target,
+# parsing tarball's file name under /srv/storage-kernels/.
+function get_last_target_build_no() {
+ TARGET_NAME=$1
+
+ if [ -n "$TARGET_NAME" ]; then
+ retval=$(find $TARGET_BASE/$TARGET_NAME -maxdepth 1 -type f \
+ -name 'linux-storage*tar.xz' | grep -v "^.$" \
+ | sed -e "s|$TARGET_BASE/$TARGET_NAME||g" \
+ | sed -e "s|.*\/linux-storage_[0-9a-zA-Z\.]*\.\([^\.]*\).tar.xz$|\1|g" \
+ | sort -n | tail -n 1)
+ [ -z "$retval" ] && retval="0"
+ else
+ retval="0"
+ fi
+
+ echo $retval
+}
+
+# overwrite PB_SUITE with branch name
+export PB_SUITE=$(echo $GIT_BRANCH_NAME | tr '/' '-' | sed -e "s/^\(feature\|bugfix\|poc\)-/dev-\1-/g")
+
+case $DISTRIBUTION in
+ production-proposed-updates)
+ export TARGET_NAME=master
+ FEATURE_APTCMD="
+ echo \"deb http://alexandria.pb.local/profitbricks-repository $DISTRIBUTION main contrib non-free\" \
+ > /etc/apt/sources.list.d/profitbricks-linux-image-storage-$TARGET_NAME.list
+ "
+ ;;
+ pre-staging)
+ export TARGET_NAME=develop
+ FEATURE_APTCMD="
+ echo \"deb http://alexandria.pb.local/profitbricks-repository $DISTRIBUTION main contrib non-free\" \
+ > /etc/apt/sources.list.d/profitbricks-linux-image-storage-$TARGET_NAME.list
+ "
+ ;;
+ experimental|dev_feature*)
+ [ -n "$PB_SUITE" ] && export TARGET_NAME=$PB_SUITE || export TARGET_NAME="experimental"
+ LAST_DEVELOP_BUILD_NO=$(get_last_target_build_no develop)
+ BUILD_NUMBER="$LAST_DEVELOP_BUILD_NO.$(printf %03d $BUILD_NUMBER)"
+
+ # kernel images must be installed from a branch-specific distribution
+ # under dev-repository. However, ANDBD modules must be installed from
+ # the pre-staging distribution, because ANDBD modules must have not
+ # been built into packages under a particular distribution.
+ FEATURE_APTCMD="
+ echo \"deb http://alexandria.pb.local/dev-repository $TARGET_NAME main contrib non-free\" \
+ > /etc/apt/sources.list.d/profitbricks-linux-image-storage-$TARGET_NAME.list ; \
+ echo \"deb http://alexandria.pb.local/profitbricks-repository pre-staging main contrib non-free\" \
+ > /etc/apt/sources.list.d/profitbricks-linux-image-storage-develop.list
+ "
+ FEATURE_VERSCMD="
+ export FEATURE_VERSION=\`apt-cache showpkg profitbricks-linux-image-storage -a \
+ | grep $TARGET_NAME | grep \) | sed -e \"s|\([^\.]*\)\ .*$|\1|g\"\`
+ "
+ ;;
+ *)
+ echo "DISTRIBUTION must be 'production-proposed-updates', 'pre-staging', 'experimental',"
+ echo "or 'dev_feature*'"
+ echo "exiting."
+ figlet "FAIL"
+ exit 1
+ ;;
+esac
+
+export TARGET_DIR=$TARGET_BASE/$TARGET_NAME/$BUILD_NUMBER
+export JOB_HOME=$JENKINS_HOME/jobs/$JOB_NAME/builds
+
+SCRIPTSDIR=$(dirname $0)
+BUILD_SCRIPT=$(mktemp -t ${0##*/}.XXXXXXXXXX)
+cat > $BUILD_SCRIPT <<-EOF
+#/bin/bash
+set -e
+set -x
+apt-get update
+# grub is needed in the postinst...
+apt-get install -y grub2
+$FEATURE_VERSCMD
+[ -n "###FEATURE_VERSION" ] && export FEATURE_VERSION="=###FEATURE_VERSION"
+apt-get -t $DISTRIBUTION -y install profitbricks-linux-image-storage###FEATURE_VERSION || true
+apt-get -y install profitbricks-andbd-modules-storage || true
+mkdir -p $TARGET_DIR
+export KERNEL_VERSION=###(ls /boot/vmlinu* | cut -d "-" -f2-)
+export GENTOO_KERNEL_VERSION="###(ls /boot/vmlinu* | cut -d "-" -f2).$BUILD_NUMBER"
+cp -v /boot/vmlinu* $TARGET_DIR/
+cp -v /boot/config* $TARGET_DIR/
+cd /lib/modules/###{KERNEL_VERSION}
+/bin/tar -cJvf $TARGET_DIR/modules-###{KERNEL_VERSION}.tar.xz .
+echo "Job : $JOB_NAME" > $TARGET_DIR/sources.txt
+echo "Build-Nr.: $BUILD_NUMBER" >> $TARGET_DIR/sources.txt
+echo "URL : http://jenkins/job/$JOB_NAME/$BUILD_NUMBER/" >> $TARGET_DIR/sources.txt
+echo "Kernel: : ###KERNEL_VERSION" >> $TARGET_DIR/sources.txt
+echo >> $TARGET_DIR/sources.txt
+apt-cache show profitbricks-linux-image-storage >> $TARGET_DIR/sources.txt
+apt-cache show profitbricks-andbd-modules-storage >> $TARGET_DIR/sources.txt
+/bin/tar -cJvf $TARGET_BASE/$TARGET_NAME/linux-storage_###{GENTOO_KERNEL_VERSION}.tar.xz -C $TARGET_DIR .
+EOF
+chmod +x $BUILD_SCRIPT
+# turn the shell call back into a shell call
+sed -i -s "s|###|$|g" $BUILD_SCRIPT
+
+#
+# run $BUILD_SCRIPT in chroot environment
+#
+sudo pbuilder --execute --bindmounts $TARGET_BASE -- $BUILD_SCRIPT
+rm $BUILD_SCRIPT
+
+set +x
+echo "Doing garbage collection now"
+#
+# cleanup $TARGET_DIR, keep as many images as jenkins keeps build logs
+#
+cd $TARGET_BASE/$TARGET_NAME
+# loop through all results of current target
+for i in $(find . -maxdepth 1 -type d|sort) ; do
+ # check if the jenkins build log still exists (and $i != ".")
+ # and if not, delete the old target as well
+ if [ ! -L $JOB_HOME/$i ] && [ "${i}" != "." ] ; then
+ echo "Deleting $TARGET_BASE/$TARGET_NAME/$i"
+ sudo rm -r ./$i
+ fi
+done
+
+figlet "OK"
+
+