diff --git a/scripts/docker/command/docker_run_install.sh b/scripts/docker/command/docker_run_install.sh index 10158e1..5d57933 100755 --- a/scripts/docker/command/docker_run_install.sh +++ b/scripts/docker/command/docker_run_install.sh @@ -39,22 +39,27 @@ dockerCommandRunInstallUser() "PATH=/home/$CFG_DOCKER_INSTALL_USER/bin:/usr/bin:/bin:/usr/local/bin" ) + # Run from the install user's HOME, not the caller's cwd. At install time the + # caller is root in /root, which the unprivileged user can't enter, so + # cwd-sensitive tools error (e.g. find: "Failed to change directory: /root"). + local run_cwd="/home/$CFG_DOCKER_INSTALL_USER" + # --argv: exec the remaining args verbatim (no shell re-parse) so regex/ # quotes/backslashes in arguments (e.g. sed scripts) survive intact. Default: # treat $1 as a shell snippet via bash -c (needed for pipes/redirects/ # systemctl --user/etc.). if [ -n "$argv_mode" ]; then if [ -n "$silent_flag" ]; then - sudo -u "$CFG_DOCKER_INSTALL_USER" env "${run_env[@]}" "$@" >/dev/null 2>&1 + sudo -u "$CFG_DOCKER_INSTALL_USER" env --chdir="$run_cwd" "${run_env[@]}" "$@" >/dev/null 2>&1 else - sudo -u "$CFG_DOCKER_INSTALL_USER" env "${run_env[@]}" "$@" + sudo -u "$CFG_DOCKER_INSTALL_USER" env --chdir="$run_cwd" "${run_env[@]}" "$@" fi else local remote_command="$1" if [ -n "$silent_flag" ]; then - sudo -u "$CFG_DOCKER_INSTALL_USER" env "${run_env[@]}" bash -c "$remote_command" >/dev/null 2>&1 + sudo -u "$CFG_DOCKER_INSTALL_USER" env --chdir="$run_cwd" "${run_env[@]}" bash -c "$remote_command" >/dev/null 2>&1 else - sudo -u "$CFG_DOCKER_INSTALL_USER" env "${run_env[@]}" bash -c "$remote_command" + sudo -u "$CFG_DOCKER_INSTALL_USER" env --chdir="$run_cwd" "${run_env[@]}" bash -c "$remote_command" fi fi }