#!/bin/bash

if [ -d debian ]; then
 if [ -e BUILD_ID ]; then
     export BUILD_ID=`cat BUILD_ID`
     echo "Using found build_id $BUILD_ID"

     if [ "${BUILD_ID}x" == "x" ]; then
        echo "Defined buld_id is empty, defaulting to 1"
        BUILD_ID=1
     fi

     cp debian/changelog debian/.changelog
     cat debian/.changelog | sed '1 s/-[0-9]\{1,\})/-build'$BUILD_ID')/' > debian/changelog
 else 
     echo "No build_id found, using defaults"
 fi

else 
  echo "You must run this on top level of the repository folder"
fi
