#!/bin/bash

# Real version – makes the changes
# Usage: ./fix-symlinks.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 "Changing: $link"
            echo "  old → $target"
            echo "  new → ../../index-archive.html"

            # Remove the old symlink
            rm "$link"

            # Create the new symlink
            ln -s "../../index-archive.html" "$newlink"

            echo "  → Done"
            echo
        else
            echo "Skipping $link (points to '$target' instead)"
        fi
    else
        echo "Skipping $dir (no index.php symlink found)"
    fi
done

echo "All done."
