Avoid recursive R wrappers

This commit is contained in:
MangoPig
2026-06-03 22:59:55 +01:00
parent 3a3073e389
commit dd8c952b1d

View File

@@ -33,6 +33,36 @@ EOF
chmod +x "$R_BIN_DIR/$target_name" chmod +x "$R_BIN_DIR/$target_name"
} }
resolve_non_wrapper_command() {
local target_name="$1"
local original_path="$PATH"
local filtered_parts=()
local filtered_path=""
local resolved_path=""
local part
IFS=':' read -r -a filtered_parts <<< "$PATH"
local kept_parts=()
for part in "${filtered_parts[@]}"; do
if [ -n "$part" ] && [ "$part" != "$R_BIN_DIR" ]; then
kept_parts+=("$part")
fi
done
filtered_path=$(IFS=:; printf '%s' "${kept_parts[*]}")
resolved_path=$(PATH="$filtered_path" command -v "$target_name" 2>/dev/null || true)
PATH="$original_path"
if [ -z "$resolved_path" ]; then
echo -e "${RED} ERROR:${NC} Could not resolve system command for $target_name outside $R_BIN_DIR"
exit 1
fi
printf '%s\n' "$resolved_path"
}
echo -e "${BLUE} LOG:${YELLOW} Detecting R installation strategy for $OS...${NC}" echo -e "${BLUE} LOG:${YELLOW} Detecting R installation strategy for $OS...${NC}"
if is_arch_family; then if is_arch_family; then
@@ -51,8 +81,8 @@ if is_arch_family; then
echo -e "${GREEN} SUCCESS:${NC} R installed via Pacman." echo -e "${GREEN} SUCCESS:${NC} R installed via Pacman."
R_BIN="R" R_BIN="R"
SYSTEM_R_BIN="$(command -v R)" SYSTEM_R_BIN="$(resolve_non_wrapper_command R)"
SYSTEM_RSCRIPT_BIN="$(command -v Rscript)" SYSTEM_RSCRIPT_BIN="$(resolve_non_wrapper_command Rscript)"
write_r_wrapper "R" "exec \"$SYSTEM_R_BIN\"" write_r_wrapper "R" "exec \"$SYSTEM_R_BIN\""
write_r_wrapper "Rscript" "exec \"$SYSTEM_RSCRIPT_BIN\"" write_r_wrapper "Rscript" "exec \"$SYSTEM_RSCRIPT_BIN\""
@@ -117,8 +147,8 @@ elif is_fedora_family; then
fi fi
R_BIN="R" R_BIN="R"
SYSTEM_R_BIN="$(command -v R)" SYSTEM_R_BIN="$(resolve_non_wrapper_command R)"
SYSTEM_RSCRIPT_BIN="$(command -v Rscript)" SYSTEM_RSCRIPT_BIN="$(resolve_non_wrapper_command Rscript)"
write_r_wrapper "R" "exec \"$SYSTEM_R_BIN\"" write_r_wrapper "R" "exec \"$SYSTEM_R_BIN\""
write_r_wrapper "Rscript" "exec \"$SYSTEM_RSCRIPT_BIN\"" write_r_wrapper "Rscript" "exec \"$SYSTEM_RSCRIPT_BIN\""
@@ -132,8 +162,8 @@ elif is_macos; then
fi fi
R_BIN="R" R_BIN="R"
SYSTEM_R_BIN="$(command -v R)" SYSTEM_R_BIN="$(resolve_non_wrapper_command R)"
SYSTEM_RSCRIPT_BIN="$(command -v Rscript)" SYSTEM_RSCRIPT_BIN="$(resolve_non_wrapper_command Rscript)"
write_r_wrapper "R" "exec \"$SYSTEM_R_BIN\"" write_r_wrapper "R" "exec \"$SYSTEM_R_BIN\""
write_r_wrapper "Rscript" "exec \"$SYSTEM_RSCRIPT_BIN\"" write_r_wrapper "Rscript" "exec \"$SYSTEM_RSCRIPT_BIN\""