arch linux – Validate all pacman packages before running an install script

I am writing a script for my use to install Arch Linux.
Suppose I have:

PKGS=(
'firefox'
'libreoffice'
'vlc'
'***'
)

I would like the script to validate my packages.
I am thinking of something around:

for packages in "${PKGS[@]}"; do
    Validate all the packages one by one
done

if packages validated successfully
    echo we are good!
else 
    echo package names that failed validation e.g. firegox ginp
    exit and stop running the script
fi

How can I achieve this please?

Read more here: Source link