#!/bin/bash source _common.sh source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression "Stopping $app's systemd service..." ynh_systemctl --service=$app --action="stop" --log_path="systemd" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression "Upgrading source files..." ynh_setup_source --dest_dir="$install_dir" chmod +x "$install_dir/shiori" #================================================= # MIGRATE AND UPGRADE #================================================= if ynh_app_upgrading_from_version_before 1.50~ynh9 then ynh_script_progression "Migrating sqlite from version < 1.50~ynh9..." 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 #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression "Upgrading system configurations related to $app..." ynh_config_add_nginx ynh_config_add_systemd ynh_config_add_logrotate yunohost service add $app --description="Simple bookmark manager" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." ynh_systemctl --service=$app --action="start" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Upgrade of $app completed"