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

169 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
#=================================================
# 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
path_url=/
2019-02-16 15:00:20 +01:00
admin=$YNH_APP_ARG_ADMIN
is_public=1
2019-02-16 15:00:20 +01:00
password=$YNH_APP_ARG_PASSWORD
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Validating installation parameters..."
2019-02-16 15:00:20 +01:00
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Storing installation settings..."
2019-02-16 15:00:20 +01:00
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
2019-02-17 19:02:16 +01:00
ynh_app_setting_set $app password $password
2019-02-16 15:00:20 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 8080)
# Open this port
ynh_app_setting_set $app port $port
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Creating a MySQL database..." --weight=20
2019-02-16 15:00:20 +01:00
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
#=================================================
# 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
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" $architecture
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Configuring nginx web server..." --weight=2
2019-02-16 15:00:20 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Configuring system user..." --weight=2
2019-02-16 15:00:20 +01:00
# Create a system user
ynh_system_user_create $app
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Create config file..." --weight=1
2019-02-16 15:00:20 +01:00
cp ../conf/config.yml "$final_path/config.yml"
2019-02-23 17:47:12 +01:00
ynh_replace_string "__APP__" $app "$final_path/config.yml"
2019-02-16 15:00:20 +01:00
ynh_replace_string "__PORT__" $port "$final_path/config.yml"
ynh_replace_string "__DBNAME__" $db_name "$final_path/config.yml"
ynh_replace_string "__DBPASS__" $db_pwd "$final_path/config.yml"
ynh_replace_string "__ADMINUSER__" $admin "$final_path/config.yml"
ynh_replace_string "__ADMINPASS__" $password "$final_path/config.yml"
ynh_replace_string "__DOMAIN__" $domain "$final_path/config.yml"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.yml"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
2020-06-07 20:01:41 +02:00
chown -R root:$app $final_path
2020-06-08 13:13:07 +02:00
mkdir -p $final_path/data
2020-06-07 20:01:41 +02:00
chown -R $app: $final_path/data/
chmod o-rwx $final_path/ -R
2019-02-16 15:00:20 +01:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app
#=================================================
# SETUP SSOWAT
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Configuring SSOwat..." --weight=1
2019-02-16 15:00:20 +01:00
# Make app public if necessary
2020-04-13 14:29:00 +02:00
ynh_permission_update --permission "main" --add visitors
2019-02-16 15:00:20 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-04-14 21:23:42 +02:00
ynh_script_progression --message="Reloading nginx web server..." --weight=1
2019-02-16 15:00:20 +01:00
systemctl reload nginx
systemctl start $app
ynh_script_progression --message="Installation of $app completed" --last
ynh_print_warn "Change the admin password after the first login or delete it in the config file (stored in plain text)"