From 85297d1be5fa7a95c0c4aa4bf228c709b1cbf263 Mon Sep 17 00:00:00 2001 From: RomanNum3ral Date: Fri, 2 Jan 2026 13:38:32 +0000 Subject: [PATCH] Add install.sh --- install.sh | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..0ac14aa --- /dev/null +++ b/install.sh @@ -0,0 +1,195 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ========================= +# BookStack Native Installer (Ubuntu + Apache + MariaDB) +# ========================= +# - Installs dependencies +# - Creates DB/user +# - Clones BookStack (release branch) +# - Configures .env +# - Runs migrations +# - Configures Apache vhost +# +# Run: sudo ./install_bookstack_native.sh +# ========================= + +# ---- Config (edit these) ---- +BOOKSTACK_DIR="/var/www/bookstack" +APACHE_SITE_NAME="Bookstack" +SERVER_NAME="bookstack.domain.com" # Change to your domain or server hostname +APP_URL="https://bookstack.domain.com" # Change to http(s)://your-domain + +DB_NAME="bookstack" +DB_USER="bookstack" +DB_PASS="$(openssl rand -base64 24 | tr -d '\n' | tr -d '/' | tr -d '+')" # auto-generate +# If you want to set your own DB password, replace the line above: +# DB_PASS="YourStrongPasswordHere" + +# Optional: set to 1 to install UFW and allow Apache +CONFIGURE_UFW=1 + +# ---- Helpers ---- +log() { echo -e "\n\033[1;32m[+] $*\033[0m"; } +warn() { echo -e "\n\033[1;33m[!] $*\033[0m"; } +die() { echo -e "\n\033[1;31m[✗] $*\033[0m"; exit 1; } + +require_root() { + if [[ "${EUID}" -ne 0 ]]; then + die "Run this script as root (use sudo)." + fi +} + +detect_php_version() { + # best-effort: use system php + if ! command -v php >/dev/null 2>&1; then + echo "" + return + fi + php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;' +} + +# ---- Start ---- +require_root + +log "Updating packages" +apt-get update -y + +log "Installing dependencies (Apache, MariaDB, PHP, Composer, extensions)" +apt-get install -y \ + apache2 mariadb-server \ + git unzip curl \ + composer \ + php php-cli php-fpm \ + php-mysql php-xml php-mbstring php-curl php-zip php-gd php-intl + +PHP_VER="$(detect_php_version || true)" +if [[ -z "${PHP_VER}" ]]; then + warn "PHP not detected after install; something is off." +else + log "Detected PHP version: ${PHP_VER}" +fi + +log "Enabling and starting services" +systemctl enable --now apache2 +systemctl enable --now mariadb + +if [[ "${CONFIGURE_UFW}" -eq 1 ]]; then + log "Configuring UFW (allow OpenSSH + Apache Full)" + apt-get install -y ufw + ufw allow OpenSSH >/dev/null || true + ufw allow "Apache Full" >/dev/null || true + ufw --force enable >/dev/null || true +fi + +log "Creating database and user" +# If already exists, keep going safely. +mysql --protocol=socket -uroot < "${APACHE_CONF}" < + ServerName ${SERVER_NAME} + DocumentRoot ${BOOKSTACK_DIR}/public + + + AllowOverride All + Require all granted + + + ErrorLog \${APACHE_LOG_DIR}/${APACHE_SITE_NAME}_error.log + CustomLog \${APACHE_LOG_DIR}/${APACHE_SITE_NAME}_access.log combined + +EOF + +log "Enabling Apache modules and site" +a2enmod rewrite >/dev/null +a2ensite "${APACHE_SITE_NAME}" >/dev/null + +# Disable default site if enabled (optional, but cleaner) +if [[ -e /etc/apache2/sites-enabled/000-default.conf ]]; then + warn "Disabling Apache default site (000-default)" + a2dissite 000-default >/dev/null || true +fi + +log "Reloading Apache" +systemctl reload apache2 + +cat <