|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2024 communtiy-scripts ORG |
| 4 | +# Author: MickLesk (Canbiz) |
| 5 | +# License: MIT |
| 6 | +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 7 | + |
| 8 | +source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +msg_info "Installing Dependencies (Patience)" |
| 17 | +$STD apt-get install -y \ |
| 18 | + unzip \ |
| 19 | + mariadb-server \ |
| 20 | + apache2 \ |
| 21 | + curl \ |
| 22 | + sudo \ |
| 23 | + php8.2-{mbstring,gd,fpm,curl,intl,ldap,tidy,bz2,mysql,zip,xml} \ |
| 24 | + composer \ |
| 25 | + libapache2-mod-php \ |
| 26 | + make \ |
| 27 | + mc |
| 28 | +msg_ok "Installed Dependencies" |
| 29 | + |
| 30 | +msg_info "Setting up Database" |
| 31 | +DB_NAME=bookstack |
| 32 | +DB_USER=bookstack |
| 33 | +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) |
| 34 | +$STD sudo mysql -u root -e "CREATE DATABASE $DB_NAME;" |
| 35 | +$STD sudo mysql -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED WITH mysql_native_password AS PASSWORD('$DB_PASS');" |
| 36 | +$STD sudo mysql -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;" |
| 37 | +{ |
| 38 | + echo "Bookstack-Credentials" |
| 39 | + echo "Bookstack Database User: $DB_USER" |
| 40 | + echo "Bookstack Database Password: $DB_PASS" |
| 41 | + echo "Bookstack Database Name: $DB_NAME" |
| 42 | +} >> ~/bookstack.creds |
| 43 | +msg_ok "Set up database" |
| 44 | + |
| 45 | +msg_info "Setup Bookstack (Patience)" |
| 46 | +LOCAL_IP="$(hostname -I | awk '{print $1}')" |
| 47 | +cd /opt |
| 48 | +RELEASE=$(curl -s https://api.github.com/repos/BookStackApp/BookStack/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') |
| 49 | +wget -q "https://github.com/BookStackApp/BookStack/archive/refs/tags/v${RELEASE}.zip" |
| 50 | +unzip -q v${RELEASE}.zip |
| 51 | +mv BookStack-${RELEASE} /opt/bookstack |
| 52 | +cd /opt/bookstack |
| 53 | +cp .env.example .env |
| 54 | +sudo sed -i "s|APP_URL=.*|APP_URL=http://$LOCAL_IP|g" /opt/bookstack/.env |
| 55 | +sudo sed -i "s/DB_DATABASE=.*/DB_DATABASE=$DB_NAME/" /opt/bookstack/.env |
| 56 | +sudo sed -i "s/DB_USERNAME=.*/DB_USERNAME=$DB_USER/" /opt/bookstack/.env |
| 57 | +sudo sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=$DB_PASS/" /opt/bookstack/.env |
| 58 | +$STD composer install --no-dev --no-plugins --no-interaction |
| 59 | +$STD php artisan key:generate --no-interaction --force |
| 60 | +$STD php artisan migrate --no-interaction --force |
| 61 | +chown www-data:www-data -R /opt/bookstack /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads /opt/bookstack/storage |
| 62 | +chmod -R 755 /opt/bookstack /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads /opt/bookstack/storage |
| 63 | +chmod -R 775 /opt/bookstack/storage /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads |
| 64 | +chmod -R 640 /opt/bookstack/.env |
| 65 | +$STD a2enmod rewrite |
| 66 | +$STD a2enmod php8.2 |
| 67 | +echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" |
| 68 | +msg_ok "Installed Bookstack" |
| 69 | + |
| 70 | +msg_info "Creating Service" |
| 71 | +cat <<EOF >/etc/apache2/sites-available/bookstack.conf |
| 72 | +<VirtualHost *:80> |
| 73 | + ServerAdmin webmaster@localhost |
| 74 | + DocumentRoot /opt/bookstack/public/ |
| 75 | +
|
| 76 | + <Directory /opt/bookstack/public/> |
| 77 | + Options -Indexes +FollowSymLinks |
| 78 | + AllowOverride None |
| 79 | + Require all granted |
| 80 | + <IfModule mod_rewrite.c> |
| 81 | + <IfModule mod_negotiation.c> |
| 82 | + Options -MultiViews -Indexes |
| 83 | + </IfModule> |
| 84 | +
|
| 85 | + RewriteEngine On |
| 86 | +
|
| 87 | + # Handle Authorization Header |
| 88 | + RewriteCond %{HTTP:Authorization} . |
| 89 | + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] |
| 90 | +
|
| 91 | + # Redirect Trailing Slashes If Not A Folder... |
| 92 | + RewriteCond %{REQUEST_FILENAME} !-d |
| 93 | + RewriteCond %{REQUEST_URI} (.+)/$ |
| 94 | + RewriteRule ^ %1 [L,R=301] |
| 95 | +
|
| 96 | + # Handle Front Controller... |
| 97 | + RewriteCond %{REQUEST_FILENAME} !-d |
| 98 | + RewriteCond %{REQUEST_FILENAME} !-f |
| 99 | + RewriteRule ^ index.php [L] |
| 100 | + </IfModule> |
| 101 | + </Directory> |
| 102 | + |
| 103 | + ErrorLog /var/log/apache2/error.log |
| 104 | + CustomLog /var/log/apache2/access.log combined |
| 105 | +
|
| 106 | +</VirtualHost> |
| 107 | +EOF |
| 108 | +$STD a2ensite bookstack.conf |
| 109 | +$STD a2dissite 000-default.conf |
| 110 | +$STD systemctl reload apache2 |
| 111 | +msg_ok "Created Services" |
| 112 | + |
| 113 | +motd_ssh |
| 114 | +customize |
| 115 | + |
| 116 | +msg_info "Cleaning up" |
| 117 | +rm -rf /opt/v${RELEASE}.zip |
| 118 | +$STD apt-get autoremove |
| 119 | +$STD apt-get autoclean |
| 120 | +msg_ok "Cleaned" |
0 commit comments