-
Notifications
You must be signed in to change notification settings - Fork 2
/
include.sh
128 lines (108 loc) · 3.1 KB
/
include.sh
1
2
3
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
# Common code for deb/build.sh and rpm/build.sh.
SCRIPT=$(basename ${BASH_SOURCE[1]})
error() { echo >&2 "$SCRIPT: $*"; exit 1; }
usage() { echo >&2 "invalid command, try \"$SCRIPT --help\""; exit 1; }
# Local directories.
SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE[1]}); pwd)
ROOT_DIR=$(cd $(dirname ${BASH_SOURCE[0]}); pwd)
BUILD_DIR="$ROOT_DIR/build"
REPO_DIR="$BUILD_DIR/librist"
INSTALLER_DIR="$ROOT_DIR/installers"
# URL of git repository.
REPO_URL=$(grep -v -e '^ *$' -e '^ *#' "$ROOT_DIR/URL.txt" | grep 'URL=' | sed 's/URL=//' | tail -1)
REPO_BRANCH=$(grep -v -e '^ *$' -e '^ *#' "$ROOT_DIR/URL.txt" | grep 'BRANCH=' | sed 's/BRANCH=//' | tail -1)
# Display help text
showhelp()
{
cat >&2 <<EOF
Build the RIST library installers.
Usage: $SCRIPT [options]
Options:
-b
--bare-version
Use the "bare version" number from librist, without commit id if there
is no tag on the current commit. By default, use a detailed version
number (most recent version, number of commits since then and short
commit hash).
--clean
Cleanup the build directory and exit.
--help
Display this help text.
--no-build
Do not rebuild RIST library and tools. Assume that they are already
built. Only build the installers.
--no-git
Do not clone or update the librist repository. Assume it is already
up to date and use the current state.
-t name
--tag name
Specify the git tag or commit to build. By default, use the latest
repo state.
EOF
exit 1
}
# Decode command line arguments
BARE_VERSION=false
CLEANUP=false
REBUILD=true
GIT_UPDATE=true
TAG=
while [[ $# -gt 0 ]]; do
case "$1" in
-b|--bare*)
BARE_VERSION=true
;;
--clean)
CLEANUP=true
;;
--help)
showhelp
;;
--no-build)
REBUILD=false
;;
--no-git)
GIT_UPDATE=false
;;
-t|--tag)
[[ $# -gt 1 ]] || usage; shift
TAG=$1
;;
*)
usage
;;
esac
shift
done
# Process cleanup command.
if $CLEANUP; then
rm -rf "$BUILD_DIR"
exit 0
fi
# Create local build directories.
mkdir -p "$BUILD_DIR" "$INSTALLER_DIR"
# Clone repository or update it.
if $GIT_UPDATE; then
if [[ -d "$REPO_DIR/.git" ]]; then
echo "Updating repository ..."
(cd "$REPO_DIR"; git checkout $REPO_BRANCH && git pull origin $REPO_BRANCH)
else
echo "Cloning $REPO_URL ..."
git clone "$REPO_URL" "$REPO_DIR"
[[ -d "$REPO_DIR/.git" ]] || error "failed to clone $REPO_URL"
(cd "$REPO_DIR"; git checkout $REPO_BRANCH)
fi
if [[ -n "$TAG" ]]; then
echo "Checking out $TAG ..."
(cd "$REPO_DIR"; git checkout "$TAG")
fi
fi
# Get librist version
if $BARE_VERSION; then
VERSION=$(cd "$REPO_DIR"; git describe --tags | sed -e 's/^v//' -e 's/-g.*//')
else
VERSION=$(cd "$REPO_DIR"; git describe --tags | sed -e 's/^v//' -e 's/-g/-/')
fi
[[ -n "$VERSION" ]] || error "RIST version not found"
echo "RIST version is $VERSION"