1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gotify_ynh.git synced 2024-09-03 20:36:26 +02:00
gotify_ynh/scripts/install

165 lines
5.5 KiB
Text
Raw Normal View History

2019-02-16 15:00:20 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2022-07-29 00:43:33 +02:00
ynh_clean_setup () {
2022-10-05 22:54:13 +02:00
true
2022-07-29 00:43:33 +02:00
}
2019-02-16 15:00:20 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
2021-04-17 15:47:43 +02:00
path_url=$YNH_APP_ARG_PATH
2019-02-16 15:00:20 +01:00
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2022-10-05 22:54:13 +02:00
ynh_script_progression --message="Validating installation parameters..." --weight=1
2019-02-16 15:00:20 +01:00
final_path=/opt/yunohost/$app
2022-07-29 00:43:33 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2019-02-16 15:00:20 +01:00
# Register (book) web path
2022-07-29 00:43:33 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2019-02-16 15:00:20 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2022-10-05 22:54:13 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=1
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=password --value=$password
2019-02-16 15:00:20 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2022-10-05 22:54:13 +02:00
ynh_script_progression --message="Finding an available port..." --weight=1
2022-07-29 00:43:33 +02:00
# Find an available port
port=$(ynh_find_port --port=8080)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2019-02-16 15:00:20 +01:00
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
2020-11-22 15:27:37 +01:00
ynh_script_progression --message="Creating a MySQL database..." --weight=10
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
2019-02-16 15:00:20 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Setting up source files..." --weight=6
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2019-02-16 15:00:20 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2022-07-29 00:43:33 +02:00
ynh_setup_source --dest_dir="$final_path" --source_id="$YNH_ARCH"
mkdir -p $final_path/data
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2019-02-16 15:00:20 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-11-22 15:27:37 +01:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
# Create a dedicated NGINX config
2019-02-16 15:00:20 +01:00
ynh_add_nginx_config
#=================================================
2022-07-29 00:43:33 +02:00
# SPECIFIC SETUP
2019-02-16 15:00:20 +01:00
#=================================================
2022-07-29 00:43:33 +02:00
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
ynh_add_config --template="../conf/config.yml" --destination="$final_path/config.yml"
chmod 400 "$final_path/config.yml"
chown $app:$app "$final_path/config.yml"
2019-02-16 15:00:20 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2022-10-05 22:54:13 +02:00
ynh_script_progression --message="Configuring a systemd service..." --weight=1
2019-02-16 15:00:20 +01:00
# Create a dedicated systemd config
2022-07-29 00:43:33 +02:00
architecture=$YNH_ARCH
2019-02-16 15:00:20 +01:00
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
2022-07-29 00:43:33 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2019-02-16 15:00:20 +01:00
#=================================================
2022-10-05 22:54:13 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
yunohost service add $app
2019-02-16 15:00:20 +01:00
#=================================================
2022-07-29 00:43:33 +02:00
# START SYSTEMD SERVICE
2019-02-16 15:00:20 +01:00
#=================================================
2022-10-05 22:54:13 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"
2019-02-16 15:00:20 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2022-07-29 00:43:33 +02:00
ynh_script_progression --message="Configuring permissions..." --weight=1
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
2019-02-16 15:00:20 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-11-22 15:27:37 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2019-02-16 15:00:20 +01:00
2022-07-29 00:43:33 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2019-02-16 15:00:20 +01:00
ynh_script_progression --message="Installation of $app completed" --last