1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/syncserver-rs_ynh.git synced 2024-09-03 20:26:32 +02:00
syncserver-rs_ynh/scripts/upgrade
Mateusz 4d66d2babe
Fix installation (#10)
* Fix installation (#3)

* Fixed linter warnings

* Add python3-venv to deps.

* Auto-update README

* cleaning

---------

Co-authored-by: yunohost-bot <yunohost@yunohost.org>
Co-authored-by: Éric Gaspar <46165813+ericgaspar@users.noreply.github.com>

* Add maintainer and tweak auto versioning. (#7)

* Fix backup, restore, upgrade and change_url (#6)

* Fix backup and restore.

* Don't 302 to docs on /

* Update nginx.conf

* Fix linter

* Fix more scripts.

* Anoter fix

* Increase verbosity.

* Update scripts.

* Use dedicated domain.

* Fixup restore.

* Only create dir if it does not exist.

* Update manifest.toml

* Update install

---------

Co-authored-by: Éric Gaspar <46165813+ericgaspar@users.noreply.github.com>

* Fix package id (#9)

* Fix package id

* Auto-update README

---------

Co-authored-by: yunohost-bot <yunohost@yunohost.org>

---------

Co-authored-by: yunohost-bot <yunohost@yunohost.org>
Co-authored-by: Éric Gaspar <46165813+ericgaspar@users.noreply.github.com>
2023-10-25 10:17:56 +02:00

129 lines
No EOL
5.3 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" --line_match="Server closing"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=5
ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$install_dir"/.rustup CARGO_HOME="$install_dir"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y'
export PATH="$install_dir/.cargo/bin:$PATH"
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH cargo install diesel_cli --no-default-features --features 'mysql'
#=================================================
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/build"
fi
# $install_dir will automatically be initialized with some decent
# permission by default ... however, you may need to recursively reapply
# ownership to all files such as after the ynh_setup_source step
chown -R $app:www-data "$install_dir"
#=================================================
# BUILD
#=================================================
ynh_script_progression --message="Building the sources (it will take some time)..." --weight=10
ynh_exec_as $app python -m venv "${install_dir}/venv"
(
set +o nounset
source "${install_dir}/venv/bin/activate"
set -o nounset
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH $install_dir/venv/bin/pip install --upgrade pip
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH $install_dir/venv/bin/pip install --upgrade setuptools
pushd $install_dir/build
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH $install_dir/venv/bin/pip install -r requirements.txt
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH $install_dir/venv/bin/pip install -r tools/tokenserver/requirements.txt
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH cargo install --path ./syncserver --locked --root $install_dir --no-default-features --features=syncstorage-db/mysql
ynh_script_progression --message="Seeding the databases..."
# syncstorage db
diesel --database-url "mysql://$db_user:${db_pwd}@localhost/$db_name" migration --migration-dir syncstorage-mysql/migrations run
# tokenserver db
diesel --database-url "mysql://$db_user:${db_pwd}@localhost/$db_name_tokenserver" migration --migration-dir tokenserver-db/migrations run
popd
)
ynh_secure_remove --file="$install_dir/.cargo"
ynh_secure_remove --file="$install_dir/.rustup"
ynh_secure_remove --file="$install_dir/.cache"
ynh_secure_remove --file="$install_dir/build"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# This should be a literal copypasta of what happened in the install's "System configuration" section
ynh_add_nginx_config
ynh_add_systemd_config
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown -R $app: /var/log/$app
yunohost service add $app --description="Firefox Sync Server (Rust)" --log="/var/log/$app/$app.log"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_add_config --template="config.toml" --destination="$install_dir/config.toml"
# FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
chmod 400 "$install_dir/config.toml"
chown $app:$app "$install_dir/config.toml"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server running on http://127.0.0.1"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last