forked from perfsonar/debian-docker-buildmachines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps-source-builder
executable file
·130 lines (117 loc) · 4.11 KB
/
ps-source-builder
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
129
#!/usr/bin/env bash
# extglob is needed for the call to tar in the binary build
shopt -s extglob
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [-t DEBIAN_TAG] [-k] [-s] [-u] [REPO]
This script builds a perfSONAR package out of a git REPO.
The build happens for the $DIST Debian distro (\$DIST should be set in your ENV).
Arguments understood:
-k: use and keep locally built packages (can be useful to solve dependencies)
-s: build only the source package
-t: git tag to build from (defaults no tag)
(upstream is read from gbp.conf)
-u: don't checkout nor update the local git repository
(useful for subsequent builds with no change to sources)
Some examples:
./${0##*/} toolkit
./${0##*/} -t debian/stretch/4.2.1 toolkit
package=pscheduler-archiver-esmond ./${0##*/} pscheduler
EOF
# Other examples: to rebuild everything in the local repo:
# for p in `ls -al pscheduler/source/ | awk '/pscheduler/ {print $9}' | grep -vE "pscheduler-(docs|rpm)" | sort -r`; do package=$p ./ps-source-builder pscheduler; done
# for p in jq python-icmperror python-jsonschema python-jsontemplate python-pyjq python-pyrsistent python-radix python-pscheduler `ls pscheduler/source | grep -E "^pscheduler" | grep -v "pscheduler-rpm"`; do package=$p ./ps-source-builder pscheduler; done
}
# Defaults
# Repository to get source from
REPO_LOC='/mnt/build/'
BUILD_SRC=${REPO_LOC}'build_source'
BUILD_RESULTS=${REPO_LOC}'build_results'
mkdir -p ${BUILD_SRC}
mkdir -p ${BUILD_RESULTS}
# Checked out source directory
SRC_DIR='source'
cd ${BUILD_SRC}
# Default values
unset tag
unset source_only
git_update=true
keep_builds=false
# Parsing options
while getopts "t:ksu" OPT; do
case $OPT in
k) keep_builds=true ;;
s) source_only=true ;;
t) tag=$OPTARG ;;
u) unset git_update ;;
'?')
show_help >&2
exit 1 ;;
esac
done
shift $((OPTIND-1))
# Check if we still have an argument left
if [ $# -gt 0 ]; then
REPO=$1
fi
if [ -z "$REPO" ]; then
show_help >&2
exit 1
fi
echo -n "CPU architecture is "
lscpu | grep Architecture | cut -c 22-
# Do we want to clone the repo or do we have it already existing?
if $git_update ; then
# Checkout source from local dev repo
rm -rf "${REPO}"
git clone "${REPO_LOC}${REPO}" "${REPO}/${SRC_DIR}"
cd "${REPO}/${SRC_DIR}"
# Do we have a tag?
if [ -n "$tag" ]; then
# We have a tag, say we will build from it (build-source-package.sh uses it)
export tag
branch=`git branch --contains "tags/${tag}" | awk '{print $2}'`
else
# We build from current branch
branch=`git rev-parse --abbrev-ref HEAD`
fi
git checkout "$branch"
elif [ -d "${REPO}/${SRC_DIR}" ]; then
echo "I'm using the existing ${REPO} directory."
cd "${REPO}/${SRC_DIR}/.."
rm -f .git
mv "${SRC_DIR}/.git" .
rm -rf *
mkdir -p "${SRC_DIR}"
cd "${SRC_DIR}"
mv ../.git .
# Restoring pristine repo
git checkout -- *
branch=`git rev-parse --abbrev-ref HEAD`
else
echo "You asked me to reuse the existing ${REPO} directory but it doesn't seem right."
exit 1
fi
# Announce what we'll do!
echo -e "\nBuilding \033[1;32m${REPO}\033[0;37m from branch \033[1;36m${branch}\033[0;37m on \033[1;32m${ARCH}\033[0;37m.\n"
[ $tag ] && echo -e "\033[1;32mThis is a \033[1;33mrelease\033[1;32m, tag \033[1;33m${tag}\033[1;32m will be built !\033[0m\n"
# TODO: Pass this directory to build-source-package to solve dependencies
if $keep_builds ; then
/usr/local/bin/ps-local-repo ${REPO_LOC}/build_results/
else
rm -rf ${REPO_LOC}/build_results/*
(cd ${REPO_LOC}/build_results/; apt-ftparchive packages . > Packages)
fi
cd ..
# Build the source package
apt-get update
${REPO_LOC}/debian-docker-buildmachines/build-source-package.sh
[ $? -eq 0 ] || exit 1
PKG=`awk '/^Source:/ {print $2}' *.dsc`
VERSION=`awk '/^Version:/ {print $2}' *.dsc`
if [ ${source_only} ]; then
echo
echo -e "I have built the source package for \033[1;32m${PKG}\033[0m at \033[1;32m${VERSION}\033[0m and you asked me to stop.\n"
exit 1
fi