From a11d46948583a6604210a683cb1da3b811d30f9f Mon Sep 17 00:00:00 2001
From: artoo <flower_of_life@gmx.net>
Date: Sun, 6 Jul 2014 20:19:24 +0200
Subject: [PATCH] check for openrc, runn different chroot when openrc

---
 mkmanjaroroot.in | 41 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/mkmanjaroroot.in b/mkmanjaroroot.in
index 9f7c6d3..d6fe2b1 100644
--- a/mkmanjaroroot.in
+++ b/mkmanjaroroot.in
@@ -8,6 +8,8 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
+set -x
+
 m4_include(lib/common.sh)
 
 CHROOT_VERSION='v3'
@@ -20,6 +22,13 @@ branch='stable'
 
 APPNAME=$(basename "${0}")
 
+# check for openrc running on build system
+if [[ -d /run/openrc ]];then
+	IS_OPENRC=1
+else
+	IS_OPENRC=0
+fi
+
 # usage: usage <exitvalue>
 usage() {
 	echo "Usage: ${APPNAME} [options] working-dir [package-list | app]"
@@ -87,15 +96,28 @@ build_mount_args() {
 
 	if [[ -n $host_mirror_path ]]; then
 		printf -v p '%q' "$host_mirror_path"
-		mount_args+=(--bind-ro="$p")
+		if (( $IS_OPENRC ));then
+			mount_args+=("$p") #-o --bind ro
+		else
+			mount_args+=(--bind-ro="$p")
+		fi
 	fi
 
 	printf -v p '%q' "${cache_dirs[0]}"
-	mount_args+=(--bind="$p")
+	if (( $IS_OPENRC ));then
+		mount_args+=("$p") #--bind
+	else
+		mount_args+=(--bind="$p")
+	fi
+
 
 	for cache_dir in ${cache_dirs[@]:1}; do
 		printf -v p '%q' "$cache_dir"
-		mount_args+=(--bind-ro="$p")
+		if (( $IS_OPENRC ));then
+			mount_args+=("$p") #-o --bind ro
+		else
+			mount_args+=(--bind-ro="$p")
+		fi
 	done
 }
 
@@ -137,12 +159,23 @@ chroot_lock () {
 chroot_run() {
 	local dir=$1
 	shift
-	systemd-nspawn -D "${dir}" "${mount_args[@]}" -- ${@} 2>/dev/null
+	if (( $IS_OPENRC ));then
+		# the mounting doesn't work properly here for all cases --> readonly
+		for m_arg in ${mount_args[@]};do
+			mount --bind -o  ro "${m_arg}" "${dir}${m_arg}"
+		done
+		arch-chroot ${dir} ${@} 2>/dev/null
+
+		#unmounting has to be done somewhere too
+	else
+		systemd-nspawn -D "${dir}" "${mount_args[@]}" -- ${@} 2>/dev/null
+	fi
 }
 
 # }}}
 
 umask 0022
+
 if [[ -n $RUN ]]; then
 	# run chroot {{{
 	#Sanity check
-- 
GitLab