2017-02-13 22:47:30 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
source _common.sh
|
2017-02-13 22:47:30 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
2017-10-23 12:38:35 +02:00
|
|
|
ynh_abort_if_errors
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2022-03-09 03:00:02 +01:00
|
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
|
|
|
admin_lastname=$(ynh_user_get_info $admin lastname)
|
|
|
|
admin_firstname=$(ynh_user_get_info $admin firstname)
|
|
|
|
admin_mail=$(ynh_user_get_info $admin mail)
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2017-10-23 12:38:35 +02:00
|
|
|
|
|
|
|
final_path=/var/www/$app
|
2022-03-09 03:00:02 +01:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2017-10-23 12:38:35 +02:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-10-23 12:38:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2017-10-23 12:38:35 +02:00
|
|
|
|
2022-03-09 03:00:02 +01: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=language --value=$language
|
|
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a MySQL database..."
|
|
|
|
|
|
|
|
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
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
2017-10-23 12:38:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2017-10-23 12:38:35 +02:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
# Create a dedicated NGINX config
|
2017-10-23 12:38:35 +02:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2017-10-23 12:44:46 +02:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..."
|
2017-10-23 12:44:46 +02:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
# Create a dedicated PHP-FPM config
|
2017-10-23 12:44:46 +02:00
|
|
|
ynh_add_fpm_config
|
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# SETUP APPLICATION WITH CURL
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Setuping application with CURL..."
|
2017-10-23 12:38:35 +02:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
# Set the app as temporarily public for curl call
|
|
|
|
ynh_script_progression --message="Configuring SSOwat..."
|
|
|
|
# Making the app public for curl
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2017-10-23 12:38:35 +02:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
# Installation with curl
|
|
|
|
ynh_script_progression --message="Finalizing installation..."
|
|
|
|
ynh_local_curl "/?ctrl=offline&action=install&disconnect=1" "lang=$language" "db_host=localhost" "db_name=$db_name" "db_login=$db_user" "db_password=$db_pwd" "adminName=$admin_lastname" "adminFirstName=$admin_firstname" "adminLogin=$admin" "adminPassword=$password" "adminPasswordVerif=$password" "adminMail=$admin_mail" "spaceName=YunoHost" "spaceDescription=YunoHost" "spacePublic=0" "ctrl=offline" "action=install" "formValidate=1" "submit=submit"
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
# Remove the public access
|
|
|
|
ynh_permission_update --permission="main" --remove="visitors"
|
2017-02-13 22:47:30 +01:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2017-10-23 12:38:35 +02:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
# Make app public if necessary
|
2017-10-23 12:38:35 +02:00
|
|
|
if [ $is_public -eq 1 ]
|
2017-02-13 22:47:30 +01:00
|
|
|
then
|
2022-03-09 03:00:02 +01:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2017-02-13 22:47:30 +01:00
|
|
|
fi
|
|
|
|
|
2017-10-23 12:38:35 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-10-23 12:38:35 +02:00
|
|
|
|
2022-03-09 03:00:02 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|