From 0723a169ada57a4c3035cea37c07bf8051089773 Mon Sep 17 00:00:00 2001 From: Kris Date: Fri, 16 Jul 2021 15:52:12 +0200 Subject: [PATCH] Added bash script to install packages The script is thought to check for required packages to be installed, and, if any of those is not detected, an attempt is made to automatically install it from the apt package manager. Note that the script will work only on distributions using apt package manager. In any other case, the user should manually install the required packages. --- requirements.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 requirements.sh diff --git a/requirements.sh b/requirements.sh new file mode 100755 index 0000000..7601ec6 --- /dev/null +++ b/requirements.sh @@ -0,0 +1,40 @@ +#! /bin/sh + +pkgs="ninja-build libglib2.0-dev make gcc g++ pkg-config" + +print_requirements(){ + echo "Required packages (note that these are apt-based package names):" + for pkg in $pkgs; do + echo "[*] $pkg" + done +} + +dpkg_status=$(dpkg-query --help > /dev/null 2>&1) +if [ $? -ne 0 ]; then + echo "dpkg-query not available. Probably your current OS is using a package manager different from apt" + echo "Please, install the required packages manually, then launch make" + echo "" + print_requirements + exit 0 +fi + +for pkg in $pkgs; do + status=$(dpkg-query -W -f='${db:Status-Status}' "$pkg" 2>/dev/null | grep -c "installed") + echo "" + if [ $? -ne 0 ] || [ $status -eq 0 ]; then + echo "$pkg not installed" + echo "Attempt to install the missing package. NOTE: SUDO PASSWORD MAY BE REQUESTED" + sudo apt-get -y install $pkg + if [ $? -eq 0 ]; then + echo "$pkg successfully installed" + else + echo "$pkg installation failed. Please manually install the required packages and retry." + print_requirements + exit 1 + fi + echo "" + echo "" + else + echo "$pkg already installed" + fi +done