Module: check_mk
Branch: master
Commit: 09575f2994a022642e1fdfaec0084600adb5ff8b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=09575f2994a022…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Thu Sep 28 16:50:24 2017 +0200
Build Windows agent within chroot jail
* Add necessary packages to debootstrap.
* Mount entire sources under chroot/build to make symlinks work.
* Add optinal parameters to do-chroot for commands to be executed within
chroot jail.
* Add 'make-agent' script for building agent within chroot jail.
Change-Id: I72db1294938b6868a00356c02ab489f4b93a7440
---
agents/windows/Makefile | 7 -----
agents/windows/do-chroot | 15 ++++++++---
agents/windows/make-agent | 53 +++++++++++++++++++++++++++++++++++++
agents/windows/make-chroot | 66 +++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 128 insertions(+), 13 deletions(-)
diff --git a/agents/windows/Makefile b/agents/windows/Makefile
index 383c5c2..1b0afb6 100644
--- a/agents/windows/Makefile
+++ b/agents/windows/Makefile
@@ -215,10 +215,3 @@ clean:
mrproper: clean
rm -f *.exe
-
-setup:
- sudo apt-get install \
- nsis \
- lcab \
- debootstrap \
- debian-archive-keyring
diff --git a/agents/windows/do-chroot b/agents/windows/do-chroot
index be7fb50..f1db6ec 100755
--- a/agents/windows/do-chroot
+++ b/agents/windows/do-chroot
@@ -1,9 +1,14 @@
#!/bin/bash
+
+# $1: cmd(s) to be executed within chroot jail
+# if non-existent, enter chroot jail with 'bash -l'
+CMD="$1"
+
export HOSTNAME=cmk-windows-agent-chroot
unset LANG
-BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" &&
pwd)"
-MNT=$BASE/chroot
+BASE="$(dirname "$(dirname "$(cd "$(dirname
"${BASH_SOURCE[0]}")" && pwd)")")"
+MNT=$BASE/agents/windows/chroot
if [ ! -e $MNT/proc/self ] ; then
mount -t proc proc $MNT/proc
@@ -21,7 +26,11 @@ if [ ! -e $MNT/build/Makefile ] ; then
mount -o bind $BASE $MNT/build
fi
-chroot chroot bash -l
+if [ -n "$CMD" ] ; then
+ chroot chroot bash -c "$CMD"
+else
+ chroot chroot bash -l
+fi
umount $MNT/build
umount $MNT/dev/pts
diff --git a/agents/windows/make-agent b/agents/windows/make-agent
new file mode 100755
index 0000000..9b45984
--- /dev/null
+++ b/agents/windows/make-agent
@@ -0,0 +1,53 @@
+#!/bin/bash
+# The script builds Windows agent within a chroot jail.
+#
+# Possible targets given as parameter(s) to this script:
+# setup - install dependencies for chroot
+# chroot - create a chroot for building Windows agent
+# * - other targets passed to make within chroot, see Makefile
+
+targets="$@" # no parameter -> default make target
+setup_target=setup
+chroot_target=chroot
+
+check_no_of_targets() {
+ if [ $1 != 1 ] ; then
+ echo "You cannot combine $2 with other targets."
+ exit 1
+ fi
+}
+
+# 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
+fi
+
+# chroot target: create a chroot for building Windows agent
+if [[ " $targets " =~ " $chroot_target " ]] ; then
+ check_no_of_targets $# $chroot_target
+ sudo ./make-chroot
+ exit
+fi
+
+# all other targets: assume chroot exists and pass targets to make inside chroot
+
+base="$(dirname "$(dirname "$(cd "$(dirname
"${BASH_SOURCE[0]}")" && pwd)")")"
+mnt=$base/agents/windows/chroot
+
+if [ ! -d "$mnt/build" ] ; then
+ echo "Did you forget to call '${BASH_SOURCE[0]} chroot' first?"
+ exit 1
+fi
+
+sudo ./do-chroot "cd build/agents/windows; make $targets"
+
+# Some cleanup: chown build artifacts to the original user.
+find . -maxdepth 1 -regextype egrep \
+-regex '(.*\.(exe|msi|rc|res))|.*\/obj.*|.*build_version|.*plugins|.*msibuild' \
+-exec sudo chown -R $USER:$USER {} \;
diff --git a/agents/windows/make-chroot b/agents/windows/make-chroot
index aa42a5a..f420455 100755
--- a/agents/windows/make-chroot
+++ b/agents/windows/make-chroot
@@ -10,8 +10,8 @@
MIRROR=http://de.archive.ubuntu.com/ubuntu
export HOSTNAME=cmk-windows-agent-chroot
export LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8
-BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" &&
pwd)"
-MNT=$BASE/chroot
+BASE="$(dirname "$(dirname "$(cd "$(dirname
"${BASH_SOURCE[0]}")" && pwd)")")"
+MNT=$BASE/agents/windows/chroot
cleanup_chroot() {
PIDS=$(lsof -Fp $MNT 2>/dev/null | cut -dp -f2)
@@ -42,10 +42,63 @@ rm -rf $MNT/*
echo "+ INSTALLING SYSTEM"
+package_names=(
+ "ca-certificates"
+ "gcc"
+ "gettext"
+ "git"
+ "lcab"
+ "libauthen-sasl-perl"
+ "libc6-dev"
+ "libencode-locale-perl"
+ "libfile-listing-perl"
+ "libfont-afm-perl"
+ "libglib2.0-dev"
+ "libgsf-1-dev"
+ "libgtk2.0-dev"
+ "libhtml-form-perl"
+ "libhtml-format-perl"
+ "libhtml-parser-perl"
+ "libhtml-tagset-perl"
+ "libhtml-tree-perl"
+ "libhttp-cookies-perl"
+ "libhttp-daemon-perl"
+ "libhttp-date-perl"
+ "libhttp-message-perl"
+ "libhttp-negotiate-perl"
+ "libio-html-perl"
+ "libio-socket-ssl-perl"
+ "liblwp-mediatypes-perl"
+ "liblwp-protocol-https-perl"
+ "libmailtools-perl"
+ "libnet-http-perl"
+ "libnet-smtp-ssl-perl"
+ "libnet-ssleay-perl"
+ "libperl-dev"
+ "libtimedate-perl"
+ "liburi-perl"
+ "libwww-perl"
+ "libwww-robotrules-perl"
+ "libxml-parser-perl"
+ "linux-base"
+ "locales"
+ "make"
+ "mingw-w64"
+ "nsis"
+ "openssl"
+ "patch"
+ "perl-openssl-defaults"
+ "pkg-config"
+ "python2.7"
+ "uuid-dev"
+ "wine-stable"
+)
+packages=$(IFS=,; echo "${package_names[*]}")
+
# TODO: Would use --force-check-gpg, but not supported on wheezy (root server)
debootstrap \
--components=main,universe \
- --include=linux-base,locales,mingw-w64,wine-stable \
+ --include="$packages" \
--arch amd64 $DISTRO $MNT $MIRROR
# Need to be installed for installation.
@@ -78,6 +131,13 @@
PS1='\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033
PS1="\[\e]0;\${debian_chroot:+(\$debian_chroot)}\u@\h: \w\a\]\$PS1"
EOF
+# Debian pkg installation does not seem to link python executable
+if [ ! -h $MNT/usr/bin/python ] ; then
+ cd $MNT/usr/bin
+ ln -s python2.7 python
+ cd -
+fi
+
mkdir $MNT/build
echo "+ CLEANING UP"