2016-08-21 01:03:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-02-17 23:50:49 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_clean_setup () {
|
2021-02-17 23:50:49 +01:00
|
|
|
true
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_abort_if_errors
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
#REMOVEME? path=$YNH_APP_ARG_PATH
|
|
|
|
#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
#REMOVEME? admin=$YNH_APP_ARG_ADMIN
|
2016-08-21 01:03:46 +02:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
2023-01-27 18:12:14 +01:00
|
|
|
fpm_footprint="low"
|
|
|
|
fpm_free_footprint=0
|
|
|
|
fpm_usage="low"
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? install_dir=/var/www/$app
|
|
|
|
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
# Register (book) web path
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=admin --value=$admin
|
2023-01-27 18:12:14 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
|
|
|
|
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint
|
|
|
|
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
2022-07-19 03:18:49 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=1
|
2022-07-19 03:18:49 +02:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
|
2022-07-19 03:18:49 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=2
|
2022-07-19 03:18:49 +02:00
|
|
|
|
|
|
|
# Create a system user
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
|
2022-07-19 03:18:49 +02:00
|
|
|
|
2021-02-17 23:50:49 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Creating a MySQL database..." --weight=1
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
#REMOVEME? db_user=$db_name
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
#REMOVEME? ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2021-03-15 23:14:42 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
|
2021-02-17 23:50:49 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-04-27 09:44:41 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir"
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2021-03-15 23:14:42 +01:00
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..." --weight=1
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
# Create a dedicated PHP-FPM config
|
2023-01-27 18:12:14 +01:00
|
|
|
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2022-07-19 03:18:49 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=4
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2021-02-17 23:50:49 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2021-03-01 09:43:17 +01:00
|
|
|
# SETUP SQL CREDENTIALS
|
2021-02-17 23:50:49 +01:00
|
|
|
#=================================================
|
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
ynh_add_config --template="../conf/common.php" --destination="$install_dir/protected/config/common.php"
|
2021-03-01 09:43:17 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DEACTIVATE DEBUG MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_replace_string --match_string="defined('YII_DEBUG') or define('YII_DEBUG', true);"\
|
|
|
|
--replace_string="// defined('YII_DEBUG') or define('YII_DEBUG', true);"\
|
2023-04-27 09:44:41 +02:00
|
|
|
--target_file="$install_dir/index.php"
|
2021-03-01 09:43:17 +01:00
|
|
|
ynh_replace_string --match_string="defined('YII_ENV') or define('YII_ENV', 'dev');"\
|
|
|
|
--replace_string="// defined('YII_ENV') or define('YII_ENV', 'dev');"\
|
2023-04-27 09:44:41 +02:00
|
|
|
--target_file="$install_dir/index.php"
|
2021-03-01 09:43:17 +01:00
|
|
|
|
2021-02-17 23:50:49 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP APPLICATION WITH CURL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set right permissions for curl install
|
2023-04-27 09:44:41 +02:00
|
|
|
chown -R $app: $install_dir
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
# Set the app as temporarily public for curl call
|
2021-03-15 23:14:42 +01:00
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --weight=30
|
2021-02-17 23:50:49 +01:00
|
|
|
# Making the app public for curl
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
|
2021-02-17 23:50:49 +01:00
|
|
|
# Reload SSOwat config
|
|
|
|
yunohost app ssowatconf
|
|
|
|
|
|
|
|
# Reload NGINX
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
# Installation with curl
|
2021-03-15 23:14:42 +01:00
|
|
|
ynh_script_progression --message="Finalizing installation..." --weight=2
|
2021-03-01 09:43:17 +01:00
|
|
|
|
2022-05-18 15:24:23 +02:00
|
|
|
install_sso
|
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
pushd $install_dir/protected
|
2022-08-30 00:36:35 +02:00
|
|
|
php$phpversion yii migrate/up --includeModuleMigrations=1 --interactive=0
|
|
|
|
|
|
|
|
php$phpversion yii settings/set ldap enabled '1'
|
|
|
|
php$phpversion yii settings/set ldap hostname 'localhost'
|
|
|
|
php$phpversion yii settings/set ldap port 389
|
|
|
|
php$phpversion yii settings/set ldap encryption ''
|
|
|
|
php$phpversion yii settings/set ldap username ''
|
|
|
|
php$phpversion yii settings/set ldap password ''
|
|
|
|
php$phpversion yii settings/set ldap baseDn 'ou=users,dc=yunohost,dc=org'
|
|
|
|
php$phpversion yii settings/set ldap loginFilter '(uid=%s)'
|
|
|
|
php$phpversion yii settings/set ldap userFilter 'objectClass=mailAccount'
|
|
|
|
php$phpversion yii settings/set ldap emailAttribute 'mail'
|
|
|
|
php$phpversion yii settings/set ldap usernameAttribute 'uid'
|
|
|
|
php$phpversion yii settings/set ldap idAttribute 'uid'
|
|
|
|
php$phpversion yii settings/set ldap refreshUsers '1'
|
|
|
|
php$phpversion yii settings/set ldap refreshUsers '1'
|
|
|
|
|
|
|
|
php$phpversion yii ldap/sync
|
|
|
|
php$phpversion yii user/make-admin ${admin}
|
2021-10-25 23:03:08 +02:00
|
|
|
|
|
|
|
ynh_local_curl "/index.php?r=installer/index/go"
|
|
|
|
|
|
|
|
local_curl_csrf "/index.php?r=installer/config/basic" \
|
|
|
|
"ConfigBasicForm[name]=YunoHost"
|
|
|
|
|
|
|
|
local_curl_csrf "/index.php?r=installer/config/use-case" \
|
|
|
|
"UseCaseForm[useCase]=" \
|
|
|
|
"UseCaseForm[useCase]=other"
|
|
|
|
|
|
|
|
local_curl_csrf "/index.php?r=installer/config/sample-data" \
|
|
|
|
"SampleDataForm[sampleData]=0"
|
|
|
|
|
2022-08-30 00:36:35 +02:00
|
|
|
php$phpversion yii settings/set user auth.anonymousRegistration '0'
|
|
|
|
php$phpversion yii settings/set user auth.allowGuestAccess '0'
|
|
|
|
php$phpversion yii settings/set user auth.internalUsersCanInvite '0'
|
2021-10-25 23:03:08 +02:00
|
|
|
|
2022-08-30 00:36:35 +02:00
|
|
|
php$phpversion yii module/enable auth-basic
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2022-05-18 15:24:23 +02:00
|
|
|
popd
|
2022-05-18 14:52:14 +02:00
|
|
|
|
2021-02-17 23:50:49 +01:00
|
|
|
# Remove the public access
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_permission_update --permission="main" --remove="visitors"
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
ynh_store_file_checksum --file="$install_dir/protected/config/common.php"
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2022-08-30 00:36:35 +02:00
|
|
|
|
2021-02-17 23:50:49 +01:00
|
|
|
#=================================================
|
2022-07-19 03:18:49 +02:00
|
|
|
# SETUP CRON CONFIGURATION
|
2021-02-17 23:50:49 +01:00
|
|
|
#=================================================
|
2022-08-30 00:36:35 +02:00
|
|
|
ynh_script_progression --message="Setuping crontab..." --weight=1
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2022-07-19 03:18:49 +02:00
|
|
|
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/${app}"
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-19 03:18:49 +02:00
|
|
|
# GENERIC FINALIZATION
|
2021-02-17 23:50:49 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=2
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
# Make app public if necessary
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? if [ $is_public -eq 1 ]
|
2021-02-17 23:50:49 +01:00
|
|
|
then
|
2022-07-19 03:18:49 +02:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
|
2021-02-17 23:50:49 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
2021-02-17 23:50:49 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
|
2021-02-17 23:50:49 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|