2018-08-26 19:04:08 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
2019-02-14 19:32:04 +01:00
|
|
|
# GENERIC START
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2019-02-14 19:32:04 +01:00
|
|
|
# MANAGE SCRIPT FAILURE
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-02-14 19:32:04 +01:00
|
|
|
ynh_clean_setup () {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2023-04-12 20:57:37 +02:00
|
|
|
context=$YNH_APP_ARG_CONTEXT
|
2023-04-07 00:15:58 +02:00
|
|
|
mode=$YNH_APP_ARG_MODE
|
|
|
|
cluster=$YNH_APP_ARG_CLUSTER
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
final_path=/var/www/$app
|
2021-03-17 21:13:57 +01:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
# Register (book) web path
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Finding an available port..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
# Find an available port
|
|
|
|
port=$(ynh_find_port --port=8095)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-04-10 17:46:40 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
|
|
|
|
# Create a system user
|
2021-06-30 05:08:36 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
2021-04-10 17:46:40 +02:00
|
|
|
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2019-02-14 19:32:04 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-02-12 17:54:52 +01:00
|
|
|
mkdir "$final_path"
|
|
|
|
chown $app:$app "$final_path"
|
2021-03-17 21:13:57 +01:00
|
|
|
pushd "$final_path"
|
2023-02-12 17:54:52 +01:00
|
|
|
ynh_exec_as $app git init
|
2023-02-12 17:48:28 +01:00
|
|
|
ynh_exec_as $app git remote add origin "$yunorunner_repository"
|
|
|
|
ynh_exec_as $app git fetch --quiet --depth=1 origin "$yunorunner_release"
|
|
|
|
ynh_exec_as $app git reset --quiet --hard FETCH_HEAD
|
2023-04-12 20:57:37 +02:00
|
|
|
setup_lxd
|
|
|
|
git clone https://github.com/YunoHost/package_check "./package_check"
|
2021-03-17 21:13:57 +01:00
|
|
|
popd
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-04-17 18:32:58 +02:00
|
|
|
chmod 750 "$final_path"
|
2021-04-10 17:46:40 +02:00
|
|
|
chmod -R o-rwx "$final_path"
|
2023-02-12 17:54:52 +01:00
|
|
|
chown -R $app "$final_path"
|
|
|
|
chown $app:www-data "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path/results"
|
2021-04-10 17:46:40 +02:00
|
|
|
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
# Create a dedicated NGINX config
|
2018-08-26 19:04:08 +02:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# INSTALL PYTHON DEPENDENCIES
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Installing Python dependencies..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2019-02-14 20:12:22 +01:00
|
|
|
pushd $final_path
|
2021-03-17 21:13:57 +01:00
|
|
|
python3 -m venv venv
|
|
|
|
venv/bin/pip install --upgrade pip
|
|
|
|
venv/bin/pip install -r requirements-frozen.txt
|
2019-02-14 20:12:22 +01:00
|
|
|
popd
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2018-10-14 17:45:28 +02:00
|
|
|
#=================================================
|
2021-04-10 17:46:40 +02:00
|
|
|
# ADD A CONFIGURATION
|
2018-10-14 17:45:28 +02:00
|
|
|
#=================================================
|
2021-04-10 17:46:40 +02:00
|
|
|
ynh_script_progression --message="Adding a config file..."
|
2018-10-14 17:45:28 +02:00
|
|
|
|
2023-04-12 20:57:37 +02:00
|
|
|
if $mode = "auto"; then
|
|
|
|
auto = "True"
|
|
|
|
else
|
|
|
|
auto = "False"
|
|
|
|
fi
|
|
|
|
|
2021-03-01 21:47:04 +01:00
|
|
|
ynh_add_config --template="yunorunner.config.py" --destination="$final_path/config.py"
|
2018-10-14 17:45:28 +02:00
|
|
|
|
2021-04-10 17:46:40 +02:00
|
|
|
chmod 400 "$final_path/config.py"
|
|
|
|
chown $app:$app "$final_path/config.py"
|
|
|
|
|
2023-04-07 00:15:58 +02:00
|
|
|
#=================================================
|
|
|
|
# FINISH INSTALL
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Run Yunorunner's finish_install script..."
|
|
|
|
|
2023-04-12 20:57:37 +02:00
|
|
|
if [ $context != "personal-ci" ] && [ ${PACKAGE_CHECK_EXEC:-0} -ne 0 ]; then
|
|
|
|
tweak_yunohost
|
|
|
|
fi
|
|
|
|
|
|
|
|
add_cron_jobs
|
2023-04-07 00:15:58 +02:00
|
|
|
|
2021-04-11 22:11:16 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# GENERIC FINALIZATION
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
yunohost service add $app --description="$app daemon for YunoRunner"
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# START SYSTEMD SERVICE
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
# Start a systemd service
|
2022-01-10 01:04:29 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" --timeout=30
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# SETUP SSOWAT
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
# Make app public
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2018-08-26 19:36:20 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# RELOAD NGINX
|
2018-08-26 19:36:20 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2018-08-26 19:36:20 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-02-14 19:32:04 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|