From: Dan Brown Date: Tue, 19 Apr 2022 12:09:04 +0000 (+0100) Subject: Copied 20.04 install script for 22.04 X-Git-Url: http://source.bookstackapp.com/devops/commitdiff_plain/bcba38e136311efa753a73722649c8319f7837b5 Copied 20.04 install script for 22.04 --- diff --git a/scripts/installation-ubuntu-22.04.sh b/scripts/installation-ubuntu-22.04.sh new file mode 100644 index 0000000..01f2b21 --- /dev/null +++ b/scripts/installation-ubuntu-22.04.sh @@ -0,0 +1,137 @@ +#!/bin/sh +# This script will install a new BookStack instance on a fresh Ubuntu 20.04 server. +# This script is experimental and does not ensure any security. + +# Fetch domain to use from first provided parameter, +# Otherwise request the user to input their domain +DOMAIN=$1 +if [ -z "$1" ] +then +echo "" +printf "Enter the domain you want to host BookStack and press [ENTER]\nExamples: my-site.com or docs.my-site.com\n" +read -r DOMAIN +fi + +# Ensure a domain was provided otherwise display +# an error message and stop the script +if [ -z "$DOMAIN" ] +then + >&2 echo 'ERROR: A domain must be provided to run this script' + exit 1 +fi + +# Get the current machine IP address +CURRENT_IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + +# Install core system packages +export DEBIAN_FRONTEND=noninteractive +add-apt-repository universe +apt update +apt install -y git unzip apache2 php7.4 curl php7.4-fpm php7.4-curl php7.4-mbstring php7.4-ldap \ +php7.4-tidy php7.4-xml php7.4-zip php7.4-gd php7.4-mysql mysql-server-8.0 libapache2-mod-php7.4 + +# Set up database +DB_PASS="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)" +mysql -u root --execute="CREATE DATABASE bookstack;" +mysql -u root --execute="CREATE USER 'bookstack'@'localhost' IDENTIFIED WITH mysql_native_password BY '$DB_PASS';" +mysql -u root --execute="GRANT ALL ON bookstack.* TO 'bookstack'@'localhost';FLUSH PRIVILEGES;" + +# Download BookStack +cd /var/www || exit +git clone https://github.com/BookStackApp/BookStack.git --branch release --single-branch bookstack +BOOKSTACK_DIR="/var/www/bookstack" +cd $BOOKSTACK_DIR || exit + +# Install composer +EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" + +if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ] +then + >&2 echo 'ERROR: Invalid composer installer checksum' + rm composer-setup.php + exit 1 +fi + +php composer-setup.php --quiet +rm composer-setup.php + +# Move composer to global installation +mv composer.phar /usr/local/bin/composer + +# Install BookStack composer dependencies +export COMPOSER_ALLOW_SUPERUSER=1 +php /usr/local/bin/composer install --no-dev --no-plugins + +# Copy and update BookStack environment variables +cp .env.example .env +sed -i.bak "s@APP_URL=.*\$@APP_URL=http://$DOMAIN@" .env +sed -i.bak 's/DB_DATABASE=.*$/DB_DATABASE=bookstack/' .env +sed -i.bak 's/DB_USERNAME=.*$/DB_USERNAME=bookstack/' .env +sed -i.bak "s/DB_PASSWORD=.*\$/DB_PASSWORD=$DB_PASS/" .env + +# Generate the application key +php artisan key:generate --no-interaction --force +# Migrate the databases +php artisan migrate --no-interaction --force + +# Set file and folder permissions +chown www-data:www-data -R bootstrap/cache public/uploads storage && chmod -R 755 bootstrap/cache public/uploads storage + +# Set up apache +a2enmod rewrite +a2enmod php7.4 + +cat >/etc/apache2/sites-available/bookstack.conf < + ServerName ${DOMAIN} + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/bookstack/public/ + + + Options Indexes FollowSymLinks + AllowOverride None + Require all granted + + + Options -MultiViews -Indexes + + + RewriteEngine On + + # Handle Authorization Header + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + # Redirect Trailing Slashes If Not A Folder... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_URI} (.+)/$ + RewriteRule ^ %1 [L,R=301] + + # Handle Front Controller... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.php [L] + + + + ErrorLog \${APACHE_LOG_DIR}/error.log + CustomLog \${APACHE_LOG_DIR}/access.log combined + + +EOL + +a2dissite 000-default.conf +a2ensite bookstack.conf + +# Restart apache to load new config +systemctl restart apache2 + +echo "" +echo "Setup Finished, Your BookStack instance should now be installed." +echo "You can login with the email 'admin@admin.com' and password of 'password'" +echo "MySQL was installed without a root password, It is recommended that you set a root MySQL password." +echo "" +echo "You can access your BookStack instance at: http://$CURRENT_IP/ or http://$DOMAIN/"