mirror of
https://github.com/YunoHost-Apps/syncserver-rs_ynh.git
synced 2024-09-03 20:26:32 +02:00
141 lines
6.3 KiB
Bash
141 lines
6.3 KiB
Bash
#!/bin/bash
|
|
#### App file generated with YoloGen, the Yunohost app generator, version 0.6.5.
|
|
# This is the tutorial version of the app.
|
|
# It contains extra commands to explain what should be done in case you want to adjust some part of the script.
|
|
# Once you are done, you may remove them.
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
secret=$(ynh_string_random --length=40)
|
|
master_secret=$(ynh_string_random --length=40)
|
|
db_name_tokenserver="${db_name}_tokenserver"
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name_tokenserver --value=$db_name_tokenserver
|
|
ynh_app_setting_set --app=$app --key=secret --value=$secret
|
|
ynh_app_setting_set --app=$app --key=master_secret --value=$master_secret
|
|
|
|
#=================================================
|
|
# 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'
|
|
|
|
#=================================================
|
|
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
|
|
|
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
|
|
### downloaded from an upstream source, like a git repository.
|
|
### `ynh_setup_source` use the file conf/app.src
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir/build"
|
|
|
|
# $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"
|
|
|
|
#=================================================
|
|
# PROVISION SECOND DB
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring second MySQL database..."
|
|
ynh_mysql_create_db "$db_name_tokenserver" "$db_user" "$db_pwd"
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
ynh_mysql_execute_as_root --sql="INSERT INTO services (id, service, pattern) VALUES (1, 'sync-1.5', '{node}/1.5/{uid}')" --database="$db_name_tokenserver";
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH SYNC_TOKENSERVER__DATABASE_URL="mysql://$db_user:${db_pwd}@localhost/$db_name_tokenserver" $install_dir/venv/bin/python tools/tokenserver/add_node.py "https://${domain%%+(/)}" 10
|
|
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/.local"
|
|
ynh_secure_remove --file="$install_dir/build"
|
|
|
|
#=================================================
|
|
# SYSTEM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
|
# Create a dedicated NGINX config using the conf/nginx.conf template
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated systemd 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
|
|
|
|
#=================================================
|
|
# APP INITIAL CONFIGURATION
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding 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"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
# Start a systemd service
|
|
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="Installation of $app completed" --last
|