#!/bin/bash
# omarchy:summary=Restore the most recent mirrorlist backup
# omarchy:examples=omarchycn mirror restore
# omarchy:requires-sudo=true

set -euo pipefail

source "$OMARCHY_PATH/cn/lib/mirror.sh"

backups=("$CN_MIRRORLIST".omarchycn-bak-*)
if [[ ! -e ${backups[0]} ]]; then
  echo "No OmarchyCN mirrorlist backups found" >&2
  exit 1
fi

latest="${backups[-1]}"
sudo cp "$latest" "$CN_MIRRORLIST"
rm -f "$CN_PROFILE_FILE"
echo "Restored $CN_MIRRORLIST from ${latest##*/}"
