1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/outline_ynh.git synced 2024-09-03 19:56:12 +02:00
outline_ynh/scripts/upgrade

143 lines
5.6 KiB
Bash

#!/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
#=================================================
# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed
if ynh_app_upstream_version_changed
then
ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --full_replace
fi
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir"
#=======================================================
# MIGRATE MINIO BUCKET IF UPGRADING FROM AN OLD VERSION
#=======================================================
ynh_script_progression "Checking if a migration is needed"
if ynh_app_upgrading_from_version_before_or_equal_to 0.69.2.2~ynh1
then
ynh_script_progression "Migrating MinIO data to local directory"
mkdir -p "/var/lib/$app/data"
chown -R minio:www-data "/var/lib/$app"
ynh_hide_warnings sudo -u minio $mc_path/mc mirror --preserve "minio/outlinestorage" "/var/lib/$app/data"
chown -R $app:www-data "/var/lib/$app"
ynh_script_progression "Data migration finished"
ynh_script_progression "Data bucket was kept for safety, just in case !"
ynh_script_progression "Don't forget to remove MinIO app if you don't use it !"
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS "uuid-ossp";"
else
ynh_script_progression "No migration to be done"
fi
#=======================================================
# MIGRATE DEFAULT LANGUAGE ENV PARAMETER
#=======================================================
if ynh_app_upgrading_from_version_before_or_equal_to 0.75.0~ynh1
then
ynh_script_progression "Migrating default language variable"
if [ "$language" == "fr" ]
then
ynh_app_setting_set --key=language --value="fr_FR"
else
ynh_app_setting_set --key=language --value="en_US"
fi
else
ynh_script_progression "No default language migration to be done"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression "Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_config_add_nginx
# Install Nodejs
ynh_nodejs_install
#=================================================
# UPGRADE YARN DEPENDENCIES
#=================================================
ynh_script_progression "Building $app. This can be very long, be patient !"
pushd "$install_dir"
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install --frozen-lockfile --network-timeout 1000000000 2>&1
ynh_hide_warnings ynh_exec_as_app node_load_PATH NODE_OPTIONS="--max-old-space-size=3900" yarn build 2>&1
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn cache clean 2>&1
popd
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression "Adding $app's configuration..."
ynh_config_add --template=".env" --destination="$install_dir/.env"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/.env"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/.env"
#=================================================
# RUN DB MIGRATION
#=================================================
ynh_script_progression "Running DB initial migration..."
pushd "$install_dir"
ynh_hide_warnings ynh_exec_as_app node_load_PATH NODE_ENV=production yarn db:migrate
popd
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression "Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_config_add_systemd
# Use logrotate to manage app-specific logfile(s)
ynh_config_add_logrotate
cron_path="/etc/cron.d/$app"
ynh_config_add --template="outline.cron" --destination="$cron_path"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root: "$cron_path"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 644 "$cron_path"
yunohost service add $app --description="Outline server" --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"