#!/bin/bash

# Add here any the actions which are required before plugin build
# like packages building, packages downloading from mirrors and so on.
# The script should return 0 if there were no errors.
#!/bin/bash

set -eux

BUILD_FOR=${BUILD_FOR:-ubuntu}
DIR="$(dirname `readlink -f $0`)"

function build_pkg {
  case $1 in
    ubuntu)
      rm -rf ${DIR}/repositories/ubuntu; mkdir -p ${DIR}/repositories/ubuntu
      rm -rf ${DIR}/build; mkdir -p ${DIR}/build; cd ${DIR}/build;
      git clone https://github.com/openstack/collectd-ceilometer-plugin
      cd  collectd-ceilometer-plugin
      git checkout 6c7cb6adf86fcaa6028ca42867ddcb0582111ab1
      tar cfvz ${DIR}/repositories/ubuntu/collectd-ceilometer.tgz . --exclude=collectd-ceilometer.tgz

      cd ${DIR}/build; ../build-collectd.sh
      cp *.deb ${DIR}/repositories/ubuntu

      rm -rf ${DIR}/build
      ;;
    *) echo "Not supported system"; exit 1;;
  esac
}

for system in $BUILD_FOR
do
  build_pkg $system
done