fixing PATH in pimox worker

This commit is contained in:
juvdiaz 2026-07-02 11:12:57 -06:00
parent cfcfc39f1f
commit 77e31bba0b
1 changed files with 21 additions and 9 deletions

30
jeannie
View File

@ -1584,17 +1584,29 @@ configure_pimox_worker_forwarding() {
worker_address="${worker_ip%%/*}"
pimox_ssh "${pimox_host}" "${pimox_user}" "${pimox_key}" "set -eu
if ! command -v iptables >/dev/null 2>&1; then
iptables_bin=\"\$(command -v iptables 2>/dev/null || true)\"
if [ -z \"\$iptables_bin\" ] && [ -x /usr/sbin/iptables ]; then
iptables_bin=/usr/sbin/iptables
fi
if [ -z \"\$iptables_bin\" ]; then
if command -v apt-get >/dev/null 2>&1; then
echo 'iptables not found on Pimox host; installing iptables for worker forwarding rules.'
sudo apt-get update
sudo apt-get install -y --no-install-recommends iptables
fi
fi
if ! command -v iptables >/dev/null 2>&1; then
iptables_bin=\"\$(command -v iptables 2>/dev/null || true)\"
if [ -z \"\$iptables_bin\" ] && [ -x /usr/sbin/iptables ]; then
iptables_bin=/usr/sbin/iptables
fi
if [ -z \"\$iptables_bin\" ]; then
echo 'iptables not found on Pimox host and could not be installed; cannot configure worker forwarding rules.' >&2
exit 1
fi
iptables_save_bin=\"\$(command -v iptables-save 2>/dev/null || true)\"
if [ -z \"\$iptables_save_bin\" ] && [ -x /usr/sbin/iptables-save ]; then
iptables_save_bin=/usr/sbin/iptables-save
fi
backup_dir='${backup_dir}'
case \"\$backup_dir\" in
'~'|'~/') backup_dir=\"\$HOME\" ;;
@ -1602,22 +1614,22 @@ case \"\$backup_dir\" in
esac
mkdir -p \"\$backup_dir\"
backup_file=\"\$backup_dir/iptables-before-jeannie-workers-\$(date +%Y%m%d-%H%M%S).rules\"
if command -v iptables-save >/dev/null 2>&1; then
sudo iptables-save >\"\$backup_file\"
if [ -n \"\$iptables_save_bin\" ]; then
sudo \"\$iptables_save_bin\" >\"\$backup_file\"
echo \"Saved Pimox iptables backup: \$backup_file\"
fi
sudo mkdir -p /etc/sysctl.d
printf '%s\n' 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/99-homelab-pimox-worker-forwarding.conf >/dev/null
sudo sysctl -w net.ipv4.ip_forward=1 >/dev/null
chain=FORWARD
if sudo iptables -S DOCKER-USER >/dev/null 2>&1; then
if sudo \"\$iptables_bin\" -S DOCKER-USER >/dev/null 2>&1; then
chain=DOCKER-USER
fi
if ! sudo iptables -C \"\$chain\" -s '${worker_address}/32' -j ACCEPT 2>/dev/null; then
sudo iptables -I \"\$chain\" 1 -s '${worker_address}/32' -j ACCEPT
if ! sudo \"\$iptables_bin\" -C \"\$chain\" -s '${worker_address}/32' -j ACCEPT 2>/dev/null; then
sudo \"\$iptables_bin\" -I \"\$chain\" 1 -s '${worker_address}/32' -j ACCEPT
fi
if ! sudo iptables -C \"\$chain\" -d '${worker_address}/32' -j ACCEPT 2>/dev/null; then
sudo iptables -I \"\$chain\" 1 -d '${worker_address}/32' -j ACCEPT
if ! sudo \"\$iptables_bin\" -C \"\$chain\" -d '${worker_address}/32' -j ACCEPT 2>/dev/null; then
sudo \"\$iptables_bin\" -I \"\$chain\" 1 -d '${worker_address}/32' -j ACCEPT
fi
echo \"Pimox worker forwarding rules active in \$chain for ${worker_address}\""
}