2017-02-08 13:56:24 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright (c) 2017 Icinga Development Team <info@icinga.com>
|
|
|
|
# Licensed as GPL-2.0+
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
while getopts ":p:U:b:" opt
|
|
|
|
do
|
|
|
|
case "$opt" in
|
|
|
|
p)
|
|
|
|
PROJECT="$OPTARG"
|
|
|
|
;;
|
|
|
|
U)
|
|
|
|
UPSTREAM_GIT_URL="$OPTARG"
|
|
|
|
;;
|
|
|
|
b)
|
|
|
|
UPSTREAM_GIT_BRANCH="$OPTARG"
|
|
|
|
;;
|
|
|
|
\?)
|
|
|
|
echo "Unknown argument: $OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
: ${PROJECT:=icinga2}
|
|
|
|
: ${UPSTREAM_GIT_URL:=https://github.com/Icinga/$PROJECT.git}
|
|
|
|
: ${UPSTREAM_GIT_BRANCH:=master}
|
|
|
|
|
|
|
|
workdir=`pwd`
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
2017-06-07 15:28:45 +02:00
|
|
|
if [ -z "$UPSTREAM_GIT_NOREPO" ]; then
|
|
|
|
if [ -d "${PROJECT}.git/" ]; then
|
|
|
|
cd "${PROJECT}.git"
|
|
|
|
if [ ! -d .git ]; then
|
|
|
|
echo "This is not a GIT repository: $(pwd)" >&2
|
|
|
|
exit 1
|
2017-06-07 14:52:17 +02:00
|
|
|
fi
|
2017-06-07 15:28:45 +02:00
|
|
|
if [ -z "$UPSTREAM_GIT_NOUPDATE" ]; then
|
|
|
|
if [ "$(git config remote.origin.url)" != "${UPSTREAM_GIT_URL}" ]; then
|
|
|
|
git remote set-url origin "${UPSTREAM_GIT_URL}"
|
|
|
|
fi
|
|
|
|
git fetch origin -p
|
|
|
|
git checkout -f "${UPSTREAM_GIT_BRANCH}"
|
|
|
|
git reset --hard "origin/${UPSTREAM_GIT_BRANCH}"
|
|
|
|
fi
|
|
|
|
git clean -fdx
|
|
|
|
elif [ -z "$UPSTREAM_GIT_NOUPDATE" ]; then
|
|
|
|
git clone -b "${UPSTREAM_GIT_BRANCH}" "${UPSTREAM_GIT_URL}" "${PROJECT}.git/"
|
|
|
|
cd "${PROJECT}.git"
|
|
|
|
else
|
|
|
|
echo "Missing '${PROJECT}.git' directory!" >&2
|
|
|
|
exit 1
|
2017-02-08 16:55:55 +01:00
|
|
|
fi
|
2017-02-08 13:56:24 +01:00
|
|
|
fi
|
|
|
|
|
2017-06-07 15:21:25 +02:00
|
|
|
git_version=$(git describe --tags "${UPSTREAM_GIT_BRANCH}")
|
2017-02-08 13:56:24 +01:00
|
|
|
package_version=$(echo "$git_version" | sed -e 's/^v//' -e 's/-/./g')
|
|
|
|
tarball="${workdir}/${PROJECT}-${package_version}.tar"
|
|
|
|
|
2017-06-07 15:21:25 +02:00
|
|
|
git archive --format=tar --prefix="${PROJECT}-${package_version}/" -o "${tarball}" "${UPSTREAM_GIT_BRANCH}"
|
2017-02-08 13:56:24 +01:00
|
|
|
|
|
|
|
# creating version file for tarball
|
2017-04-21 16:06:37 +02:00
|
|
|
mkdir "${PROJECT}-${package_version}"
|
|
|
|
echo "#define VERSION \"$git_version\"" > "${PROJECT}-${package_version}/"icinga-version.h.force
|
|
|
|
tar --append -f "${tarball}" "${PROJECT}-${package_version}/"*
|
|
|
|
rm -rf "${PROJECT}-${package_version}"
|
2017-02-08 13:56:24 +01:00
|
|
|
|
|
|
|
# pack tarball
|
|
|
|
gzip -vf9 "${tarball}"
|
|
|
|
sha256sum "${tarball}.gz"
|
|
|
|
|
|
|
|
# store package version for build scripts
|
2017-06-07 15:21:25 +02:00
|
|
|
echo -e "${package_version}\t$(git rev-parse "${UPSTREAM_GIT_BRANCH}")\t$(basename "${tarball}.gz")\t${UPSTREAM_GIT_BRANCH}" > "${workdir}/${PROJECT}.version"
|