peertube_remote_runner_ynh/scripts/install
Éric Gaspar 5cc544c396 cleaning
2023-12-31 16:03:09 +01:00

72 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Installing PeerTube remote runner npm module..." --weight=1
chown -R $app:www-data "$install_dir"
pushd "$install_dir"
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm install @peertube/peertube-runner
popd
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding PeerTube runner service $app..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add $app --description="PeerTube remote runner" --log="/var/log/$app/$app.log"
#=================================================
# 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="systemd"
#=================================================
# SPECIFIC FINALIZATION
#=================================================
# RUNNER REGISTRATION
#=================================================
ynh_script_progression --message="Registering the runner on Peertube server..." --weight=1
runner_id=$(ynh_string_random --length=5 --filter='0-9')
ynh_app_setting_set --app=$app --key='runner_id' --value=$runner_id
pushd "$install_dir"
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_node "$install_dir/node_modules/@peertube/peertube-runner" register --url $peertube_url --registration-token $runner_token --runner-name $app\_$runner_id
popd
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last