From a5ea9c46bee9d744fc354fdf610fecbd25637b8b Mon Sep 17 00:00:00 2001 From: kenny-io Date: Fri, 13 Sep 2024 19:31:56 +0400 Subject: [PATCH] request user permission for package installations --- installer.sh | 62 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/installer.sh b/installer.sh index ba43504..f8ca69a 100755 --- a/installer.sh +++ b/installer.sh @@ -121,45 +121,45 @@ echo "The base directory is set to: $input" NODEHOME="${input/#\~/$HOME}" # support ~ in path # Check all things that will be needed for this script to succeed like access to docker and docker-compose -# If any check fails, attempt to install the missing dependency -command -v git >/dev/null 2>&1 || { - echo >&2 "'git' is not installed. Attempting to install git..." - if command -v apt-get >/dev/null 2>&1; then - sudo apt-get update && sudo apt-get install -y git - elif command -v yum >/dev/null 2>&1; then - sudo yum install -y git - else - echo >&2 "Unable to install git. Please install it manually." - exit 1 +# If any check fails exit with a message on what the user needs to do to fix the problem +check_and_install() { + if ! command -v $1 &>/dev/null; then + read -p "$1 is not installed. Do you want to install it? (y/n) " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + case $1 in + git) + sudo apt-get update && sudo apt-get install -y git || sudo yum install -y git + ;; + docker) + curl -fsSL https://get.docker.com | sudo sh + sudo usermod -aG docker $USER + ;; + docker-compose) + sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + ;; + esac + else + echo "$1 is required but not installed. Exiting." + exit 1 + fi fi } -command -v docker >/dev/null 2>&1 || { - echo >&2 "'docker' is not installed. Attempting to install docker..." - curl -fsSL https://get.docker.com -o get-docker.sh - sudo sh get-docker.sh - sudo usermod -aG docker $USER - rm get-docker.sh -} +# Check and install required components +check_and_install git +check_and_install docker +check_and_install docker-compose +# Verify Docker Compose installation if ! command -v docker-compose &>/dev/null && ! docker --help | grep -q "compose"; then - echo "docker-compose or docker compose is not installed. Attempting to install docker-compose..." - sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose -fi - -# Verify installations -command -v git >/dev/null 2>&1 || { echo >&2 "Failed to install git. Please install it manually."; exit 1; } -command -v docker >/dev/null 2>&1 || { echo >&2 "Failed to install docker. Please install it manually."; exit 1; } -if command -v docker-compose &>/dev/null; then - echo "docker-compose is installed on this machine" -elif docker --help | grep -q "compose"; then - echo "docker compose subcommand is installed on this machine" -else - echo "Failed to install docker-compose. Please install it manually." + echo "docker-compose or docker compose is not installed. Please install it manually." exit 1 fi +echo "All required packages are installed." + export DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-safe() {