From fe2e490ff47871de1d4b3e8a29652b71044c071e Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Sat, 6 Mar 2021 13:58:22 +0700 Subject: [PATCH] Add way to mount to different directory. --- README.md | 7 +++++-- init.bash | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 757e8a3..d759608 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,10 @@ Edit SHARED_FOLDER in ```/etc/archbox.conf```. For example: ``` SHARED_FOLDER=( /home /var/www ) ``` -Note that this will recursively mount directories. +To mount to different directory, use ```:``` separator : +``` +SHARED_FOLDER=( /home /var/www:/host_webroot ) +``` ### Known issues #### NixOS-specific issues ##### /run mounting @@ -161,7 +164,7 @@ Or alternatively if you use WM-only, just disable mounting ```/run``` entirely a ##### Archbox didn't access resources in /usr/share In Archbox, Symlink ```/usr``` to ```/run/current-system/sw```: ``` -sudo mkdir -p /run/current-system/ +sudo mkdir -p /run/current-system sudo ln -s /usr /run/current-system/sw ``` make sure /run isn't mounted. diff --git a/init.bash b/init.bash index b19122e..bb3e570 100644 --- a/init.bash +++ b/init.bash @@ -12,6 +12,11 @@ rbind() { [[ $2 = "make-rslave" ]] && mount --make-rslave $CHROOT$1 } +rbind_diff() { + [[ $(mount | grep $CHROOT$2) ]] && msg "$CHROOT$2 already mounted." \ + || (mount -R $1 $CHROOT$2 && msg "$CHROOT$2 mounted!") +} + bindproc() { [[ $(mount | grep $CHROOT/proc) ]] && msg "$CHROOT/proc already mounted." \ || (mount -t proc /proc $CHROOT/proc && msg "$CHROOT/proc mounted!") @@ -37,8 +42,14 @@ case $1 in fi [[ -d /var/lib/dbus ]] && rbind /var/lib/dbus for i in ${SHARED_FOLDER[@]}; do - mkdir -p $CHROOT/$i - rbind $i + if [[ $i = *:* ]]; then + source=$(echo $i | sed 's/:.*//') + target=$(echo $i | sed 's/.*://') + mkdir -p $CHROOT$target + rbind_diff $source $target; + else + rbind $i; + fi done msg "Starting services" for j in ${SERVICES[@]}; do @@ -71,7 +82,12 @@ case $1 in fi rmbind /var/lib/dbus for i in ${SHARED_FOLDER[@]}; do - rmbind $i + if [[ $i = *:* ]]; then + target=$(echo $i | sed 's/.*://') + rmbind $target; + else + rmbind $i; + fi done exit 0 ;;