From 4cf1811225e969b21e7501bfd09f796564fbe160 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Wed, 7 May 2025 15:42:57 +0200 Subject: [PATCH 1/2] Add bookstack for troublshooting --- ct/bookstack.sh | 78 +++++++++++++++++++++++ install/bookstack-install.sh | 117 +++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 ct/bookstack.sh create mode 100644 install/bookstack-install.sh diff --git a/ct/bookstack.sh b/ct/bookstack.sh new file mode 100644 index 0000000..8084195 --- /dev/null +++ b/ct/bookstack.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2025 community-scripts ORG +# Author: MickLesk (Canbiz) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/BookStackApp/BookStack + +APP="Bookstack" +var_tags="${var_tags:-organizer}" +var_cpu="${var_cpu:-1}" +var_ram="${var_ram:-1024}" +var_disk="${var_disk:-4}" +var_os="${var_os:-debian}" +var_version="${var_version:-12}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + header_info + check_container_storage + check_container_resources + if [[ ! -d /opt/bookstack ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + RELEASE=$(curl -fsSL https://api.github.com/repos/BookStackApp/BookStack/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + msg_info "Stopping Apache2" + systemctl stop apache2 + msg_ok "Services Stopped" + + msg_info "Updating ${APP} to v${RELEASE}" + mv /opt/bookstack /opt/bookstack-backup + curl -fsSL "https://github.com/BookStackApp/BookStack/archive/refs/tags/v${RELEASE}.zip" -o "/opt/BookStack-${RELEASE}.zip" + unzip -q "/opt/BookStack-${RELEASE}.zip" -d /opt + mv "/opt/BookStack-${RELEASE}" /opt/bookstack + cp /opt/bookstack-backup/.env /opt/bookstack/.env + cp -r /opt/bookstack-backup/public/uploads/* /opt/bookstack/public/uploads/ || true + cp -r /opt/bookstack-backup/storage/uploads/* /opt/bookstack/storage/uploads/ || true + cp -r /opt/bookstack-backup/themes/* /opt/bookstack/themes/ || true + cd /opt/bookstack + export COMPOSER_ALLOW_SUPERUSER=1 + $STD composer install --no-dev + $STD php artisan migrate --force + chown www-data:www-data -R /opt/bookstack /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads /opt/bookstack/storage + chmod -R 755 /opt/bookstack /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads /opt/bookstack/storage + chmod -R 775 /opt/bookstack/storage /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads + chmod -R 640 /opt/bookstack/.env + echo "${RELEASE}" >/opt/${APP}_version.txt + msg_ok "Updated ${APP} to v${RELEASE}" + + msg_info "Starting Apache2" + systemctl start apache2 + msg_ok "Started Apache2" + + msg_info "Cleaning Up" + rm -rf /opt/bookstack-backup + rm -rf "/opt/BookStack-${RELEASE}.zip" + msg_ok "Cleaned" + msg_ok "Updated Successfully" + else + msg_ok "No update required. ${APP} is already at v${RELEASE}" + fi + exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following URL:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}${CL}" diff --git a/install/bookstack-install.sh b/install/bookstack-install.sh new file mode 100644 index 0000000..4756a08 --- /dev/null +++ b/install/bookstack-install.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2025 community-scripts ORG +# Author: MickLesk (Canbiz) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/BookStackApp/BookStack + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies (Patience)" +$STD apt-get install -y \ + unzip \ + mariadb-server \ + apache2 \ + php8.2-{mbstring,gd,fpm,curl,intl,ldap,tidy,bz2,mysql,zip,xml} \ + composer \ + libapache2-mod-php \ + make +msg_ok "Installed Dependencies" + +msg_info "Setting up Database" +DB_NAME=bookstack +DB_USER=bookstack +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) +$STD sudo mysql -u root -e "CREATE DATABASE $DB_NAME;" +$STD sudo mysql -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED WITH mysql_native_password AS PASSWORD('$DB_PASS');" +$STD sudo mysql -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;" +{ + echo "Bookstack-Credentials" + echo "Bookstack Database User: $DB_USER" + echo "Bookstack Database Password: $DB_PASS" + echo "Bookstack Database Name: $DB_NAME" +} >>~/bookstack.creds +msg_ok "Set up database" + +msg_info "Setup Bookstack (Patience)" +LOCAL_IP="$(hostname -I | awk '{print $1}')" +cd /opt +RELEASE=$(curl -fsSL https://api.github.com/repos/BookStackApp/BookStack/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +curl -fsSL "https://github.com/BookStackApp/BookStack/archive/refs/tags/v${RELEASE}.zip" -o $(basename "https://github.com/BookStackApp/BookStack/archive/refs/tags/v${RELEASE}.zip") +unzip -q v${RELEASE}.zip +mv BookStack-${RELEASE} /opt/bookstack +cd /opt/bookstack +cp .env.example .env +sudo sed -i "s|APP_URL=.*|APP_URL=http://$LOCAL_IP|g" /opt/bookstack/.env +sudo sed -i "s/DB_DATABASE=.*/DB_DATABASE=$DB_NAME/" /opt/bookstack/.env +sudo sed -i "s/DB_USERNAME=.*/DB_USERNAME=$DB_USER/" /opt/bookstack/.env +sudo sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=$DB_PASS/" /opt/bookstack/.env +$STD composer install --no-dev --no-plugins --no-interaction +$STD php artisan key:generate --no-interaction --force +$STD php artisan migrate --no-interaction --force +chown www-data:www-data -R /opt/bookstack /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads /opt/bookstack/storage +chmod -R 755 /opt/bookstack /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads /opt/bookstack/storage +chmod -R 775 /opt/bookstack/storage /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads +chmod -R 640 /opt/bookstack/.env +$STD a2enmod rewrite +$STD a2enmod php8.2 +echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" +msg_ok "Installed Bookstack" + +msg_info "Creating Service" +cat </etc/apache2/sites-available/bookstack.conf + + ServerAdmin webmaster@localhost + DocumentRoot /opt/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 /var/log/apache2/error.log + CustomLog /var/log/apache2/access.log combined + + +EOF +$STD a2ensite bookstack.conf +$STD a2dissite 000-default.conf +$STD systemctl reload apache2 +msg_ok "Created Services" + +motd_ssh +customize + +msg_info "Cleaning up" +rm -rf /opt/v${RELEASE}.zip +$STD apt-get autoremove +$STD apt-get autoclean +msg_ok "Cleaned" From 7f4cb6c416d19569cd4cab9b3b89652af26f58ce Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Wed, 7 May 2025 15:43:11 +0200 Subject: [PATCH 2/2] Add bookstack for troublshooting --- ct/bookstack.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ct/bookstack.sh b/ct/bookstack.sh index 8084195..86d3be6 100644 --- a/ct/bookstack.sh +++ b/ct/bookstack.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) # Copyright (c) 2021-2025 community-scripts ORG # Author: MickLesk (Canbiz) # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE