#!/bin/bash

clear
echo "-----------------------------------------------------------"
echo "OnixOS System Updater (with pacman) "
echo "-----------------------------------------------------------"

if command -v reflector &> /dev/null; then
	echo "Updating mirrorlist using reflector..."
	sudo reflector --latest 20 --sort rate --save /etc/pacman.d/mirrorlist
	echo "Mirrorlist updated."
fi

if command -v pacman &> /dev/null; then
	echo "Updating pacman keyring..."
	sudo pacman -Sy --noconfirm archlinux-keyring
	sudo pacman-key --init
	sudo pacman-key --populate archlinux
	echo "Pacman keyring update completed."

	echo "Updating the system..."
	sudo pacman -Syu --noconfirm --overwrite "*"
fi

echo "-----------------------------------------------------------"
echo "Done. "
echo "-----------------------------------------------------------"
