#!/bin/bash

set -e

HOOK_URL="https://mirror.kr.md/hooks/40-multipath-routing"
HOOK_DEST="/etc/dhcp/dhclient-exit-hooks.d/40-multipath-routing"

echo "[+] Installing dhclient auto-route hook..."

# Ensure ipcalc is installed
if ! command -v ipcalc >/dev/null 2>&1; then
    echo "[+] ipcalc not found. Installing..."
    apt-get update && apt-get install -y ipcalc
fi

# Download the hook
echo "[+] Downloading hook from $HOOK_URL..."
curl -fsSL "$HOOK_URL" -o "$HOOK_DEST"

# Make it executable
chmod +x "$HOOK_DEST"
echo "[+] Hook installed to $HOOK_DEST"

# Optionally renew DHCP for eth* interfaces
echo "[+] Restarting DHCP on eth* interfaces..."

dhclient -v

echo "[✓] dhclient auto-route setup complete."
