mirror of
https://github.com/YunoHost-Apps/fab-manager_ynh.git
synced 2024-09-03 18:36:16 +02:00
106 lines
4.1 KiB
Bash
Executable file
106 lines
4.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# INITIALIZE AND STORE SETTINGS
|
|
#=================================================
|
|
|
|
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
|
|
|
|
secret_key_base=$(ynh_string_random --length=30)
|
|
ynh_app_setting_set --app="$app" --key="secret_key_base" --value="$secret_key_base"
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing NodeJS..." --weight=1
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
|
|
|
|
ynh_script_progression --message="Installing Ruby..." --weight=4
|
|
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version"
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring $app's PostgreSQL database..." --weight=1
|
|
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;"
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS unaccent;"
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;"
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R "$app:www-data" "$install_dir"
|
|
|
|
chmod -R o-rwx "$data_dir"
|
|
chown -R "$app:www-data" "$data_dir"
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
|
|
|
ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
|
|
chmod 400 "$install_dir/config/secrets.yml"
|
|
chown "$app:$app" "$install_dir/config/secrets.yml"
|
|
|
|
ynh_add_config --template="database.yml" --destination="$install_dir/config/database.yml"
|
|
chmod 400 "$install_dir/config/database.yml"
|
|
chown "$app:$app" "$install_dir/config/database.yml"
|
|
|
|
#=================================================
|
|
# BUILD APP
|
|
#=================================================
|
|
ynh_script_progression --message="Building app..." --weight=7
|
|
|
|
fabmanager_build_ruby
|
|
|
|
fabmanager_migrate_db
|
|
fabmanager_seed_db
|
|
|
|
fabmanager_build_ui
|
|
|
|
ynh_secure_remove --file="$install_dir/.cache"
|
|
|
|
#=================================================
|
|
# SYSTEM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config --service="$app-app" --template="fab-manager-app.service"
|
|
yunohost service add "$app-app" --description="$app app service"
|
|
ynh_add_systemd_config --service="$app-worker" --template="fab-manager-worker.service"
|
|
yunohost service add "$app-worker" --description="$app worker service"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd
|
|
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|