2016-10-05 19:44:08 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC START
|
|
|
|
|
#=================================================
|
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
source _common.sh
|
2020-04-21 00:00:02 +02:00
|
|
|
|
source experimental_helpers/_ynh_add_extra_apt_repos
|
|
|
|
|
source experimental_helpers/ynh_install_php
|
2020-03-14 21:22:54 +01:00
|
|
|
|
source experimental_helpers/ynh_exec_as
|
2020-04-21 00:00:02 +02:00
|
|
|
|
source experimental_helpers/ynh_composer
|
|
|
|
|
source experimental_helpers/ynh_send_readme_to_admin
|
2020-05-17 14:56:21 +02:00
|
|
|
|
source experimental_helpers/hardware
|
|
|
|
|
source experimental_helpers/ynh_add_swap
|
2020-04-21 00:00:02 +02:00
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-02-22 15:47:46 +01:00
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2020-04-19 20:01:48 +02:00
|
|
|
|
ynh_clean_setup () {
|
2020-05-17 14:56:21 +02:00
|
|
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
|
|
|
true
|
2020-04-19 20:01:48 +02:00
|
|
|
|
}
|
2018-02-12 16:07:11 +01:00
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
|
ynh_abort_if_errors
|
2016-10-05 19:44:08 +02:00
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
#===================================================
|
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
|
#===================================================
|
|
|
|
|
|
2016-10-05 19:44:08 +02: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
|
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
# Retrieve arguments
|
2018-02-12 16:07:11 +01:00
|
|
|
|
|
2016-10-05 19:44:08 +02:00
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2018-02-12 16:07:11 +01:00
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2016-10-05 19:44:08 +02:00
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2016-10-08 20:12:31 +02:00
|
|
|
|
title=$YNH_APP_ARG_TITLE
|
2016-10-05 19:44:08 +02:00
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2018-02-18 14:38:26 +01:00
|
|
|
|
language=$YNH_APP_ARG_LANGUAGE
|
2018-08-13 16:15:41 +02:00
|
|
|
|
bazaar_extension=$YNH_APP_ARG_BAZAAR_EXTENSION
|
2016-10-05 19:44:08 +02:00
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
#===================================================
|
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
|
#===================================================
|
2016-10-05 19:44:08 +02:00
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
final_path=/var/www/$app
|
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
2017-02-22 15:47:46 +01:00
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
# Normalize the url path syntax
|
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
2017-02-22 15:47:46 +01:00
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
# Check web path availability
|
|
|
|
|
ynh_webpath_available $domain $path_url
|
2017-02-22 15:47:46 +01:00
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
# Register (book) web path
|
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
|
|
|
|
|
2020-05-17 14:56:21 +02:00
|
|
|
|
#===================================================
|
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH CURRENT RAM
|
|
|
|
|
#===================================================
|
|
|
|
|
ynh_script_progression --message="Ensuring sufficient memory..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
# Check RAM
|
|
|
|
|
if [[ $(ynh_get_ram --free) < 1000 ]]; then
|
|
|
|
|
ynh_add_swap --size=1000
|
|
|
|
|
fi
|
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
#===================================================
|
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
|
#===================================================
|
2017-02-22 15:47:46 +01:00
|
|
|
|
|
2016-10-05 19:44:08 +02:00
|
|
|
|
# Save app settings
|
2018-02-12 16:07:11 +01:00
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
|
ynh_app_setting_set $app path $path_url
|
2018-02-12 21:53:49 +01:00
|
|
|
|
ynh_app_setting_set $app admin $admin
|
2018-02-18 14:38:26 +01:00
|
|
|
|
ynh_app_setting_set $app language $language
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_app_setting_set $app php_version $php_version
|
2018-12-03 23:07:40 +01:00
|
|
|
|
ynh_app_setting_set $app project_version $project_version
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_app_setting_set $app core_version $core_version
|
|
|
|
|
ynh_app_setting_set $app ssowat_version $ssowat_version
|
2018-08-13 16:47:43 +02:00
|
|
|
|
ynh_app_setting_set $app bazaar_extension $bazaar_extension
|
2018-02-12 16:07:11 +01:00
|
|
|
|
|
2019-08-24 12:54:18 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
|
#=================================================
|
2020-04-06 10:54:13 +02:00
|
|
|
|
# INSTALL PHP
|
2019-08-24 12:54:18 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
|
2020-04-06 10:54:13 +02:00
|
|
|
|
if [ "$(lsb_release --codename --short)" = "buster" ]; then
|
2020-05-17 14:56:21 +02:00
|
|
|
|
pkg_dependencies="$pkg_dependencies $extra_pkg_dependencies"
|
2020-04-06 10:54:13 +02:00
|
|
|
|
else
|
2020-05-17 14:56:21 +02:00
|
|
|
|
ynh_script_progression --message="Installing php${php_version}..." --time --weight=1
|
|
|
|
|
ynh_install_php --phpversion="${php_version}" --package="$extra_pkg_dependencies"
|
2020-04-06 10:54:13 +02:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
|
#=================================================
|
2020-04-21 09:07:21 +02:00
|
|
|
|
ynh_script_progression --message="Installing dependencies..." --time --weight=1
|
2019-08-24 12:54:18 +02:00
|
|
|
|
|
2020-04-21 00:00:02 +02:00
|
|
|
|
_ynh_install_app_dependencies "$pkg_dependencies"
|
2019-08-24 12:54:18 +02:00
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
|
ynh_app_setting_set $app db_name $db_name
|
|
|
|
|
ynh_mysql_setup_db $db_name $db_name
|
|
|
|
|
ynh_app_setting_set "$app" db_pwd "$db_pwd"
|
|
|
|
|
|
2020-04-19 20:01:48 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
|
#=================================================
|
2020-05-17 14:56:21 +02:00
|
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=7
|
2020-04-19 20:01:48 +02: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"
|
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
|
2018-02-12 16:07:11 +01:00
|
|
|
|
if [ $path_url = "/" ]; then
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
|
2017-03-05 19:56:26 +01:00
|
|
|
|
else
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
|
2017-03-05 19:56:26 +01:00
|
|
|
|
fi
|
2019-08-24 12:54:18 +02:00
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
|
ynh_add_nginx_config
|
2018-02-12 16:07:11 +01:00
|
|
|
|
|
2020-04-19 20:01:48 +02:00
|
|
|
|
#===================================================
|
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
|
#===================================================
|
|
|
|
|
ynh_script_progression --message="Configuring system user..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
|
ynh_system_user_create $app $final_path
|
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
# Create a dedicated php-fpm config
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_add_fpm_config $php_version
|
2018-02-12 21:53:49 +01:00
|
|
|
|
|
2020-04-19 20:01:48 +02:00
|
|
|
|
#=================================================
|
2020-05-17 14:56:21 +02:00
|
|
|
|
# INSTALL AND INITIALIZE COMPOSER
|
2020-04-19 20:01:48 +02:00
|
|
|
|
#=================================================
|
2020-05-17 14:56:21 +02:00
|
|
|
|
ynh_script_progression --message="Installing Flarum with Composer..." --time --weight=1
|
2020-04-19 20:01:48 +02:00
|
|
|
|
|
2020-05-17 14:56:21 +02:00
|
|
|
|
# Create composer directory and making sure it is writable
|
|
|
|
|
mkdir -p "$final_path/.composer"
|
2020-04-21 00:00:02 +02:00
|
|
|
|
chown -R $app: $final_path
|
2020-04-19 20:01:48 +02:00
|
|
|
|
|
2020-05-17 14:56:21 +02:00
|
|
|
|
# Installing composer
|
2020-04-19 20:01:48 +02:00
|
|
|
|
ynh_install_composer --user=$app --phpversion=$php_version --workdir=$final_path
|
|
|
|
|
|
2020-05-17 14:56:21 +02:00
|
|
|
|
# Set Flarum version
|
|
|
|
|
ynh_composer_exec --user=$app --phpversion=$php_version --workdir=$final_path \
|
|
|
|
|
--commands="require flarum/core:$core_version --prefer-lowest --no-update"
|
2020-04-21 00:00:02 +02:00
|
|
|
|
|
2020-05-17 14:56:21 +02:00
|
|
|
|
# Require SSOwat extension
|
|
|
|
|
ynh_composer_exec --user=$app --phpversion=$php_version --workdir=$final_path \
|
|
|
|
|
--commands="require tituspijean/flarum-ext-auth-ssowat:$ssowat_version --no-update"
|
2020-04-21 00:00:02 +02:00
|
|
|
|
|
2020-05-17 14:56:21 +02:00
|
|
|
|
# Update and download dependencies
|
|
|
|
|
ynh_composer_exec --user=$app --phpversion=$php_version --workdir=$final_path \
|
|
|
|
|
--commands="update"
|
2020-04-21 00:00:02 +02:00
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
|
ynh_use_logrotate
|
2017-03-05 19:56:26 +01:00
|
|
|
|
|
2018-02-12 16:07:11 +01:00
|
|
|
|
#=================================================
|
2020-03-27 20:21:46 +01:00
|
|
|
|
# SETUP PERMISSIONS
|
2018-02-12 16:07:11 +01:00
|
|
|
|
#=================================================
|
2020-03-27 20:21:46 +01:00
|
|
|
|
ynh_script_progression --message="Configuring permissions..." --time --weight=1
|
2016-10-05 19:44:08 +02:00
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
# Make app public if necessary
|
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
|
then
|
2020-05-17 14:56:21 +02:00
|
|
|
|
# Everyone can access the app.
|
|
|
|
|
# The "main" permission is automatically created before the install script.
|
|
|
|
|
ynh_permission_update --permission "main" --add "visitors"
|
2016-10-05 19:44:08 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# RELOAD NGINX
|
|
|
|
|
#=================================================
|
2016-10-08 19:08:37 +02:00
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
systemctl reload nginx
|
2018-02-12 16:07:11 +01:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# FLARUM POST-INSTALL
|
|
|
|
|
#=================================================
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_script_progression --message="Configuring Flarum..." --time --weight=2
|
2017-02-21 21:11:23 +01:00
|
|
|
|
|
2018-08-30 20:35:01 +02:00
|
|
|
|
# Copy the configuration.yml to working directory
|
|
|
|
|
finalflarumconf="$final_path/configuration.yml"
|
|
|
|
|
cp ../conf/configuration.yml $finalflarumconf
|
2020-05-17 14:56:21 +02:00
|
|
|
|
chown $app: $finalflarumconf
|
2018-08-30 20:35:01 +02:00
|
|
|
|
# Generate admin password and retrieve their email address
|
|
|
|
|
admin_pwd=$(ynh_string_random 8)
|
|
|
|
|
admin_mail=$(ynh_user_get_info $admin mail)
|
|
|
|
|
# Populate configuration.yml
|
2018-08-30 20:59:31 +02:00
|
|
|
|
ynh_replace_string "__DOMAIN__" "$domain" "$finalflarumconf"
|
|
|
|
|
ynh_replace_string "/__PATH__" "$path_url" "$finalflarumconf"
|
|
|
|
|
ynh_replace_string "__USER__" "$app" "$finalflarumconf"
|
|
|
|
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$finalflarumconf"
|
|
|
|
|
ynh_replace_string "__ADMIN__" "$admin" "$finalflarumconf"
|
|
|
|
|
ynh_replace_string "__ADMIN_PWD__" "$admin_pwd" "$finalflarumconf"
|
|
|
|
|
ynh_replace_string "__ADMIN_EML__" "$admin_mail" "$finalflarumconf"
|
|
|
|
|
ynh_replace_string "__FORUM_TITLE__" "$title" "$finalflarumconf"
|
2018-08-30 20:35:01 +02:00
|
|
|
|
# Execute post-installation
|
|
|
|
|
pushd $final_path
|
2019-08-24 12:54:18 +02:00
|
|
|
|
exec_as $app php$php_version -d $final_path -d memory_limit=-1 flarum install -f configuration.yml
|
|
|
|
|
# Delete configuration.yml as it contains sensitive data
|
|
|
|
|
ynh_secure_remove $finalflarumconf
|
2018-08-30 20:35:01 +02:00
|
|
|
|
popd
|
|
|
|
|
|
|
|
|
|
# Email setup
|
|
|
|
|
sql_command="REPLACE INTO \`settings\` (\`key\`, \`value\`) VALUES
|
|
|
|
|
('mail_driver', 'mail'),
|
|
|
|
|
('mail_encryption', 'ssl'),
|
|
|
|
|
('mail_from', '$app@$domain'),
|
|
|
|
|
('mail_host', 'localhost'),
|
|
|
|
|
('mail_port', '587');"
|
|
|
|
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
2019-08-24 12:54:18 +02:00
|
|
|
|
|
2020-05-17 14:56:21 +02:00
|
|
|
|
# Enable and set up the SSOwat auth extension
|
|
|
|
|
ynh_script_progression --message="Enabling and configuring SSOwat extension..." --time --weight=2
|
|
|
|
|
activate_flarum_extension $db_name "tituspijean-auth-ssowat"
|
2018-08-30 20:35:01 +02:00
|
|
|
|
ssowatdomain=$(</etc/yunohost/current_host)
|
|
|
|
|
sql_command="INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('tituspijean-auth-ssowat.domain', '$ssowatdomain'), ('tituspijean-auth-ssowat.onlyUse', '0');"
|
|
|
|
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
|
|
|
|
|
|
|
|
|
# Install, activate and set language extensions
|
|
|
|
|
case $language in
|
|
|
|
|
fr)
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_script_progression --message="Installing French extension..." --time --weight=2
|
2020-05-17 14:56:21 +02:00
|
|
|
|
ynh_composer_exec --user=$app --phpversion=$php_version --workdir=$final_path --commands="require milescellar/lang-french"
|
|
|
|
|
activate_flarum_extension $db_name "milescellar-lang-french"
|
2018-08-30 20:35:01 +02:00
|
|
|
|
sql_command="UPDATE \`settings\` SET \`value\` = 'fr' WHERE \`settings\`.\`key\` = 'default_locale'"
|
|
|
|
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
|
|
|
|
;;
|
|
|
|
|
de)
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_script_progression --message="Installing German extension..." --time --weight=2
|
2020-05-17 14:56:21 +02:00
|
|
|
|
ynh_composer_exec --user=$app --phpversion=$php_version --workdir=$final_path --commands="require cbmainz/flarum-de"
|
|
|
|
|
activate_flarum_extension $db_name "cbmainz-de"
|
2018-08-30 20:35:01 +02:00
|
|
|
|
sql_command="UPDATE \`settings\` SET \`value\` = 'de' WHERE \`settings\`.\`key\` = 'default_locale'"
|
|
|
|
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
|
|
|
|
;;
|
2018-09-11 12:11:39 +02:00
|
|
|
|
esac
|
2018-08-30 20:35:01 +02:00
|
|
|
|
|
2018-09-11 12:11:01 +02:00
|
|
|
|
if [ $bazaar_extension -eq 1 ]; then
|
2019-08-24 12:54:18 +02:00
|
|
|
|
ynh_script_progression --message="Installing Bazaar extension..." --time --weight=2
|
2020-05-17 14:56:21 +02:00
|
|
|
|
ynh_composer_exec --user=$app --phpversion=$php_version --workdir=$final_path --commands="require extiverse/bazaar"
|
2017-02-27 19:06:31 +01:00
|
|
|
|
fi
|
2018-08-30 20:35:01 +02:00
|
|
|
|
|
2020-05-17 14:56:21 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
### For security reason, any app should set the permissions to root: before anything else.
|
|
|
|
|
### Then, if write authorization is needed, any access should be given only to directories
|
|
|
|
|
### that really need such authorization.
|
|
|
|
|
|
|
|
|
|
# Set right permissions
|
|
|
|
|
chown -R $app:www-data $final_path
|
|
|
|
|
|
2019-08-24 12:54:18 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# SEND CREDENTIALS TO ADMIN
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
ynh_script_progression --message="Sending generated admin credentials by email, but you can log in with your YunoHost credentials!" --time --weight=1
|
2018-08-30 20:35:01 +02:00
|
|
|
|
app_message="User : $admin, password : $admin_pwd
|
|
|
|
|
Change your password!
|
|
|
|
|
Your forum is accessible at https://$domain$path_url"
|
|
|
|
|
ynh_send_readme_to_admin "$app_message" "$admin"
|
2018-09-17 22:06:03 +02:00
|
|
|
|
ynh_print_warn "$app_message"
|