get_snapshot 2.76 KB
Newer Older
Markus Frosch's avatar
Markus Frosch committed
1
#!/bin/bash
Markus Frosch's avatar
Markus Frosch committed
2
3
# Copyright (c) 2017 Icinga Development Team <info@icinga.com>
# Licensed as GPL-2.0+
Markus Frosch's avatar
Markus Frosch committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

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

34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
        fi
        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}"
48
        fi
49
50
51
52
53
54
55
        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
56
    fi
Markus Frosch's avatar
Markus Frosch committed
57
58
fi

59
git_version=$(git describe --tags "${UPSTREAM_GIT_BRANCH}")
60

61
# TEMP: Fixup version for 2.11.2 - so that it is displayed as 2.11.2
62
if [[ "$git_version" = v2.11.0* ]]; then
63
    git_version="$(echo "$git_version" | sed s/2.11.0/2.11.2/)"
64
65
fi

66
67
68
69
70
71
if [ `echo "$git_version" | grep -v -E '(g[0-9a-f]+)$'` ]; then
	echo "This is a release tagged commit and does not fit the naming scheme, it will confuse the packaging server.
It's safer to wait for the next commit. Have a nice day."
	exit 1
fi

72
73
74
75
76
if [[ "$git_version" = *2.6.3* ]]; then
  package_version=$(echo "$git_version" | sed -e 's/^v//' -e 's/-/+t/' -e 's/-/./g')
else
  package_version=$(echo "$git_version" | sed -e 's/^v//' -e 's/-/+/' -e 's/-/./g')
fi
Markus Frosch's avatar
Markus Frosch committed
77
78
tarball="${workdir}/${PROJECT}_${package_version}.orig.tar"

79
git archive --format=tar --prefix="${PROJECT}_${package_version}/" -o "${tarball}" "${UPSTREAM_GIT_BRANCH}"
Markus Frosch's avatar
Markus Frosch committed
80
81
82
83
84
85
86
87
88
89
90
91

# creating version file for tarball
echo "#define VERSION \"$git_version\"" > icinga-version.h.force
# TODO: do we need this?
#touch -d`date +%Y%m%d` icinga-version.h.force
tar --append -f "${tarball}" --transform "s@^@${PROJECT}_${package_version}/@" icinga-version.h.force

# pack tarball
gzip -vf9 "${tarball}"
sha256sum "${tarball}.gz"

# store package version for build scripts
92
echo -e "${package_version}\t$(git rev-parse "${UPSTREAM_GIT_BRANCH}")\t$(basename "${tarball}.gz")\t${UPSTREAM_GIT_BRANCH}" > "${workdir}/${PROJECT}.version"