From 457f842f43029c0662518ba6bd08472274f9d12e Mon Sep 17 00:00:00 2001 From: th33xitus <31533186+th33xitus@users.noreply.github.com> Date: Sat, 27 Jun 2020 16:05:24 +0200 Subject: [PATCH] adding dependencie check on startup checks for some packages installed which are necessary for the script to work properly. fixes some crashes when calling for wget or unzip while not having those packages already installed. --- kiauh.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kiauh.sh b/kiauh.sh index a249ae9..64a30d8 100644 --- a/kiauh.sh +++ b/kiauh.sh @@ -87,6 +87,37 @@ check_euid(){ fi } +### check for package dependencies +dependency_check(){ + package=(curl wget virtualenv unzip git) + + for pkg in "${package[@]}"; do + if ! command -v $pkg >&/dev/null 2>&1 + then + install+=($package) + fi + done + + if ! [ ${#install[@]} -eq 0 ] + then + status_msg "The following packages are missing:" + echo -e "${red}${install[@]}${default}" + status_msg "They are necessary for this script to work." + status_msg "Please install them now or do it manually!" + echo + while true; do + read -p "Do you want to install them now? (Y/n): " yn + case "$yn" in + Y|y|Yes|yes|"") + echo; status_msg "Installing dependencies ..." + sudo apt install ${install[@]} -y && echo && confirm_msg "Dependencies successfully installed!"; echo; break;; + N|n|No|no) break;; + *) warn_msg "Unknown parameter: $yn"; echo;; + esac + done + fi +} + ### checking for existing installations on startup start_check(){ check_files