#!/bin/bash
# This script is designed to help installing LOGS on Ubuntu 24 LTS.

clear

MAGENTA='\033[1;35m'
NC='\033[0m'

echo -e "${MAGENTA}"
echo -e "##################################################################"
echo -e "#                                                                #"
echo -e "#                  S  c  i  Y   L O G S                          #"
echo -e "#          - Your scientific data management system -            #"
echo -e "#                                                                #"
echo -e "#  Shortcut to Installation Script for Ubuntu 24 or AlmaLinux    #"
echo -e "#                                                                #"
echo -e "##################################################################"
echo -e "#    --> Visit https://logs.sciy.com for more details <--        #"
echo -e "##################################################################${NC}"
echo


# 2) Check if curl is installed
if ! command -v curl &> /dev/null; then
    echo "Warning: curl is not installed."

    read -p "Do you want to update the system and install curl now? [Y/n] " response
    response=${response,,} # to lowercase

    if [[ "$response" =~ ^(yes|y|)$ ]]; then
        echo "Installing curl..."
        sudo apt update && sudo apt install -y curl
    else
        echo "Aborting. curl is required."
        exit 1
    fi
fi

# 3) Load and decrypt installer script
echo "Note: For enhanced security the installer script is encrypted."
echo "You find the decryption passphrase in the email you received after purchasing LOGS."
echo "If you need additional help, please contact support@sciy.com."
echo
curl -s https://install.logs-sciy.com/ubuntu24_alma.sh.gpg | gpg --quiet --pinentry-mode loopback --output install_logs_ubuntu24_alma.sh -d

if [ -f "./install_logs_ubuntu24_alma.sh" ]; then
    echo "-> Installation script downloaded and decrypted successfully."
    echo "-> Please execute the following command to install LOGS:"
    echo -e "\033[1;38;5;208m sudo bash ./install_logs_ubuntu24_alma.sh \033[0m"
    echo
else
    echo
    echo "Error: Download or Decryption failed. Please try again or contact support@sciy.com."
    echo
fi