This script simply installs the chosen packages if they're not present on a Linux system using the apt
package manager. Notes on improvements of any aspect are welcome!
setup_env.sh
#!/usr/bin/env bash
set -euo pipefail
install_if_not_exist() {
if dpkg -s "$1" &>/dev/null; then
PKG_EXIST=$(dpkg -s "$1" | grep "install ok installed")
if [ -z "$PKG_EXIST" ]; then
sudo apt install "$1" -y
fi
else
sudo apt install "$1" -y
fi
}
sudo apt update -y
install_if_not_exist aria2
install_if_not_exist coreutils
install_if_not_exist gawk
install_if_not_exist jq
install_if_not_exist moreutils
install_if_not_exist sed
install_if_notexist foo
every time you want to install a new package. \$\endgroup\$apt install
, and it would tell you which of the requested packages are already installed (and therefore it won't install them again)? \$\endgroup\$apt
is more efficient when you install all the packages you want in one transaction. \$\endgroup\$