#!/bin/sh

WPCLI=/home/verseaumee/security-scan/tools/wp-cli.phar
LIST=/home/verseaumee/security-scan/reports/wordpress-roots.txt

while IFS= read -r site; do
    echo "========================================"
    echo "SITE: $site"

    VER=$(grep -m1 "\$wp_version =" "$site/wp-includes/version.php" 2>/dev/null \
        | sed "s/.*'\([^']*\)'.*/\1/")

    echo "VERSION: $VER"

    if [ -n "$VER" ]; then
        php "$WPCLI" core download \
            --path="$site" \
            --version="$VER" \
            --force \
            --skip-content
    else
        echo "SKIPPED - VERSION NOT DETECTED"
    fi

done < "$LIST"

echo "CORE REPAIR FINISHED"
