I am writing a numerous shell scripts, which depends on specific packages.
For example one of my scripts depends on ca-certificates
and wget
. If I have not yet run apt-get -y update
, then I get the following errors:
Package ca-certificates is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source.
E: Package 'ca-certificates' has no installation candidate
E: Unable to locate package wget
I want to avoid running apt-get -y update
on every script. Basically, I want to create a shortcut function which will do the following two things:
- Run
apt-get -y update
only when necessary. - Install only the packages which are not installed/latest.
Here is my current function so far:
function install-packages()
{
apt-get -y update
apt-get install -y --no-install-recommends $@
}
install-packages ca-certificates wget