From 65489cd1069b6e9cb592508103211984c43d3bbf Mon Sep 17 00:00:00 2001
From: P. J. McDermott <pj@pehjota.net>
Date: Mon, 25 May 2015 20:33:22 -0400
Subject: Merge branch 'feature/block-device-mounting'

---
(limited to 'lib/cmd')

diff --git a/lib/cmd/build.sh b/lib/cmd/build.sh
index 32dca26..d22fa1e 100644
--- a/lib/cmd/build.sh
+++ b/lib/cmd/build.sh
@@ -18,6 +18,7 @@
 # along with the ProteanOS Development Kit.  If not, see
 # <http://www.gnu.org/licenses/>.
 
+use block
 use profile
 use session
 use rand
@@ -31,6 +32,7 @@ cmd_build_build_deps=
 cmd_build_main()
 {
 	local root=
+	local dev=
 	local opkbuild_optstring=
 	local arch=
 	local plat=
@@ -43,9 +45,16 @@ cmd_build_main()
 	fi
 
 	root="${1}"
-	cmd_build_root="${root}"
 	shift 1
 
+	dev=''
+	if is_block "${root}"; then
+		dev="${root}"
+		root="$(block_mount "${dev}")"
+	fi
+
+	cmd_build_root="${root}"
+
 	opkbuild_optstring="$(cat "${root}/usr/share/opkbuild/optstring")"
 	arch="$(cat "${root}/etc/proteanos_arch")"
 	plat="$(cat "${root}/etc/proteanos_plat")"
@@ -91,6 +100,10 @@ cmd_build_main()
 	cmd_build_fini
 
 	session_end
+
+	if [ "x${dev}" != 'x' ]; then
+		block_umount "${root}"
+	fi
 }
 
 cmd_build_make_deps_pkg()
diff --git a/lib/cmd/install.sh b/lib/cmd/install.sh
index ac817e0..a02a77c 100644
--- a/lib/cmd/install.sh
+++ b/lib/cmd/install.sh
@@ -21,6 +21,7 @@
 use getopt
 use feed
 use profile
+use block
 use dir
 use fd
 use pkg
@@ -41,6 +42,7 @@ cmd_install_main()
 	local profile=
 	local mirror=
 	local foreign=
+	local dev=
 
 	if ! get_options "${@}"; then
 		print_cmd_usage 'install' >&2
@@ -97,6 +99,12 @@ cmd_install_main()
 		foreign=false
 	fi
 
+	dev=''
+	if is_block "${chroot}"; then
+		dev="${chroot}"
+		chroot="$(block_mount "${dev}")"
+	fi
+
 	info "$(get_msg 'cmd_install_setting_up_chroot')"
 	if [ -d "${chroot}" ] && ! dir_is_empty "${chroot}" 'lost+found'; then
 		error 2 "$(get_msg 'cmd_install_chroot_dir_exists')" "${chroot}"
@@ -119,6 +127,10 @@ cmd_install_main()
 	fi
 
 	rm "${chroot}/prokit/installing"
+
+	if [ "x${dev}" != 'x' ]; then
+		block_umount "${chroot}"
+	fi
 }
 
 cmd_install_find_pkgs()
diff --git a/lib/cmd/opkg.sh b/lib/cmd/opkg.sh
index 9f0c0de..51b90dc 100644
--- a/lib/cmd/opkg.sh
+++ b/lib/cmd/opkg.sh
@@ -18,6 +18,7 @@
 # along with the ProteanOS Development Kit.  If not, see
 # <http://www.gnu.org/licenses/>.
 
+use block
 use profile
 use session
 use rand
@@ -27,6 +28,7 @@ cmd_opkg_opks=
 cmd_opkg_main()
 {
 	local root=
+	local dev=
 	local first_arg=
 	local install_cmd=
 	local arg=
@@ -40,6 +42,12 @@ cmd_opkg_main()
 	root="${1}"
 	shift 1
 
+	dev=''
+	if is_block "${root}"; then
+		dev="${root}"
+		root="$(block_mount "${dev}")"
+	fi
+
 	first_arg=true
 	install_cmd=false
 	cmd_opkg_opks=''
@@ -84,6 +92,10 @@ cmd_opkg_main()
 
 	cmd_opkg_fini
 	session_end
+
+	if [ "x${dev}" != 'x' ]; then
+		block_umount "${root}"
+	fi
 }
 
 cmd_opkg_fini()
diff --git a/lib/cmd/shell.sh b/lib/cmd/shell.sh
index dfff07f..b5b6d69 100644
--- a/lib/cmd/shell.sh
+++ b/lib/cmd/shell.sh
@@ -18,12 +18,14 @@
 # along with the ProteanOS Development Kit.  If not, see
 # <http://www.gnu.org/licenses/>.
 
+use block
 use profile
 use session
 
 cmd_shell_main()
 {
 	local root=
+	local dev=
 
 	if [ ${#} -lt 1 ]; then
 		print_cmd_usage 'shell' >&2
@@ -33,6 +35,12 @@ cmd_shell_main()
 	root="${1}"
 	shift 1
 
+	dev=''
+	if is_block "${root}"; then
+		dev="${root}"
+		root="$(block_mount "${dev}")"
+	fi
+
 	. "${root}/etc/os-release"
 	profile_set "${ID}"
 
@@ -45,4 +53,8 @@ cmd_shell_main()
 		session_exec "${@}"
 	fi
 	session_end
+
+	if [ "x${dev}" != 'x' ]; then
+		block_umount "${root}"
+	fi
 }
--
cgit v0.9.1