Module: check_mk
Branch: master
Commit: e7ae01ecf9bfce845dc4dac8e0936037b9f0b019
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e7ae01ecf9bfce…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Wed Oct 4 11:40:07 2017 +0200
Windows agent: do setup & chroot targets on demand
Change make-agent script to implicitly execute setup and chroot targets
if necessary, that is, if the chroot jail has not already been properly
set up or should be updated. Allow setup and chroot to be given as
explicit targets, possibly combined with explicit make targets within
chroot.
Change-Id: I4500828af52c0b6ba5f271d13506eac3a867c4e1
---
agents/windows/chroot_version | 1 +
agents/windows/make-agent | 77 ++++++++++++++++++++++++++++++-------------
agents/windows/make-chroot | 1 +
3 files changed, 56 insertions(+), 23 deletions(-)
diff --git a/agents/windows/chroot_version b/agents/windows/chroot_version
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/agents/windows/chroot_version
@@ -0,0 +1 @@
+0
diff --git a/agents/windows/make-agent b/agents/windows/make-agent
index 9b45984..4c646aa 100755
--- a/agents/windows/make-agent
+++ b/agents/windows/make-agent
@@ -5,46 +5,77 @@
# setup - install dependencies for chroot
# chroot - create a chroot for building Windows agent
# * - other targets passed to make within chroot, see Makefile
+#
+# Note: setup and chroot can be combined with explicit targets passed to make
+# inside chroot. However, giving setup or chroot without further targets does
+# *not* implicitly trigger default make target within chroot.
targets="$@" # no parameter -> default make target
setup_target=setup
chroot_target=chroot
+chroot_dependencies=(nsis lcab debootstrap debian-archive-keyring)
+versionfile=chroot_version
-check_no_of_targets() {
- if [ $1 != 1 ] ; then
- echo "You cannot combine $2 with other targets."
- exit 1
+base="$(dirname "$(dirname "$(cd "$(dirname
"${BASH_SOURCE[0]}")" && pwd)")")"
+mnt=$base/agents/windows/chroot
+
+setup() {
+ sudo apt-get install "${chroot_dependencies[@]}"
+}
+
+ensure_chroot() {
+ # Ensure that versionfile exists...
+ if [ ! -f "$mnt/$versionfile" ] ; then
+ echo "chroot version not found."
+ create=yes
+ # ... and it is up to date.
+ elif [ $(cat "$mnt/$versionfile") -ne $(cat
"$base/agents/windows/$versionfile") ] ; then
+ echo "chroot is out of date."
+ create=yes
+ fi
+
+ if [ -z $create ] ; then
+ echo "chroot is up to date."
+ else
+ setup
+ sudo VERSIONFILE=$versionfile ./make-chroot
fi
}
-# setup target: install dependencies for chroot
+remove_target() {
+ targets=$(sed -e "s/$1//g" \
+ -e "s/^[[:blank:]]*//g" \
+ -e "s/[[:blank:]]*$//g" <<< "$targets")
+}
+
+if [ ! -f "$base/agents/windows/$versionfile" ] ; then
+ echo "Error: File $base/agents/windows/$versionfile not found."
+ echo "Is your Git repository up to date?"
+ exit 1
+fi
+
+# 1) setup target: install dependencies for chroot
if [[ " $targets " =~ " $setup_target " ]] ; then
- check_no_of_targets $# $setup_target
- sudo apt-get install \
- nsis \
- lcab \
- debootstrap \
- debian-archive-keyring
- exit
+ setup
+ remove_target $setup_target
fi
-# chroot target: create a chroot for building Windows agent
+# 2) chroot target: create a chroot for building Windows agent
if [[ " $targets " =~ " $chroot_target " ]] ; then
- check_no_of_targets $# $chroot_target
- sudo ./make-chroot
- exit
+ ensure_chroot
+ remove_target $chroot_target
fi
-# all other targets: assume chroot exists and pass targets to make inside chroot
+# If no other targets are left but originally there was at least one,
+# we did either setup or chroot -> we are done now (let us not do default make)
+[ -z "$targets" ] && [ $# != 0 ] && exit
-base="$(dirname "$(dirname "$(cd "$(dirname
"${BASH_SOURCE[0]}")" && pwd)")")"
-mnt=$base/agents/windows/chroot
+# 3) all other targets (including default target):
-if [ ! -d "$mnt/build" ] ; then
- echo "Did you forget to call '${BASH_SOURCE[0]} chroot' first?"
- exit 1
-fi
+# Ensure that chroot exists and is up to date.
+ensure_chroot
+# Pass remaining targets to make inside chroot.
sudo ./do-chroot "cd build/agents/windows; make $targets"
# Some cleanup: chown build artifacts to the original user.
diff --git a/agents/windows/make-chroot b/agents/windows/make-chroot
index f420455..f61586f 100755
--- a/agents/windows/make-chroot
+++ b/agents/windows/make-chroot
@@ -139,6 +139,7 @@ if [ ! -h $MNT/usr/bin/python ] ; then
fi
mkdir $MNT/build
+cp "$BASE/agents/windows/$VERSIONFILE" "$MNT/"
echo "+ CLEANING UP"