Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,19 @@ user_home() {
echo "/home/${_user}"
}

# Config dir the openshell CLI will use, resolved in the same environment the CLI
# runs in. The CLI takes $XDG_CONFIG_HOME when set and $HOME/.config otherwise,
# so asking through as_target_user covers both cases: the same-user branch
# inherits the caller's XDG_CONFIG_HOME, while the sudo and runuser branches
# reset the environment and fall back to the target user's home.
#
# An empty XDG_CONFIG_HOME falls back to $HOME/.config, per the XDG base
# directory spec. The CLI instead joins onto an empty base and yields a relative
# "openshell", which no installer path can usefully match.
target_openshell_config_dir() {
as_target_user sh -c 'printf "%s\n" "${XDG_CONFIG_HOME:-$HOME/.config}/openshell"'
}

as_target_user() {
if [ "${PLATFORM:-}" = "darwin" ]; then
if [ "$(id -u)" -eq "$TARGET_UID" ]; then
Expand Down Expand Up @@ -1020,7 +1033,7 @@ wait_for_local_gateway_listener() {
_elapsed=0
_last_output=""
_probe_url="$(local_gateway_endpoint)/"
_mtls_dir="${TARGET_HOME}/.config/openshell/gateways/openshell/mtls"
_mtls_dir="$(target_openshell_config_dir)/gateways/openshell/mtls"

info "waiting for local gateway listener to become reachable..."
while [ "$_elapsed" -lt "$_timeout" ]; do
Expand Down Expand Up @@ -1089,7 +1102,7 @@ remove_local_gateway_registration_from() {
}

remove_local_gateway_registration() {
remove_local_gateway_registration_from "${TARGET_HOME}/.config/openshell"
remove_local_gateway_registration_from "$(target_openshell_config_dir)"
}

remove_snap_gateway_registration() {
Expand Down
40 changes: 40 additions & 0 deletions tasks/scripts/test-install-sh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,44 @@ done

unset -f gh uname linux_package_method

# The installer must look for gateway entries and client certs where the CLI
# keeps them, which is $XDG_CONFIG_HOME/openshell when that variable is set.
assert_target_config_dir() {
local name=$1
local expected=$2
local actual
actual="$(target_openshell_config_dir)"
if [ "$actual" != "$expected" ]; then
echo "FAIL: ${name}: expected ${expected}, got ${actual}" >&2
exit 1
fi
}

TARGET_HOME="${tmpdir}/target-home"
TARGET_USER="$(id -un)"
TARGET_UID="$(id -u)"
PLATFORM=linux
TARGET_RUNTIME_DIR="${tmpdir}/runtime"

saved_xdg_config_home="${XDG_CONFIG_HOME-}"
saved_xdg_config_home_set="${XDG_CONFIG_HOME+set}"

unset XDG_CONFIG_HOME
assert_target_config_dir "unset XDG_CONFIG_HOME uses the target home" \
"${TARGET_HOME}/.config/openshell"

export XDG_CONFIG_HOME="${tmpdir}/xdg-config"
assert_target_config_dir "XDG_CONFIG_HOME is honored" \
"${tmpdir}/xdg-config/openshell"

export XDG_CONFIG_HOME=""
assert_target_config_dir "empty XDG_CONFIG_HOME falls back per the XDG spec" \
"${TARGET_HOME}/.config/openshell"

if [ "$saved_xdg_config_home_set" = "set" ]; then
export XDG_CONFIG_HOME="$saved_xdg_config_home"
else
unset XDG_CONFIG_HOME
fi

echo "install.sh focused tests passed"
Loading