From a715aa45243e18adbe90d1ded2c50c3275ac28ef Mon Sep 17 00:00:00 2001
From: eater <=@eater.me>
Date: Fri, 22 Feb 2019 00:00:25 +0100
Subject: [PATCH] Add grumble and xbps-builder container
---
grumble/Dockerfile | 15 +++++
grumble/files/grumble.ini | 63 +++++++++++++++++++
grumble/files/template | 14 +++++
xbps-builder/Dockerfile | 5 ++
xbps-builder/README.md | 26 ++++++++
xbps-builder/files/fakedchroot.sh | 80 +++++++++++++++++++++++++
xbps-builder/files/setup-fakedchroot.sh | 37 ++++++++++++
7 files changed, 240 insertions(+)
create mode 100644 grumble/Dockerfile
create mode 100644 grumble/files/grumble.ini
create mode 100644 grumble/files/template
create mode 100644 xbps-builder/Dockerfile
create mode 100644 xbps-builder/README.md
create mode 100644 xbps-builder/files/fakedchroot.sh
create mode 100644 xbps-builder/files/setup-fakedchroot.sh
diff --git a/grumble/Dockerfile b/grumble/Dockerfile
new file mode 100644
index 0000000..9bd238b
--- /dev/null
+++ b/grumble/Dockerfile
@@ -0,0 +1,15 @@
+FROM d.xr.to/xbps-builder AS builder
+RUN git pull;
+COPY files/template /_workdir/srcpkgs/grumble/template
+RUN ./xbps-src pkg grumble
+FROM d.xr.to/base AS main
+LABEL maintainer="=@eater.me"
+COPY --from=builder /_workdir/hostdir/binpkgs /tmp/xbps
+RUN xbps-install -SyR /tmp/xbps grumble && xbps-remove -Oo && rm -rf /var/cache/xbps/* /tmp/xbps
+RUN mkdir /grumble
+COPY files/grumble.ini /grumble/grumble.ini
+VOLUME /grumble
+EXPOSE 64738/tcp
+EXPOSE 64738/udp
+EXPOSE 443/tcp
+CMD grumble --datadir /grumble
diff --git a/grumble/files/grumble.ini b/grumble/files/grumble.ini
new file mode 100644
index 0000000..f016f13
--- /dev/null
+++ b/grumble/files/grumble.ini
@@ -0,0 +1,63 @@
+# Grumble configuration file.
+#
+# The commented out settings represent the defaults.
+# Options here may be overridden by virtual server specific configuration.
+# Make sure to enclose values containing # or ; in double quotes or backticks.
+
+# Address to bind the listeners to.
+#host = 0.0.0.0
+
+# port is the port to bind the native Mumble protocol to.
+# webport is the port to bind the WebSocket Mumble protocol to.
+# They are incremented for each virtual server (if set globally).
+#port = 64738
+#webport = 443
+
+# "Message of the day" HTML string sent to connecting clients.
+welcometext = "Welcome to this server running Grumble on Void."
+
+# Password to join the server.
+#serverpassword =
+
+# Maximum bandwidth (in bits per second) per client for voice.
+# Grumble does not yet enforce this limit, but some clients nicely follow it.
+bandwidth = 288000
+
+# Maximum number of concurrent clients.
+#users = 1000
+#usersperchannel = 0
+
+#textmessagelength = 5000
+#imagemessagelength = 131072
+#allowhtml
+
+# The default channel is the channel (by ID) new users join.
+# The root channel (ID = 0) is the default.
+#defaultchannel = 0
+
+# Whether users will rejoin the last channel they were in.
+#rememberchannel
+
+# Whether to include server OS info in ping response.
+#sendversion
+
+# Whether to respond to pings from the Connect dialog.
+#allowping
+
+# Path to the log file (relative to the data directory).
+logfile = /dev/stdout
+
+# Path to TLS certificate and key (relative to the data directory).
+# The certificate needs to have the entire chain concatenated to be valid.
+# If these paths do not exist, Grumble will autogenerate a certificate.
+#sslCert = cert.pem
+#sslKey = key.pem
+
+# Options for public server registration.
+# All of these have to be set to make the server public.
+# registerName additionally sets the name of the root channel.
+# registerPassword is a simple, arbitrary secret to guard your registration. Don't lose it.
+#registerName =
+#registerHostname =
+#registerPassword =
+#registerUrl =
diff --git a/grumble/files/template b/grumble/files/template
new file mode 100644
index 0000000..f0c7c42
--- /dev/null
+++ b/grumble/files/template
@@ -0,0 +1,14 @@
+# Template file for 'grumble'
+pkgname=grumble
+version=1.0.0
+revision=1
+short_desc="nada"
+build_style="go"
+go_import_path=mumble.info/grumble
+go_package="${go_import_path}/cmd/grumble"
+license="BAD"
+homepage="https://github.com/mumble-voip/grumble"
+_branch="config"
+distfiles="https://github.com/rubenseyer/grumble/archive/${_branch}.tar.gz"
+wrksrc="${pkgname}-${_branch}"
+checksum="18fa4170114adef1b40b18e421e924eeff51b0f1c0109d8c735c937e7b32a758"
diff --git a/xbps-builder/Dockerfile b/xbps-builder/Dockerfile
new file mode 100644
index 0000000..5cbf34e
--- /dev/null
+++ b/xbps-builder/Dockerfile
@@ -0,0 +1,5 @@
+FROM d.xr.to/base
+COPY files/fakedchroot.sh /_fakedchroot.sh
+COPY files/setup-fakedchroot.sh /
+RUN bash /setup-fakedchroot.sh && rm /setup-fakedchroot.sh
+WORKDIR '/_workdir'
diff --git a/xbps-builder/README.md b/xbps-builder/README.md
new file mode 100644
index 0000000..b7d8198
--- /dev/null
+++ b/xbps-builder/README.md
@@ -0,0 +1,26 @@
+# `d.xr.to/xbps-builder`
+
+```bash
+docker pull d.xr.to/xbps-builder
+```
+
+A simple pre-configured container to build void packages in, [void-linux/void-packages](https://github.com/void-linux/void-packages)
+is checked out in `/_workdir` which is also the current workdir
+
+Building an image inside a Dockerfile and installing it
+it in a target docker container looks like the following
+
+```Dockerfile
+FROM d.xr.to/xbps-builder AS builder
+RUN git pull
+RUN ./xbps-src pkg docker
+FROM d.xr.to/base
+COPY --from=builder /_workdir/hostdir /tmp/xbps
+RUN xbps-install -SyR /tmp/xbps docker \
+ && xbps-remove -Oo \
+ && rm -rf /var/cache/xbps/* /tmp/xbps
+```
+
+# Warning
+
+This xbps-builder is bootstrapped with some very bad magic, so if you hit an issue, please create an issue!
diff --git a/xbps-builder/files/fakedchroot.sh b/xbps-builder/files/fakedchroot.sh
new file mode 100644
index 0000000..18f97d4
--- /dev/null
+++ b/xbps-builder/files/fakedchroot.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+#
+# This chroot script uses bad design
+#
+fake_mount() {
+ #
+ # Fake mount works by removing the dir, and replacing it with a symlink
+ # This created the illusion of a bind.
+ #
+
+ local FROM="$1";
+ local TO="$2"
+ if [ -d "$TO" ]; then
+ rmdir "$TO";
+ fi
+ ln -s "$FROM" "$TO";
+}
+
+fake_umount() {
+ #
+ # Remove the symlink and recreate the dir
+ #
+ rm "$1";
+ mkdir "$1";
+}
+
+readonly MASTERDIR="$1"
+readonly DISTDIR="$2"
+readonly HOSTDIR="$3"
+readonly EXTRA_ARGS="$4"
+readonly CMD="$5"
+shift 5
+
+if [ -z "$MASTERDIR" -o -z "$DISTDIR" ]; then
+ echo "$0 MASTERDIR/DISTDIR not set"
+ exit 1
+fi
+
+fake_mount $DISTDIR $MASTERDIR/void-packages;
+
+if [ ! -z "$HOSTDIR" ]; then
+ fake_mount $HOSTDIR $MASTERDIR/host;
+fi
+
+ITEMS="";
+# xbps-src may send some other binds, parse them here
+while getopts 'b:' c -- "$EXTRA_ARGS"; do
+ # Skip everything that's not a bind
+ [ "$c" = "b" ] || continue;
+
+ _FROM="$(cut -d: -f1 <<< "$OPTARG")";
+ _TO="$(cut -d: -f2 <<< "$OPTARG")";
+ fake_mount "${_FROM}" "${_TO}";
+ # Save created mounts so we can clean them up later
+ ITEMS+="${_TO} "
+done
+
+CURR_DIR="${PWD}";
+# To give the illusion we entered the chroot, cd to /
+cd /;
+# Tell xbps-src that we are "in the chroot".
+IN_CHROOT=1 $CMD $@;
+# Save exit code for after clean up
+X="$?";
+# cd back to the old pwd, so everything is the same again
+cd "$CURR_DIR";
+
+if [ ! -z "$HOSTDIR" ]; then
+ fake_umount $MASTERDIR/host;
+fi
+
+fake_umount $MASTERDIR/void-packages;
+
+# "umount" on demand created "mounts"
+for i in $ITEMS; do
+ fake_umount "$i";
+done
+
+# Exit with the returned exit code
+exit "$X";
diff --git a/xbps-builder/files/setup-fakedchroot.sh b/xbps-builder/files/setup-fakedchroot.sh
new file mode 100644
index 0000000..8aa8aee
--- /dev/null
+++ b/xbps-builder/files/setup-fakedchroot.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+set -e;
+
+readonly WORKDIR="/_workdir"
+# Install base utils required for downloading latest void packages and running xbps-src
+xbps-install -Sy xtools base-devel chroot-git chroot-util-linux tar wget coreutils
+
+# Clone void-packages into workdir, with depth 1, as template history is irrelevant
+git clone --depth 1 'https://github.com/void-linux/void-packages.git' "${WORKDIR}";
+cd "${WORKDIR}";
+
+# Copy fakedchroot chroot style into chroot-style dir and make it executable
+cp /_fakedchroot.sh "${WORKDIR}/common/chroot-style/fakedchroot.sh";
+chmod a+x "${WORKDIR}/common/chroot-style/fakedchroot.sh";
+
+# If masterdir exists: remove it, because we will replace it with a symlink
+if [ -d "${WORKDIR}/masterdir" ]; then
+ rm "${WORKDIR}/masterdir";
+fi
+# Make $WORKDIR/masterdir point to /
+ln -s / "${WORKDIR}/masterdir";
+
+# Tell xbps-src to used our new chroot style: fakedchroot
+echo XBPS_CHROOT_CMD=fakedchroot >> etc/conf;
+
+# Tell xbps-src we init'd the chroot
+touch "${WORKDIR}/masterdir/.xbps_chroot_init"
+
+# Since base-chroot has some conflicts with a normal base, replace the check with true
+sed -i 's:check_installed_pkg base-chroot-0.1_1:true:' common/xbps-src/shutils/common.sh
+
+# Install the non-conflicting dependencies of base-chroot anyway
+xbps-install -Sy $(xbps-query -Rx base-chroot | grep -v 'bash\|texinfo');
+
+# Clean up cache
+rm -rf /var/cache/xbps/*;