#!/usr/bin/env bash # Setup script for BookStackApp/BookStack on macOS, from https://gitmanual.com/BookStackApp/BookStack # Read it before you run it: the commands come from the repo's own README and files. # Run: bash setup.sh set -eo pipefail trap 'echo "Setup stopped at the step above. Steps and fixes: https://gitmanual.com/BookStackApp/BookStack" >&2' ERR step() { printf '\n\033[1m==> %s\033[0m\n' "$1"; } have() { command -v "$1" >/dev/null 2>&1; } # Installers put programs here; make them usable right away. export PATH="$HOME/.local/share/mise/shims:$HOME/.cargo/bin:$HOME/.local/bin:$HOME/.deno/bin:$HOME/.bun/bin:$PATH" # nvm is a shell function, so load it into this script when it's installed. export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" load_nvm() { [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" || { have brew && [ -s "$(brew --prefix nvm 2>/dev/null)/nvm.sh" ] && mkdir -p "$NVM_DIR" && . "$(brew --prefix nvm)/nvm.sh"; }; } have_nvm() { load_nvm >/dev/null 2>&1; type nvm >/dev/null 2>&1; } step '1/6 Clone the repository' [ -d 'BookStack' ] || git clone https://github.com/BookStackApp/BookStack.git cd 'BookStack' step '2/6 Install the required runtimes' # Node.js LTS (no version pinned), PHP ^8.3.0 # needs nvm: brew install nvm (or https://github.com/nvm-sh/nvm) if have_nvm; then nvm install --lts; elif have node; then echo "nvm not found: using Node $(node -v)"; else echo "Needs Node.js: install nvm from https://github.com/nvm-sh/nvm" >&2; exit 1; fi have php || brew install php composer step '3/6 Configure environment variables' # Fill in secrets: APP_KEY, DB_PASSWORD, MAIL_PASSWORD if [ ! -f .env ]; then cp .env.example .env; echo 'Created .env. Fill in secrets: APP_KEY, DB_PASSWORD, MAIL_PASSWORD in .env, then run this script again.'; exit 0; fi step '4/6 Start backing services' # Needs: MySQL, Mail catcher # Docker Desktop have docker || brew install --cask docker docker compose -f docker-compose.yml up -d step '5/6 Install dependencies' npm ci composer install step '6/6 Set up the database / app' php artisan key:generate php artisan migrate echo 'Set up BookStackApp/BookStack.' echo 'Fill in secrets: APP_KEY, DB_PASSWORD, MAIL_PASSWORD' echo 'Next, from the project folder:' echo ' npm run dev' echo ' php artisan serve' echo ' npm test' echo 'Manual: https://gitmanual.com/BookStackApp/BookStack'