#!/bin/bash
apt-get -qq update
apt-get -qq upgrade
echo "Installing nginx"
apt-get -qq install nginx
ufw allow 'Nginx Full'
echo "Installing zip"
apt-get -qq install zip
echo "Installing mysql"
apt-get -qq install mysql-server
echo "Installing Node.js"
apt-get -qq install -y ca-certificates curl gnupg
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=18 # Use a supported version
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt-get -qq install nodejs
echo "Creating 1GB swapfile"
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab
sysctl vm.swappiness=15
echo 'sysctl vm.swappiness=15' | tee -a /etc/sysctl.conf
sysctl vm.vfs_cache_pressure=60
echo 'sysctl vm.vfs_cache_pressure=60' | tee -a /etc/sysctl.conf
npm install ghost-cli@latest -g
echo "Creating Ghost directory structure"
mkdir -p /var/www/ghost-blog
chown ubuntu:ubuntu /var/www/ghost-blog
chmod 775 /var/www/ghost-blog
echo "Completed instance custom install script"

