From e14063176077f4da2fc7aa12c746f8d57c6298f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Sat, 5 Jul 2025 22:30:08 +0200 Subject: [PATCH] Refactor (#5732) --- ct/bookstack.sh | 19 ++++++++++++------- install/bookstack-install.sh | 22 ++++++++-------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/ct/bookstack.sh b/ct/bookstack.sh index 5a7fda1f2..b1710edd2 100644 --- a/ct/bookstack.sh +++ b/ct/bookstack.sh @@ -23,25 +23,31 @@ 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 + if [[ "${RELEASE}" != "$(cat ~/.bookstack 2>/dev/null)" ]] || [[ ! -f ~/.bookstack ]]; then msg_info "Stopping Apache2" systemctl stop apache2 msg_ok "Services Stopped" - msg_info "Updating ${APP} to v${RELEASE}" + msg_info "Backing up data" mv /opt/bookstack /opt/bookstack-backup - curl -fsSL "https://github.com/BookStackApp/BookStack/archive/refs/tags/v${RELEASE}.zip" -o "/opt/BookStack-${RELEASE}.zip" - $STD unzip "/opt/BookStack-${RELEASE}.zip" -d /opt - mv "/opt/BookStack-${RELEASE}" /opt/bookstack + msg_ok "Backup finished" + + fetch_and_deploy_gh_release "bookstack" "BookStackApp/BookStack" + + msg_info "Restoring backup" cp /opt/bookstack-backup/.env /opt/bookstack/.env [[ -d /opt/bookstack-backup/public/uploads ]] && cp -a /opt/bookstack-backup/public/uploads/. /opt/bookstack/public/uploads/ [[ -d /opt/bookstack-backup/storage/uploads ]] && cp -a /opt/bookstack-backup/storage/uploads/. /opt/bookstack/storage/uploads/ [[ -d /opt/bookstack-backup/themes ]] && cp -a /opt/bookstack-backup/themes/. /opt/bookstack/themes/ + msg_ok "Backup restored" + + msg_info "Configuring BookStack" cd /opt/bookstack export COMPOSER_ALLOW_SUPERUSER=1 $STD composer install --no-dev @@ -51,7 +57,7 @@ function update_script() { 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_ok "Configured BookStack" msg_info "Starting Apache2" systemctl start apache2 @@ -59,7 +65,6 @@ function update_script() { msg_info "Cleaning Up" rm -rf /opt/bookstack-backup - rm -rf "/opt/BookStack-${RELEASE}.zip" msg_ok "Cleaned" msg_ok "Updated Successfully" else diff --git a/install/bookstack-install.sh b/install/bookstack-install.sh index 0b3ebbd50..b2f2cc126 100644 --- a/install/bookstack-install.sh +++ b/install/bookstack-install.sh @@ -15,13 +15,12 @@ update_os msg_info "Installing Dependencies (Patience)" $STD apt-get install -y \ - apache2 \ - php8.2-{mbstring,gd,fpm,curl,intl,ldap,tidy,bz2,mysql,zip,xml} \ - composer \ - libapache2-mod-php \ - make + apache2 +make msg_ok "Installed Dependencies" +PHP_MODULE="fpm, ldap, tidy, bz2, mysql" PHP_FPM="YES" PHP_APACHE="YES" PHP_VERSION="8.2" setup_php +setup_composer setup_mariadb msg_info "Setting up Database" @@ -39,13 +38,10 @@ $STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUS } >>~/bookstack.creds msg_ok "Set up database" -msg_info "Setup Bookstack (Patience)" +fetch_and_deploy_gh_release "bookstack" "BookStackApp/BookStack" 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 "v${RELEASE}.zip" -$STD unzip v${RELEASE}.zip -mv BookStack-${RELEASE} /opt/bookstack + +msg_info "Configuring Bookstack (Patience)" cd /opt/bookstack cp .env.example .env sudo sed -i "s|APP_URL=.*|APP_URL=http://$LOCAL_IP|g" /opt/bookstack/.env @@ -61,8 +57,7 @@ chmod -R 775 /opt/bookstack/storage /opt/bookstack/bootstrap/cache /opt/bookstac chmod -R 640 /opt/bookstack/.env $STD a2enmod rewrite $STD a2enmod php8.2 -echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" -msg_ok "Installed Bookstack" +msg_ok "Configured Bookstack" msg_info "Creating Service" cat </etc/apache2/sites-available/bookstack.conf @@ -111,7 +106,6 @@ motd_ssh customize msg_info "Cleaning up" -rm -rf /opt/v${RELEASE}.zip $STD apt-get autoremove $STD apt-get autoclean msg_ok "Cleaned"