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
|
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-02-22 15:47:46 +01:00
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
|
#=================================================
|
|
|
|
|
|
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-12 16:07:11 +01:00
|
|
|
|
flarum_version="v0.1.0-beta.7"
|
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
|
|
|
|
|
|
|
|
|
|
#===================================================
|
|
|
|
|
# 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
|
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2018-02-12 16:07:11 +01:00
|
|
|
|
|
|
|
|
|
#===================================================
|
2018-02-12 21:53:49 +01:00
|
|
|
|
# CREATE DEDICATED USER
|
2018-02-12 16:07:11 +01:00
|
|
|
|
#===================================================
|
|
|
|
|
|
2018-02-15 18:37:46 +01:00
|
|
|
|
ynh_system_user_create $app $final_path
|
2018-02-12 16:07:11 +01:00
|
|
|
|
sudo usermod -a -G www-data $app
|
2018-02-15 18:37:46 +01:00
|
|
|
|
# Create working directory
|
|
|
|
|
sudo mkdir -p "$final_path/.composer"
|
|
|
|
|
sudo chown -R $app:www-data $final_path
|
|
|
|
|
sudo chmod -R 0775 $final_path
|
2018-02-12 16:07:11 +01:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# COMPOSER INSTALLATION
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2018-02-15 18:37:46 +01:00
|
|
|
|
init_composer $app $final_path
|
2018-02-12 16:07:11 +01:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# FLARUM INSTALLATION
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
# Prepare Flarum temp directory
|
|
|
|
|
tmp=/tmp/$app
|
|
|
|
|
sudo mkdir -p $tmp
|
|
|
|
|
sudo chown -R $app:www-data $tmp
|
|
|
|
|
sudo chmod -R 0775 $tmp
|
|
|
|
|
|
|
|
|
|
# Install Flarum
|
2018-02-15 18:37:46 +01:00
|
|
|
|
exec_composer $app $final_path "create-project flarum/flarum $tmp $flarum_version --stability=beta --ansi"
|
2018-02-12 16:07:11 +01:00
|
|
|
|
|
2018-02-15 18:37:46 +01:00
|
|
|
|
# Copy Flarum to working directory and clean temp directory
|
2018-02-12 16:07:11 +01:00
|
|
|
|
sudo cp -Rf $tmp/* $final_path
|
|
|
|
|
sudo chown -R $app:www-data $final_path
|
2018-02-15 18:37:46 +01:00
|
|
|
|
sudo chmod -R 0775 $final_path
|
|
|
|
|
ynh_secure_remove $tmp
|
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"
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# 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
|
2018-02-15 18:37:46 +01:00
|
|
|
|
sed -i "s@__LOCATION_HACK__@@g" ../conf/nginx.conf
|
|
|
|
|
sed -i "s@__PATH_HACK__@/@g" ../conf/nginx.conf
|
2017-03-05 19:56:26 +01:00
|
|
|
|
else
|
2018-02-15 18:37:46 +01:00
|
|
|
|
sed -i "s@__LOCATION_HACK__@$path_url@g" ../conf/nginx.conf
|
|
|
|
|
sed -i "s@__PATH_HACK__@$path_url$path_url@g" ../conf/nginx.conf
|
2017-03-05 19:56:26 +01:00
|
|
|
|
fi
|
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
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2018-02-12 21:53:49 +01:00
|
|
|
|
# Create a dedicated php-fpm config
|
|
|
|
|
ynh_add_fpm_config
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SSOWAT
|
|
|
|
|
#=================================================
|
2016-10-05 19:44:08 +02:00
|
|
|
|
|
2018-02-12 21:53:49 +01: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
|
2018-02-12 21:53:49 +01:00
|
|
|
|
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
|
|
|
|
|
|
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
|
|
|
|
|
#=================================================
|
2017-02-21 21:11:23 +01:00
|
|
|
|
|
|
|
|
|
if [[ -n $admin && -n $title ]]; then
|
2018-02-15 18:37:46 +01:00
|
|
|
|
# If admin user and title were specified, start post-installation
|
|
|
|
|
# Copy the configuration.yml to working directory
|
2018-02-14 10:48:34 +01:00
|
|
|
|
finalflarumconf="$final_path/configuration.yml"
|
2018-02-15 18:37:46 +01:00
|
|
|
|
cp ../conf/configuration.yml $finalflarumconf
|
|
|
|
|
# Generate admin password and retrieve their email address
|
2018-02-14 10:48:34 +01:00
|
|
|
|
admin_pwd=$(ynh_string_random 8)
|
|
|
|
|
admin_mail=$(ynh_user_get_info $admin mail)
|
2018-02-15 18:37:46 +01:00
|
|
|
|
# Populate configuration.yml
|
|
|
|
|
sed -i "s@__DOMAIN__@$domain@g" $finalflarumconf
|
|
|
|
|
sed -i "s@/__PATH__@$path_url@g" $finalflarumconf
|
|
|
|
|
sed -i "s@__USER__@$app@g" $finalflarumconf
|
|
|
|
|
sed -i "s@__DB_PWD__@$db_pwd@g" $finalflarumconf
|
|
|
|
|
sed -i "s@__ADMIN__@$admin@g" $finalflarumconf
|
|
|
|
|
sed -i "s@__ADMIN_PWD__@$admin_pwd@g" $finalflarumconf
|
|
|
|
|
sed -i "s%__ADMIN_EML__%$admin_mail%g" $finalflarumconf
|
|
|
|
|
sed -i "s@__FORUM_TITLE__@$title@g" $finalflarumconf
|
|
|
|
|
# Execute post-installation
|
|
|
|
|
cd $final_path
|
|
|
|
|
exec_as $app "php -d memory_limit=-1 flarum install -f configuration.yml"
|
|
|
|
|
# Delete configuration.yml as it sensitive data
|
2018-02-14 11:11:55 +01:00
|
|
|
|
ynh_secure_remove $finalflarumconf
|
2018-02-14 10:48:34 +01:00
|
|
|
|
|
2018-02-15 19:53:58 +01:00
|
|
|
|
# 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
|
|
|
|
|
|
2018-02-14 10:48:34 +01:00
|
|
|
|
# Install the SSOwat auth extension
|
2018-02-15 18:37:46 +01:00
|
|
|
|
exec_composer $app $final_path "require tituspijean/flarum-ext-auth-ssowat:*@dev --ansi"
|
2018-02-14 10:48:34 +01:00
|
|
|
|
|
|
|
|
|
# Configure SSOwat auth extension
|
2018-02-14 18:44:46 +01:00
|
|
|
|
ssowatdomain=$(</etc/yunohost/current_host)
|
|
|
|
|
sql_command="INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('flarum-ext-auth-ssowat.address', '$ssowatdomain'), ('flarum-ext-auth-ssowat.onlyUse', '0');"
|
|
|
|
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
|
|
|
|
|
|
|
|
|
# Enable SSOwat auth extension
|
2018-02-15 18:37:46 +01:00
|
|
|
|
# Retrieve current enabled extensions
|
2018-02-14 18:44:46 +01:00
|
|
|
|
sql_command="SELECT \`value\` FROM settings WHERE \`key\` = 'extensions_enabled'"
|
|
|
|
|
old_extensions_enabled=$(ynh_mysql_execute_as_root "$sql_command" $db_name | tail -1)
|
2018-02-15 18:37:46 +01:00
|
|
|
|
# Append the extension name at the end of the list
|
2018-02-14 18:44:46 +01:00
|
|
|
|
addition=",\"tituspijean-auth-ssowat\"]"
|
|
|
|
|
new_extensions_enabled=${old_extensions_enabled::-1}$addition
|
|
|
|
|
sql_command="UPDATE \`settings\` SET \`value\`='$new_extensions_enabled' WHERE \`key\`='extensions_enabled';"
|
|
|
|
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
|
|
|
|
|
2018-02-15 18:37:46 +01:00
|
|
|
|
# Send login credentials to admin
|
2018-02-14 10:48:34 +01:00
|
|
|
|
app_message="User : $admin, password : $admin_pwd
|
|
|
|
|
Change your password!
|
2018-02-14 18:44:46 +01:00
|
|
|
|
Your forum is accessible at https://$domain$path_url"
|
2018-02-14 10:48:34 +01:00
|
|
|
|
>&2 echo $app_message
|
|
|
|
|
ynh_send_readme_to_admin "$app_message" "$admin"
|
2018-02-12 16:07:11 +01:00
|
|
|
|
else
|
2018-02-15 18:37:46 +01:00
|
|
|
|
# If admin user and title were not specified, ask admin to perform manual post-installation
|
2018-02-14 10:48:34 +01:00
|
|
|
|
app_message="Post-installation required, visit your Flarum instance."
|
|
|
|
|
>&2 echo $app_message
|
|
|
|
|
ynh_send_readme_to_admin "$app_message" "$admin"
|
2017-02-27 19:06:31 +01:00
|
|
|
|
fi
|