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
|
|
|
|
|
|
|
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
|
2021-07-24 08:28:46 +02:00
|
|
|
ynh_die "You must set up an user if OwnTracks is public"
|
2019-10-22 23:39:45 +02:00
|
|
|
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
|
|
|
|
2021-07-24 08:28:46 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
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
|
|
|
|
2021-07-24 08:28:46 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2018-02-19 22:23:03 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-03-17 09:09:35 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2020-07-08 17:31:37 +02:00
|
|
|
|
2018-02-19 22:23:03 +01:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2021-07-24 08:28:46 +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
|
|
|
|
#=================================================
|
2021-11-27 09:12:05 +01:00
|
|
|
ynh_script_progression --message="Adding a configuration file..."
|
2018-02-19 22:23:03 +01:00
|
|
|
|
2021-07-24 08:38:06 +02:00
|
|
|
ynh_add_config --template="../conf/config.inc.php" --destination="$final_path/config.inc.php"
|
2018-02-19 22:23:03 +01:00
|
|
|
|
2021-11-27 09:12:05 +01:00
|
|
|
chmod 400 "$final_path/config.inc.php"
|
|
|
|
chown $app:$app "$final_path/config.inc.php"
|
|
|
|
|
2018-02-19 22:23:03 +01:00
|
|
|
#=================================================
|
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.
|
2021-03-17 09:09:35 +01: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
|
|
|
#=================================================
|
2021-03-17 09:09:35 +01: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
|