BASH: check if a package is installed [Debian/Ubuntu]

Example: checks if the packages in the variable pks are installed. If not, update and install without prompt

 #Packages
pks="root-tail xdm"
echo "Installing required packages if missed"
dpkg-query -l $pks
if [ "$?" != "0" ]
then apt-get update && apt-get -y install $pks
fi