Skip to content

Commit 492be65

Browse files
authored
Refactor (#6416)
1 parent b5b5934 commit 492be65

2 files changed

Lines changed: 16 additions & 26 deletions

File tree

ct/monica.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ function update_script() {
2727
msg_error "No ${APP} Installation Found!"
2828
exit
2929
fi
30+
3031
RELEASE=$(curl -fsSL https://api.github.com/repos/monicahq/monica/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 [[ ! -f ~/.monica ]] || [[ "${RELEASE}" != "$(cat ~/.monica)" ]]; then
3233
msg_info "Stopping Service"
3334
systemctl stop apache2
3435
msg_ok "Stopped Service"
3536

36-
msg_info "Updating ${APP} to v${RELEASE}"
37-
cd /opt
37+
msg_info "Creating backup"
3838
mv /opt/monica/ /opt/monica-backup
39-
curl -fsSL "https://github.com/monicahq/monica/releases/download/v${RELEASE}/monica-v${RELEASE}.tar.bz2" -o $(basename "https://github.com/monicahq/monica/releases/download/v${RELEASE}/monica-v${RELEASE}.tar.bz2")
40-
tar -xjf "monica-v${RELEASE}.tar.bz2"
41-
mv "/opt/monica-v${RELEASE}" /opt/monica
39+
msg_ok "Backup created"
40+
41+
fetch_and_deploy_gh_release "monica" "monicahq/monica" "prebuild" "latest" "/opt/monica" "monica-v*.tar.bz2"
42+
43+
msg_info "Configuring monica"
4244
cd /opt/monica/
4345
cp -r /opt/monica-backup/.env /opt/monica
4446
cp -r /opt/monica-backup/storage/* /opt/monica/storage/
@@ -48,17 +50,16 @@ function update_script() {
4850
$STD php artisan monica:update --force
4951
chown -R www-data:www-data /opt/monica
5052
chmod -R 775 /opt/monica/storage
51-
echo "${RELEASE}" >/opt/${APP}_version.txt
52-
msg_ok "Updated $APP to v${RELEASE}"
53+
msg_ok "Configured monica"
5354

5455
msg_info "Starting Service"
5556
systemctl start apache2
5657
msg_ok "Started Service"
5758

5859
msg_info "Cleaning up"
59-
rm -r "/opt/monica-v${RELEASE}.tar.bz2"
6060
rm -r /opt/monica-backup
6161
msg_ok "Cleaned"
62+
6263
msg_ok "Updated Successfully"
6364
else
6465
msg_ok "No update required. ${APP} is already at v${RELEASE}"

install/monica-install.sh

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ setting_up_container
1313
network_check
1414
update_os
1515

16-
msg_info "Installing Dependencies"
17-
$STD apt-get install -y \
18-
apache2 \
19-
libapache2-mod-php \
20-
php-{bcmath,curl,dom,gd,gmp,iconv,intl,json,mbstring,mysqli,opcache,pdo-mysql,redis,tokenizer,xml,zip} \
21-
composer
22-
msg_ok "Installed Dependencies"
23-
16+
PHP_VERSION="8.2" PHP_APACHE="YES" PHP_MODULE="dom,gmp,iconv,mysqli,pdo-mysql,redis,tokenizer" setup_php
17+
setup_composer
2418
setup_mariadb
2519
NODE_VERSION="20" NODE_MODULE="yarn@latest" setup_nodejs
2620

@@ -39,12 +33,9 @@ $STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUS
3933
} >>~/monica.creds
4034
msg_ok "Set up MariaDB"
4135

42-
msg_info "Installing monica"
43-
RELEASE=$(curl -fsSL https://api.github.com/repos/monicahq/monica/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
44-
cd /opt
45-
curl -fsSL "https://github.com/monicahq/monica/releases/download/v${RELEASE}/monica-v${RELEASE}.tar.bz2" -o "monica-v${RELEASE}.tar.bz2"
46-
tar -xjf "monica-v${RELEASE}.tar.bz2"
47-
mv "/opt/monica-v${RELEASE}" /opt/monica
36+
fetch_and_deploy_gh_release "monica" "monicahq/monica" "prebuild" "latest" "/opt/monica" "monica-v*.tar.bz2"
37+
38+
msg_info "Configuring monica"
4839
cd /opt/monica
4940
cp /opt/monica/.env.example /opt/monica/.env
5041
HASH_SALT=$(openssl rand -base64 32)
@@ -59,8 +50,7 @@ $STD php artisan key:generate
5950
$STD php artisan setup:production --email=admin@helper-scripts.com --password=helper-scripts.com --force
6051
chown -R www-data:www-data /opt/monica
6152
chmod -R 775 /opt/monica/storage
62-
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
63-
msg_ok "Installed monica"
53+
msg_ok "Configured monica"
6454

6555
msg_info "Creating Service"
6656
cat <<EOF >/etc/apache2/sites-available/monica.conf
@@ -87,7 +77,6 @@ motd_ssh
8777
customize
8878

8979
msg_info "Cleaning up"
90-
rm -rf "/opt/monica-v${RELEASE}.tar.bz2"
9180
$STD apt-get -y autoremove
9281
$STD apt-get -y autoclean
9382
msg_ok "Cleaned"

0 commit comments

Comments
 (0)