Skip to content

Commit e140631

Browse files
authored
Refactor (#5732)
1 parent ae24b56 commit e140631

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

ct/bookstack.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,31 @@ function update_script() {
2323
header_info
2424
check_container_storage
2525
check_container_resources
26+
2627
if [[ ! -d /opt/bookstack ]]; then
2728
msg_error "No ${APP} Installation Found!"
2829
exit
2930
fi
3031
RELEASE=$(curl -fsSL https://api.github.com/repos/BookStackApp/BookStack/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
31-
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then
32+
if [[ "${RELEASE}" != "$(cat ~/.bookstack 2>/dev/null)" ]] || [[ ! -f ~/.bookstack ]]; then
3233
msg_info "Stopping Apache2"
3334
systemctl stop apache2
3435
msg_ok "Services Stopped"
3536

36-
msg_info "Updating ${APP} to v${RELEASE}"
37+
msg_info "Backing up data"
3738
mv /opt/bookstack /opt/bookstack-backup
38-
curl -fsSL "https://github.com/BookStackApp/BookStack/archive/refs/tags/v${RELEASE}.zip" -o "/opt/BookStack-${RELEASE}.zip"
39-
$STD unzip "/opt/BookStack-${RELEASE}.zip" -d /opt
40-
mv "/opt/BookStack-${RELEASE}" /opt/bookstack
39+
msg_ok "Backup finished"
40+
41+
fetch_and_deploy_gh_release "bookstack" "BookStackApp/BookStack"
42+
43+
msg_info "Restoring backup"
4144
cp /opt/bookstack-backup/.env /opt/bookstack/.env
4245
[[ -d /opt/bookstack-backup/public/uploads ]] && cp -a /opt/bookstack-backup/public/uploads/. /opt/bookstack/public/uploads/
4346
[[ -d /opt/bookstack-backup/storage/uploads ]] && cp -a /opt/bookstack-backup/storage/uploads/. /opt/bookstack/storage/uploads/
4447
[[ -d /opt/bookstack-backup/themes ]] && cp -a /opt/bookstack-backup/themes/. /opt/bookstack/themes/
48+
msg_ok "Backup restored"
49+
50+
msg_info "Configuring BookStack"
4551
cd /opt/bookstack
4652
export COMPOSER_ALLOW_SUPERUSER=1
4753
$STD composer install --no-dev
@@ -51,15 +57,14 @@ function update_script() {
5157
chmod -R 775 /opt/bookstack/storage /opt/bookstack/bootstrap/cache /opt/bookstack/public/uploads
5258
chmod -R 640 /opt/bookstack/.env
5359
echo "${RELEASE}" >/opt/${APP}_version.txt
54-
msg_ok "Updated ${APP} to v${RELEASE}"
60+
msg_ok "Configured BookStack"
5561

5662
msg_info "Starting Apache2"
5763
systemctl start apache2
5864
msg_ok "Started Apache2"
5965

6066
msg_info "Cleaning Up"
6167
rm -rf /opt/bookstack-backup
62-
rm -rf "/opt/BookStack-${RELEASE}.zip"
6368
msg_ok "Cleaned"
6469
msg_ok "Updated Successfully"
6570
else

install/bookstack-install.sh

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ update_os
1515

1616
msg_info "Installing Dependencies (Patience)"
1717
$STD apt-get install -y \
18-
apache2 \
19-
php8.2-{mbstring,gd,fpm,curl,intl,ldap,tidy,bz2,mysql,zip,xml} \
20-
composer \
21-
libapache2-mod-php \
22-
make
18+
apache2
19+
make
2320
msg_ok "Installed Dependencies"
2421

22+
PHP_MODULE="fpm, ldap, tidy, bz2, mysql" PHP_FPM="YES" PHP_APACHE="YES" PHP_VERSION="8.2" setup_php
23+
setup_composer
2524
setup_mariadb
2625

2726
msg_info "Setting up Database"
@@ -39,13 +38,10 @@ $STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUS
3938
} >>~/bookstack.creds
4039
msg_ok "Set up database"
4140

42-
msg_info "Setup Bookstack (Patience)"
41+
fetch_and_deploy_gh_release "bookstack" "BookStackApp/BookStack"
4342
LOCAL_IP="$(hostname -I | awk '{print $1}')"
44-
cd /opt
45-
RELEASE=$(curl -fsSL https://api.github.com/repos/BookStackApp/BookStack/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
46-
curl -fsSL "https://github.com/BookStackApp/BookStack/archive/refs/tags/v${RELEASE}.zip" -o "v${RELEASE}.zip"
47-
$STD unzip v${RELEASE}.zip
48-
mv BookStack-${RELEASE} /opt/bookstack
43+
44+
msg_info "Configuring Bookstack (Patience)"
4945
cd /opt/bookstack
5046
cp .env.example .env
5147
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
6157
chmod -R 640 /opt/bookstack/.env
6258
$STD a2enmod rewrite
6359
$STD a2enmod php8.2
64-
echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
65-
msg_ok "Installed Bookstack"
60+
msg_ok "Configured Bookstack"
6661

6762
msg_info "Creating Service"
6863
cat <<EOF >/etc/apache2/sites-available/bookstack.conf
@@ -111,7 +106,6 @@ motd_ssh
111106
customize
112107

113108
msg_info "Cleaning up"
114-
rm -rf /opt/v${RELEASE}.zip
115109
$STD apt-get autoremove
116110
$STD apt-get autoclean
117111
msg_ok "Cleaned"

0 commit comments

Comments
 (0)