#!/bin/bash # Installation command: # bash <(curl -sSL "https://installghost.com/?p=selfghost") # Colors RED='\x1b[0;31m' GREEN='\x1b[0;32m' BLUE='\x1b[0;34m' YELLOW='\x1b[0;33m' NC='\x1b[0m' # No Color # Function to display a frame with messages function print_frame() { local message=$1 local color=$2 local reset=$3 echo -e "${color}===${reset} ${message} ${color}===${reset}\n" } # Function to display messages function print_message() { echo -e "\n${BLUE}=== $1 ===${NC}\n" } # Display Ghost logo cat << "EOF" _ __ __ __ _ _ | |/ _|/ / \ \| | | | ___ ___| | |_| | __ _ | | |__ ___ ___| |_ / __|/ _ \ | _| |/ _` || | '_ \ / _ \/ __| __| \__ \ __/ | | | | (_| || | | | | (_) \__ \ |_ |___/\___|_|_| | |\__, || |_| |_|\___/|___/\__| \_\__/ /_/ |___/ ======== Last update: 2024-10-16 ======== ======== https://selfghost.com ======== EOF echo -e "${GREEN}\nWelcome to the self(g)host Ghost CMS automatic installer!\n${NC}" echo -e "${RED}IMPORTANT: Before proceeding, make sure to point your domain name DNS to your server's IP address.\n${NC}" print_frame "LET'S GO!" "$GREEN" "$NC" # Ask the user for variables with default values print_message "Configuration" read -p "Enter the full URL of the Ghost site you're installing (e.g., https://mysite.com): " GHOST_URL read -p "Enter your email address for the site's SSL configuration: " EMAIL read -p "Enter the name of the directory where Ghost will be installed on your VPS (default: selfghost): " GHOST_DIR GHOST_DIR=${GHOST_DIR:-selfghost} read -p "Enter the name of the Ghost database (default: selfghost): " DB_NAME DB_NAME=${DB_NAME:-selfghost} read -p "Enter the username for the database (default: selfghost): " DB_USER DB_USER=${DB_USER:-selfghost} read -s -p "Enter the password for the database user [automatically generated if empty]: " DB_PASSWORD echo if [ -z "$DB_PASSWORD" ]; then DB_PASSWORD=$(openssl rand -base64 12) echo -e "Generated password: $DB_PASSWORD" fi read -p "Enter the major version of Node.js to install (default: 18): " NODE_MAJOR NODE_MAJOR=${NODE_MAJOR:-18} # Non-interactive mode print_message "Non-interactive mode: ON" export DEBIAN_FRONTEND=noninteractive echo 'APT::Get::Assume-Yes "true";' | sudo tee /etc/apt/apt.conf.d/90forceyes echo 'DPkg::options { "--force-confdef"; "--force-confold"; }' | sudo tee -a /etc/apt/apt.conf.d/90forceyes # Disable needrestart prompts sudo sed -i 's/#\$nrconf{restart} = '\''\'i'\'\'';/\$nrconf{restart} = '\''\'a'\'\'';/g' /etc/needrestart/needrestart.conf # Update & Upgrade print_message "Updating the system" sudo apt-get update -y && sudo apt-get upgrade -y # Install and configure UFW print_message "Installing and configuring UFW" sudo apt-get install -y ufw sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw --force enable # Install Fail2Ban print_message "Installing and configuring Fail2Ban" sudo apt-get install -y fail2ban sudo systemctl enable --now fail2ban # Install MySQL print_message "Installing and configuring MySQL" sudo apt-get install -y mysql-server if [ $? -ne 0 ]; then echo -e "${RED}Error during MySQL installation.${NC}" exit 1 fi sudo systemctl enable mysql print_message "Creating Ghost database" sudo mysql <