#!/bin/sh

set -e
PKGS="$@"
all_installed=1

if [ -z "$UID" ]; then
	UID=`id -u`
fi
if [ "$UID" = 0 ]; then
	SUDO=
else
	SUDO=sudo
fi

for pkg in "$@"
do
	if ! dpkg -s "$pkg" | grep -q 'Status: install ok installed'; then
		echo "$pkg is not installed"
		all_installed=0
	fi
done

if [ $all_installed = 0 ]; then
	$SUDO apt-get install -y $PKGS
fi
