#!/bin/sh # # This script sets up everything need to run Danbooru under Docker. It installs Docker and Git (if # they're not already installed), downloads the Danbooru code from Github (if it's not already # downloaded), and initializes the config files. # # If this script is run with `curl -sSL https://raw.githubusercontent.com/danbooru/danbooru/master/bin/setup | sh`, # then it will automatically run `docker compose up` to start Danbooru. Otherwise you can run `docker compose up` # manually to start Danbooru. # Usage: # # $ bin/setup # $ sudo docker compose up set -eu DANBOORU_REPO=https://github.com/danbooru/danbooru # Check if program exists. has() { type "$1" > /dev/null 2>&1 } # Ask for confirmation before proceeding. confirm() { read -p "$1 (y/n) " REPLY [ $REPLY = "y" ] } # Clone the Danbooru repo and cd into it, unless we're already in it. clone_repo() { if grep -s danbooru .git/config > /dev/null; then return elif grep -s danbooru danbooru/.git/config > /dev/null; then cd danbooru return fi install_git git clone "$DANBOORU_REPO" cd danbooru } # Install Git if it's not installed already. install_git() { if has git; then return elif ! confirm "Git not found. Install it?"; then echo "You must install Git to proceed. See https://git-scm.com/downloads to install it manually." exit 1 fi if has apt-get; then sudo apt-get update sudo apt-get install -y git elif has dnf; then sudo dnf install -y git elif has pacman; then sudo pacman -Sy --noconfirm git else echo "Error: Couldn't install Git. See https://git-scm.com/downloads to install Git manually." exit 1 fi } # Install Docker and Docker Compose if they're not installed already. install_docker_compose() { if has docker && docker compose > /dev/null 2>&1; then return elif ! confirm "Docker not found. Install it?"; then echo "Error: You must install Docker and Docker Compose to proceed. See https://docs.docker.com/engine/install/ to install it manually." exit 1 fi # Debian and Ubuntu if has apt-get; then if ! has curl; then sudo apt-get update sudo apt-get install -y curl fi curl -fsSL https://get.docker.com | sh # Fedora elif has dnf; then if ! has curl; then sudo dnf install -y curl fi curl -fsSL https://get.docker.com | sh # Arch Linux elif has pacman; then sudo pacman -Sy --noconfirm docker docker-compose else echo "Error: Couldn't install Docker automatically. See https://docs.docker.com/engine/install/ to install Docker manually." exit 1 fi # Start Docker if it's not running already. if has systemctl; then sudo systemctl start docker fi } # `docker compose up` needs these files to exist. initialize_config_files() { touch -a .env.local config/danbooru_local_config.rb } # Start Danbooru if running this script with `curl | sh`. start_danbooru() { if [ "$0" != "sh" ]; then return fi # Test whether we need sudo to run docker. if docker version > /dev/null 2>&1; then exec docker compose "${@:-up}" elif sudo docker version > /dev/null 2>&1; then exec sudo docker compose "${@:-up}" else echo "Error: Couldn't run Docker. Make sure Docker is installed correctly." exit 1 fi } install_docker_compose clone_repo initialize_config_files start_danbooru