# This file is part of shellfire core. It is subject to the licence terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/core/master/COPYRIGHT. No part of shellfire core, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2014-2015 The developers of shellfire core. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/core/master/COPYRIGHT.


core_dependency_check_Debian_checkFunction()
{
	core_dependency_check_releaseFile debian_version Debian
}
core_functions_register _core_dependency_check_functions core_dependency_check_Debian_checkFunction

core_dependency_check_Debian_extractUnqualifiedPackageName()
{
	local fullyQualifiedPackageName="$1"
	printf '%s' "$fullyQualifiedPackageName"
}

core_dependency_requires Debian sudo apt-get id
core_dependency_check_Debian_packageManager()
{
	if [ $(core_init_verbosity) -gt 0 ]; then
		local aptVerbosity=""
	else
		local aptVerbosity=" --quiet"
	fi

	local ourCurrentId="$(id -u)"
	if [ "$ourCurrentId" = 0 ]; then
		core_message NOTICE "Updating apt-get package manager (may take some time)"
		apt-get${aptVerbosity} update
	elif core_compatibility_whichNoOutput sudo; then
		core_message NOTICE "Updating apt-get package manager (may take some time)"
		sudo -p "Please enter the password for %p for sudo to apt-get update: " apt-get${aptVerbosity} update
	else
		core_message INFO "Not running as root and sudo not found, so not installing packages '$@'"
		return 0
	fi
	
	if core_variable_isSet core_dependency_check_forcePackageManagerUpgradeDuringInstall; then
		if [ $core_dependency_check_forcePackageManagerUpgradeDuringInstall -eq 1 ]; then
			core_message INFO "Upgrading apt-get package manager (may take some time)"
			if [ "$ourCurrentId" = 0 ]; then
				apt-get${aptVerbosity} dist-upgrade
			else
				sudo -p "Please enter the password for %p for sudo to run apt-get dist-upgrade: " apt-get${aptVerbosity} dist-upgrade
			fi
		fi
	fi

	if [ "$ourCurrentId" = 0 ]; then
		apt-get${aptVerbosity} --no-install-recommends --yes --no-upgrade install "$@"
	else
		sudo -p "Please enter the password for %p for sudo to install packages using apt-get: " apt-get${aptVerbosity} --no-install-recommends --yes --no-upgrade install "$@"
	fi
}
