1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/flarum_ynh.git synced 2024-09-03 18:36:24 +02:00
flarum_ynh/scripts/install

279 lines
10 KiB
Text
Raw Normal View History

2016-10-05 19:44:08 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_add_extra_apt_repos__3
source ynh_install_php__3
2019-08-24 12:54:18 +02:00
source ynh_exec_as
source ynh_composer__2
source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2016-10-05 19:44:08 +02: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
# Retrieve arguments
2016-10-05 19:44:08 +02:00
domain=$YNH_APP_ARG_DOMAIN
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
#===================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#===================================================
2016-10-05 19:44:08 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#===================================================
# STORE SETTINGS FROM MANIFEST
#===================================================
2016-10-05 19:44:08 +02:00
# Save app settings
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
2018-02-18 14:38:26 +01:00
ynh_app_setting_set $app language $language
ynh_app_setting_set $app final_path $final_path
2019-08-24 12:54:18 +02:00
ynh_app_setting_set $app php_version $php_version
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
2019-08-24 12:54:18 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --time --weight=1
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
### Those deb packages will be installed as dependencies of this package.
### If you're not using this helper:
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
### - Remove the variable "pkg_dependencies" in _common.sh
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
ynh_install_php --phpversion=7.3 --package="$pkg_dependencies"
2019-08-24 12:54:18 +02:00
#===================================================
# CREATE DEDICATED USER
#===================================================
2019-08-24 12:54:18 +02:00
ynh_system_user_create $app $final_path 1
usermod -a -G www-data $app
# Create working directory
mkdir -p "$final_path/.composer"
chown -R $app:www-data $final_path
chmod -R 0775 $final_path
#=================================================
# COMPOSER INSTALLATION
#=================================================
2019-08-24 12:54:18 +02:00
ynh_script_progression --message="Installing Composer..." --time --weight=1
ynh_install_composer $php_version $final_path
#=================================================
# FLARUM INSTALLATION
#=================================================
# Prepare Flarum temp directory
tmp=/tmp/$app
mkdir -p $tmp
chown -R $app:www-data $tmp
chmod -R 0775 $tmp
# Install Flarum
2019-08-24 12:54:18 +02:00
ynh_script_progression --message="Composer is installing Flarum and its dependencies (may take a while)..." --time --weight=3
# First, create the project with core and all basic extensions
2019-08-24 12:54:18 +02:00
ynh_composer_exec $app $php_version $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp"
# Copy Flarum to working directory and clean temp directory
cp -Rf $tmp/* $final_path
ynh_secure_remove $tmp
2019-08-24 12:54:18 +02:00
# Set right permissions for the post-installation
chown -R $app: $final_path
chown -R $app:www-data $final_path/storage
chmod -R 0775 $final_path
#=================================================
# 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"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
if [ $path_url = "/" ]; then
2019-08-24 12:54:18 +02:00
ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
else
2019-08-24 12:54:18 +02:00
ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
fi
2019-08-24 12:54:18 +02:00
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
2019-08-24 12:54:18 +02:00
ynh_add_fpm_config $php_version
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate
#=================================================
# SETUP SSOWAT
#=================================================
2016-10-05 19:44:08 +02:00
if [ $is_public -eq 0 ]
then # Remove the public access
2018-02-14 10:48:34 +01:00
ynh_app_setting_delete $app skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
then
2018-02-14 10:48:34 +01:00
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
2016-10-05 19:44:08 +02:00
fi
#=================================================
# RELOAD NGINX
#=================================================
2016-10-08 19:08:37 +02:00
systemctl reload nginx
#=================================================
# FLARUM POST-INSTALL
#=================================================
2019-08-24 12:54:18 +02:00
ynh_script_progression --message="Configuring Flarum..." --time --weight=2
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
chown $app:www-data $finalflarumconf
# 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
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
2018-08-30 20:35:01 +02:00
# Install and activate the SSOwat auth extension
2019-08-24 12:54:18 +02:00
ynh_script_progression --message="Installing SSOwat extension..." --time --weight=2
install_and_activate_extension $app $php_version $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
2018-08-30 20:35:01 +02:00
# Configure SSOwat auth extension
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
ynh_print_info "SSOwat extension has been installed."
2018-08-30 20:35:01 +02:00
# 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
install_and_activate_extension $app $php_version $final_path $db_name "milescellar/flarum-ext-french" "milescellar-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
install_and_activate_extension $app $php_version $final_path $db_name "cbmainz/flarum-de" "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
ynh_composer_exec $app $php_version $final_path "require flagrow/bazaar --ansi"
fi
2018-08-30 20:35:01 +02:00
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"
ynh_print_warn "$app_message"