From 57320ad95839fae3a608ed13ebefd381b8940d04 Mon Sep 17 00:00:00 2001 From: Edi Septriyanto Date: Wed, 11 Aug 2021 15:13:22 +0700 Subject: [PATCH] Add pre check required packages --- lib/lemper-create.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/lemper-create.sh b/lib/lemper-create.sh index 515d87f..4eb262b 100755 --- a/lib/lemper-create.sh +++ b/lib/lemper-create.sh @@ -100,13 +100,19 @@ if [ "$(id -u)" -ne 0 ]; then fi # Check pre-requisite packages. -if [[ ! -f $(command -v unzip) || ! -f $(command -v git) || ! -f $(command -v rsync) ]]; then - error "${APP_NAME^} requires git, rsync, unzip, wget, please install it first!" - echo "help: sudo apt install git rsync unzip wget" +REQUIRED_PACKAGES=("curl" "git" "rsync" "unzip" "wget") +for CMD in "${REQUIRED_PACKAGES[@]}"; do + if ! [[ -x "$(command -v "${CMD}")" ]]; then + NO_PACKAGES+=("${CMD}") + fi +done +if [[ ${#NO_PACKAGES[@]} -gt 0 ]]; then + printf -v NO_PACKAGES_STR '%s, ' "${NO_PACKAGES[@]}" + error "${APP_NAME^} requires: ${NO_PACKAGES_STR%, }, please install it first!" + echo "help: run 'sudo apt-get install ${NO_PACKAGES[*]}'" exit 1 fi - ## # Main Functions #