@@ -20,7 +20,7 @@ service_pid_file="${runtime_dir}/nemoclaw-podman-service.pid"
2020log_file=" ${runtime_dir} /nemoclaw-podman-service.log"
2121gateway_service_name=" nemoclaw-openshell-gateway"
2222gateway_unit_path=" ${config_home} /systemd/user/${gateway_service_name} .service"
23- gateway_binary_path=" ${bin_home} /openshell-gateway "
23+ gateway_binary_path=" "
2424gateway_env_file=" ${config_home} /openshell/gateway.env"
2525gateway_tls_dir=" ${state_home} /openshell/tls"
2626gateway_state_dir=" ${state_home} /openshell/gateway"
@@ -460,6 +460,34 @@ stop_runtime() {
460460 rm -f " $socket_path " " $backend_socket_path "
461461}
462462
463+ gateway_binary_path_is_trusted () {
464+ local candidate=" $1 "
465+ local user_bin_home=" ${bin_home%/ } "
466+ case " $candidate " in
467+ " ${user_bin_home} /openshell-gateway" | /usr/local/bin/openshell-gateway | /usr/bin/openshell-gateway)
468+ return 0
469+ ;;
470+ * )
471+ return 1
472+ ;;
473+ esac
474+ }
475+
476+ read_managed_gateway_binary_path () {
477+ local candidate=" " count=0 line
478+ while IFS= read -r line || [[ -n " $line " ]]; do
479+ case " $line " in
480+ ExecStart=* )
481+ candidate=" ${line# ExecStart=} "
482+ (( count += 1 ))
483+ ;;
484+ esac
485+ done < " $gateway_unit_path "
486+ [[ " $count " -eq 1 && " $candidate " == /* && " $candidate " != * [[:space:]]* ]] || return 1
487+ gateway_binary_path_is_trusted " $candidate " || return 1
488+ printf ' %s\n' " $candidate "
489+ }
490+
463491validate_gateway_unit () {
464492 if [[ ! -f " $gateway_unit_path " || -L " $gateway_unit_path " || ! -r " $gateway_unit_path " ]]; then
465493 echo " Portable profile fixture requires the managed gateway user service at ${gateway_unit_path} ." >&2
@@ -469,15 +497,21 @@ validate_gateway_unit() {
469497 echo " Portable profile fixture rejected the foreign gateway user service at ${gateway_unit_path} ." >&2
470498 return 1
471499 fi
472- if [[ " $( grep -Fxc " ExecStart=${gateway_binary_path} " " $gateway_unit_path " || true) " -ne 1 ]] \
473- || [[ " $( grep -Fxc " ExecStartPre=${gateway_binary_path} generate-certs --output-dir \$ {OPENSHELL_LOCAL_TLS_DIR} --server-san host.openshell.internal" " $gateway_unit_path " || true) " -ne 1 ]] \
500+ local unit_gateway_binary
501+ unit_gateway_binary=" $( read_managed_gateway_binary_path) " || {
502+ echo " Portable profile fixture rejected the OpenShell gateway user service identity at ${gateway_unit_path} ." >&2
503+ return 1
504+ }
505+ if [[ " $( grep -Fxc " ExecStart=${unit_gateway_binary} " " $gateway_unit_path " || true) " -ne 1 ]] \
506+ || [[ " $( grep -Fxc " ExecStartPre=${unit_gateway_binary} generate-certs --output-dir \$ {OPENSHELL_LOCAL_TLS_DIR} --server-san host.openshell.internal" " $gateway_unit_path " || true) " -ne 1 ]] \
474507 || [[ " $( grep -Fxc ' StateDirectory=openshell/gateway' " $gateway_unit_path " || true) " -ne 1 ]] \
475508 || [[ " $( grep -Fxc ' Environment=OPENSHELL_LOCAL_TLS_DIR=%S/openshell/tls' " $gateway_unit_path " || true) " -ne 1 ]] \
476509 || [[ " $( grep -Fxc ' EnvironmentFile=-%E/openshell/gateway.env' " $gateway_unit_path " || true) " -ne 1 ]] \
477- || [[ ! -x " $gateway_binary_path " || -L " $gateway_binary_path " ]]; then
478- echo " Portable profile fixture rejected the gateway user service identity at ${gateway_unit_path} ." >&2
510+ || [[ ! -f " $unit_gateway_binary " || ! -r " $unit_gateway_binary " || ! - x " $unit_gateway_binary " || -L " $unit_gateway_binary " ]]; then
511+ echo " Portable profile fixture rejected the OpenShell gateway user service identity at ${gateway_unit_path} ." >&2
479512 return 1
480513 fi
514+ gateway_binary_path=" $unit_gateway_binary "
481515}
482516
483517load_gateway_environment () {
0 commit comments