#!/bin/sh
set -e

# Läs secrets
PW=$(cat /run/secrets/skoda_password)
SPIN=$(cat /run/secrets/skoda_spin)

cat > /root/.netrc <<EOF
machine skoda
  login simon@milvert.com
  password $PW
  account $SPIN
EOF

chmod 600 /root/.netrc

# Kör original-cmd
if [ -n "$ADDITIONAL_INSTALLS" ]; then
  echo "Installing additional packages: $ADDITIONAL_INSTALLS"
  # try pip3 first, fall back to pip
  if command -v pip3 >/dev/null 2>&1; then
    pip3 install --no-cache-dir $ADDITIONAL_INSTALLS || echo "Warning: pip3 install failed for $ADDITIONAL_INSTALLS"
  elif command -v pip >/dev/null 2>&1; then
    pip install --no-cache-dir $ADDITIONAL_INSTALLS || echo "Warning: pip install failed for $ADDITIONAL_INSTALLS"
  else
    echo "No pip found in container; skipping additional installs"
  fi
fi

exec "$@"