2018-02-19 22:23:03 +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=$YNH_APP_ARG_PATH
|
2019-10-22 23:39:45 +02:00
|
|
|
user=$YNH_APP_ARG_USER
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
# This is a multi-instance app, meaning it can be installed several times independently
|
|
|
|
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
|
|
|
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
|
|
|
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
|
|
|
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
|
|
|
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
|
|
|
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
|
|
|
# The app instance name is probably what you are interested the most, since this is
|
|
|
|
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
|
|
|
# db names, ...
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
2019-10-22 23:39:45 +02:00
|
|
|
if [ $is_public -eq 1 ] && [ ! $user ]
|
|
|
|
then
|
|
|
|
ynh_die "You must set up an user if owntracks is public"
|
|
|
|
fi
|
|
|
|
|
2018-02-19 22:23:03 +01:00
|
|
|
# Register (book) web path
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2020-07-08 18:26:15 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=user --value=$user
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Creating a MySQL database..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
2020-07-08 17:31:37 +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
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2018-02-19 22:23:03 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx web server..."
|
|
|
|
|
|
|
|
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
# Create a system user
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Configuring php-fpm..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
# Create a dedicated php-fpm config
|
|
|
|
ynh_add_fpm_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# PREPARE MYQSL DATABASE
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Initializing the database..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
ynh_mysql_connect_as $app $db_pwd $db_name < "$final_path/sql/schema.sql"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_replace_string "__USER__" "$app" "$final_path/config.inc.php"
|
|
|
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/config.inc.php"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions to app files
|
|
|
|
chown -R $app:www-data $final_path
|
|
|
|
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
# SETUP PERMISSIONS
|
2018-02-19 22:23:03 +01:00
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
2020-07-08 17:31:37 +02:00
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
2020-07-08 18:26:15 +02:00
|
|
|
ynh_permission_update --permission "main" --add "visitors"
|
2020-07-08 17:31:37 +02:00
|
|
|
else
|
|
|
|
ynh_permission_update --permission "main" --add $user --remove="all_users"
|
|
|
|
fi
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
# RELOAD NGINX
|
2018-02-19 22:23:03 +01:00
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
2020-07-08 17:31:37 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-02-19 22:23:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-08 17:31:37 +02:00
|
|
|
# END OF SCRIPT
|
2018-02-19 22:23:03 +01:00
|
|
|
#=================================================
|
|
|
|
|
2020-07-08 17:45:01 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|