1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/shiori_ynh.git synced 2024-09-03 20:26:17 +02:00
shiori_ynh/scripts/upgrade

91 lines
3.6 KiB
Text
Raw Normal View History

2022-01-10 15:18:34 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2022-01-10 22:50:47 +01:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
2022-01-10 15:18:34 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-06-08 10:39:21 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2022-01-10 15:18:34 +01:00
2024-06-08 10:39:21 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
2022-01-10 15:18:34 +01:00
2023-02-20 16:20:49 +01:00
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chmod +x "$install_dir/shiori"
2024-03-17 21:35:27 +01:00
#=================================================
# MIGRATE AND UPGRADE
#=================================================
2024-06-08 10:39:21 +02:00
if ynh_compare_current_package_version --comparison lt --version 1.50~ynh9
2024-03-17 21:35:27 +01:00
then
ynh_script_progression --message="Migrating sqlite from version < 1.50~ynh9..." --weight=1
FTS4_EXISTS=$(sqlite3 "$data_dir/shiori.db" "SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'bookmark_content' AND sql LIKE '%USING fts4%';")
if [ -z "$FTS4_EXISTS" ]
then
echo "No FTS4 table found or already migrated"
else
sqlite3 "$data_dir/shiori.db" "BEGIN TRANSACTION; CREATE VIRTUAL TABLE bookmark_content_fts5 USING fts5(title, content, html, docid); INSERT INTO bookmark_content_fts5 (title, content, html, docid) SELECT title, content, html, docid FROM bookmark_content; DROP TABLE bookmark_content; ALTER TABLE bookmark_content_fts5 RENAME TO bookmark_content; COMMIT;"
fi
SCHEMA_MIGRATIONS_EXISTS=$(sqlite3 "$data_dir/shiori.db" "SELECT name FROM sqlite_master WHERE type='table' AND name='schema_migrations';")
if [ -z "$SCHEMA_MIGRATIONS_EXISTS" ]; then
echo "No schema_migrations table found, skipping"
else
DIRTY=$(sqlite3 "$data_dir/shiori.db" "SELECT dirty FROM schema_migrations WHERE dirty = 1;")
if [ -z "$DIRTY" ]; then
echo "No dirty migrations found, skipping"
else
VERSION=$(sqlite3 "$data_dir/shiori.db" "SELECT version FROM schema_migrations WHERE dirty = 1;")
NEW_VERSION=$((VERSION - 1))
sqlite3 "$data_dir/shiori.db" "UPDATE schema_migrations SET version = $NEW_VERSION, dirty = 0 WHERE dirty = 1;"
fi
fi
fi
2022-01-10 15:18:34 +01:00
#=================================================
2023-02-20 16:31:16 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
2022-01-10 15:18:34 +01:00
#=================================================
2023-02-20 16:31:16 +01:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2022-01-10 15:18:34 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
2022-01-10 15:32:00 +01:00
yunohost service add $app --description="Simple bookmark manager" --log="/var/log/$app/$app.log"
2022-01-10 15:18:34 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
2022-01-10 15:38:24 +01:00
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
2022-01-10 15:18:34 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last