forked from perfsonar/debian-docker-buildmachines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps-binary-builder
executable file
·91 lines (77 loc) · 2.73 KB
/
ps-binary-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
#!/usr/bin/env bash
# extglob is needed for the call to tar in the binary build
shopt -s extglob
# Default values
keep_builds=false
# Parsing options
while getopts "k" OPT; do
case $OPT in
k) keep_builds=true ;;
esac
done
shift $((OPTIND-1))
# Arg must be the git repo to build
GITREPO=$1
# Defaults
# Repository to get source from
REPO_LOC='/mnt/build/'
BUILD_SRC=${REPO_LOC}'build_source'
BUILD_RESULTS=${REPO_LOC}'build_results'
SRC_DIR='source'
BUILD_DIR='binary'
# Go where the source package is
cd ${BUILD_SRC}/${GITREPO}
# Announce what we'll do!
# We get $BUILD_ARCH, $DIST and $RELEASE from the content of the source package
. ${REPO_LOC}/debian-docker-buildmachines/check-release-repo.sh
[ $? -eq 0 ] || exit 1
# Check build architecture
if [[ `uname -m` != "x86_64" && "$BUILD_ARCH" == "all" ]]; then
echo "I only build binary independent package on amd64. I'll skip this build."
exit 0
fi
# Setup local repository if we have one
if $keep_builds ; then
/usr/local/bin/ps-local-repo ${BUILD_RESULTS}/
fi
# Extract source package
mkdir -p $BUILD_DIR
if grep -q '(native)' *.dsc ; then
echo "This is a Debian native package, there is no orig tarball."
tar -x -C $BUILD_DIR --strip-components 1 -f *.tar.xz
else
tar -x -C $BUILD_DIR --strip-components 1 -f *.orig.*
tar -x -C $BUILD_DIR -f *.debian.*
fi
cd $BUILD_DIR
# If we were given an second argument, we run it as a command, cheap debugging
if [ "$2" ]; then
echo -e "\n\033[1;33mWe've been given a second argument, we'll run it instead of the build command.\033[0m\n"
$2
exit
fi
# Install build dependencies
apt-get update
mk-build-deps --install --tool 'apt-get --yes --no-install-recommends -o Debug::pkgProblemResolver=yes' --remove
# Alternative: `apt build-dep ./`
# Build binary package without signing
# TODO: for Jenkins, we'll want signing!
if [ `uname -m` == "x86_64" ]; then
# Only run lintian on amd64 (automatically called from debuild)
debuild -i -us -uc -sa -b
else
# Calling directly dpkg-buildpackage on other ARCHES so we don't run Lintian that seems to have an issue when running under QEMU
dpkg-buildpackage -us -uc -i -sa -b
fi
if [ $? -eq 0 ]; then
# We copy the resulting packages back to the main host
echo -e "\n\033[1;32mBuild succeeded, the resulting packages will be copied to the shared volume ${BUILD_RESULTS}\033[0m\n"
cp -afv ../!(${SRC_DIR}|${BUILD_DIR}) ${BUILD_RESULTS}
# And create a Packages file to serve as a local deb repo
echo -en "\nUpdating the APT local repository Packages content (in ${BUILD_RESULTS})"
(cd ${BUILD_RESULTS}; apt-ftparchive packages . > Packages)
echo "."
else
echo -e "\n\033[1;33mSomething went wrong, package not built!\033[0m\n"
exit 1
fi