Module: check_mk
Branch: master
Commit: 7e2a272d3d4140973f5f180f06d9a3af38d2a770
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7e2a272d3d4140…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Sep 20 10:41:31 2017 +0200
Started chroot based build environment for windows agent
---
agents/windows/.gitignore | 1 +
agents/windows/Makefile | 6 +--
agents/windows/do-chroot | 30 +++++++++++++++
agents/windows/make-chroot | 92 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 125 insertions(+), 4 deletions(-)
diff --git a/agents/windows/.gitignore b/agents/windows/.gitignore
index 3686414..b565751 100644
--- a/agents/windows/.gitignore
+++ b/agents/windows/.gitignore
@@ -17,3 +17,4 @@ testtools
*.d
*.o
wmitest.exe
+chroot
diff --git a/agents/windows/Makefile b/agents/windows/Makefile
index 05f223c..42efbad 100644
--- a/agents/windows/Makefile
+++ b/agents/windows/Makefile
@@ -220,7 +220,5 @@ setup:
sudo apt-get install \
nsis \
lcab \
- binutils-mingw-w64-i686 \
- binutils-mingw-w64-x86-64 \
- g++-mingw-w64-i686 \
- g++-mingw-w64-x86-64
+ debootstrap \
+ ubuntu-archive-keyring
diff --git a/agents/windows/do-chroot b/agents/windows/do-chroot
new file mode 100755
index 0000000..be7fb50
--- /dev/null
+++ b/agents/windows/do-chroot
@@ -0,0 +1,30 @@
+#!/bin/bash
+export HOSTNAME=cmk-windows-agent-chroot
+unset LANG
+
+BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" &&
pwd)"
+MNT=$BASE/chroot
+
+if [ ! -e $MNT/proc/self ] ; then
+ mount -t proc proc $MNT/proc
+fi
+
+if [ ! -e $MNT/dev/sda ] ; then
+ mount -o bind /dev $MNT/dev
+fi
+
+if [ ! -e $MNT/dev/pts/ptmx ] ; then
+ mount -t devpts devpts $MNT/dev/pts 2>/dev/null || true
+fi
+
+if [ ! -e $MNT/build/Makefile ] ; then
+ mount -o bind $BASE $MNT/build
+fi
+
+chroot chroot bash -l
+
+umount $MNT/build
+umount $MNT/dev/pts
+sleep 2
+umount $MNT/dev
+umount $MNT/proc
diff --git a/agents/windows/make-chroot b/agents/windows/make-chroot
new file mode 100755
index 0000000..aa42a5a
--- /dev/null
+++ b/agents/windows/make-chroot
@@ -0,0 +1,92 @@
+#!/bin/bash
+# The script creates a chroot based on a current ubuntu version
+# and installs all dependencies needed to build the windows agent.
+
+set -e
+
+DISTRO=zesty
+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
+
+cleanup_chroot() {
+ PIDS=$(lsof -Fp $MNT 2>/dev/null | cut -dp -f2)
+ [ -n "$PIDS" ] && kill -9 $PIDS 2>&1
+
+ [ -e $MNT/dev/pts/ptmx ] && umount $MNT/dev/pts && sleep 2
+ [ -e $MNT/dev/sda ] && umount $MNT/dev && sleep 2
+ [ -e $MNT/proc/self ] && umount $MNT/proc && sleep 2
+
+ if mount | grep $MNT >/dev/null; then
+ echo "Error: There are still mounts below $MNT. Terminating."
+ exit 1
+ fi
+}
+
+if [ "$(id -u)" != "0" ]; then
+ echo "Sorry, you are not root. Change or execute this script with sudo."
+ exit 1
+fi
+
+unset LANG
+
+echo "+ CLEANING UP CHROOT"
+cleanup_chroot
+
+# chroot leer machen
+rm -rf $MNT/*
+
+echo "+ INSTALLING SYSTEM"
+
+# 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 \
+ --arch amd64 $DISTRO $MNT $MIRROR
+
+# Need to be installed for installation.
+cat <<EOF > $MNT/etc/fstab
+# created by make-chroot
+/dev/sda1 / ext2 rw,noatime,nodiratime,errors=continue 0 1
+EOF
+
+# Nun ein kleiner Hack um zu verhindern, dass beim Installieren der Pakete
+# die Daemonen der Pakete gestartet werden. Ist nicht dramatisch, erzeugt
+# aber doofe Fehlermeldungen.
+echo exit 101 > $MNT/usr/sbin/policy-rc.d
+chmod +x $MNT/usr/sbin/policy-rc.d
+
+cp /etc/resolv.conf $MNT/etc/resolv.conf
+
+if [ ! -e $MNT/bin/hostname.bin ] ; then
+ mv $MNT/bin/hostname{,.bin}
+fi
+cat <<EOF > $MNT/bin/hostname
+echo $HOSTNAME
+EOF
+chmod +x $MNT/bin/hostname
+
+# Uses debian_chroot, but use it for all distros!
+#debian_chroot=\$(hostname)
+cat <<EOF > $MNT/root/.bashrc
+debian_chroot=$(hostname)
+PS1='\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\\$
'
+PS1="\[\e]0;\${debian_chroot:+(\$debian_chroot)}\u@\h: \w\a\]\$PS1"
+EOF
+
+mkdir $MNT/build
+
+echo "+ CLEANING UP"
+
+# Raeume apt-cache auf
+ls $MNT/var/cache/apt/archives/*.deb >/dev/null 2>&1 \
+ && rm $MNT/var/cache/apt/archives/*.deb 2>&1 || true
+
+# Alle Prozesse aus dem chroot killen
+cleanup_chroot
+
+echo "+ FINISHED!"