#!/bin/bash

# DRY-RUN version that accepts directories as arguments
# Usage: ./fix-symlinks-dryrun.sh dir1 dir2 dir3 ...

if [ $# -eq 0 ]; then
    echo "Usage: $0 directory1 [directory2 ...]"
    exit 1
fi

for dir in "$@"; do
    if [ ! -d "$dir" ]; then
        echo "Warning: '$dir' is not a directory — skipping"
        continue
    fi

    link="$dir/index.php"

    if [ -L "$link" ]; then
        target=$(readlink "$link")

        if [ "$target" = "../../index-archive.php" ]; then
            newlink="$dir/index.html"

            echo "Would change: $link"
            echo "  old → $target"
            echo "  new → ../../index-archive.html"
            echo "  (would create: $newlink)"
            echo
        else
            echo "Skipping $link (points to '$target' instead)"
        fi
    else
        echo "Skipping $dir (no index.php symlink found)"
    fi
done

echo "Dry run complete. No changes were made."
