From fd3fcf1e36463594841a4405dc6d91cf4b5eccdb Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 31 Dec 2022 15:08:55 -0500 Subject: [PATCH] app_containers: Detect the user home directory dynamically ...so that we can stop assuming the username inside the container (although the shortcut generation script still does, but we'll fix that later, hopefully) --- app_containers/.local/bin/run_app_container | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app_containers/.local/bin/run_app_container b/app_containers/.local/bin/run_app_container index 011a4a8..c59a061 100755 --- a/app_containers/.local/bin/run_app_container +++ b/app_containers/.local/bin/run_app_container @@ -51,14 +51,18 @@ fi # Default user run_as=$UID -# We assume the user named `user` inside the container always has the same UID as -# the user with uid $run_as on the host; this is currently not yet configurable -homedir=/home/user if [ "$CONTAINER_RUN_AS_ROOT" = true ]; then run_as=0 - homedir=/root fi +homedir=/ +for line in $(sudo cat /var/lib/machines/$CONTAINER_NAME/etc/passwd); do + if [ "$(echo "$line" | cut -d: -f3)" == "$run_as" ]; then + homedir="$(echo "$line" | cut -d: -f6)" + break + fi +done + # Userns-related config # Default to identity mapping, which does not provide uid isolation but does for capabilities private_users=identity