2015-08-03 11:35:01 +02:00
|
|
|
#!/bin/bash
|
2016-07-10 16:24:09 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-07-10 16:24:09 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
source _common.sh
|
2018-08-10 14:59:24 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-07-11 18:41:22 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2018-08-10 15:55:41 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2020-07-24 12:46:55 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2018-08-10 15:55:41 +02:00
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
|
|
|
timezone=$(cat /etc/timezone)
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2018-08-10 16:36:04 +02:00
|
|
|
final_path=/var/www/$app
|
2022-01-31 08:47:43 +01:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2018-08-10 15:55:41 +02:00
|
|
|
|
|
|
|
# Register (book) web path
|
2020-07-24 12:31:07 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2015-08-12 14:35:47 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2015-08-12 14:35:47 +02:00
|
|
|
|
2020-07-24 12:31:07 +02: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=admin --value=$admin
|
2018-08-10 15:55:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
2018-08-10 17:06:29 +02:00
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Finding an available port..."
|
2018-08-10 17:06:29 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
# Find an available port
|
2020-09-17 08:37:00 +02:00
|
|
|
port=$(ynh_find_port --port=9537)
|
2020-07-24 12:31:07 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
2018-08-12 00:03:51 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
2018-08-12 00:03:51 +02:00
|
|
|
|
|
|
|
# Install packages
|
2021-01-15 13:32:05 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2018-08-12 00:03:51 +02:00
|
|
|
|
2021-08-09 23:58:08 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
2021-08-09 23:58:08 +02:00
|
|
|
|
|
|
|
# Create a system user
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
2021-08-09 23:58:08 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2020-07-24 12:31:07 +02:00
|
|
|
# CREATE A POSTGRESQL DATABASE
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2020-07-24 12:31:07 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
2018-08-12 00:29:57 +02:00
|
|
|
db_user=$db_name
|
2020-07-24 12:31:07 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
ynh_psql_test_if_first_run
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2020-07-24 18:37:29 +02:00
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
|
2020-07-24 18:32:57 +02:00
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2018-08-12 00:03:51 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2020-07-24 12:31:07 +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
|
2020-09-22 19:18:47 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_replace_string --match_string="0.3.5" --replace_string="0.4.1" --target_file="$final_path/composer.json"
|
|
|
|
|
2021-08-09 23:58:08 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2018-08-12 00:03:51 +02:00
|
|
|
# NGINX CONFIGURATION
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2020-09-26 11:47:54 +02:00
|
|
|
# Create a dedicated NGINX config
|
2018-08-12 00:03:51 +02:00
|
|
|
ynh_add_nginx_config
|
2018-08-10 16:36:04 +02:00
|
|
|
|
2018-08-12 00:03:51 +02:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..."
|
2018-08-12 00:03:51 +02:00
|
|
|
|
2020-09-26 11:47:54 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
2020-11-23 23:39:34 +01:00
|
|
|
ynh_add_fpm_config --package="$extra_php_dependencies"
|
2022-01-31 08:47:43 +01:00
|
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
2020-07-24 18:50:37 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Adding a configuration file..."
|
2020-07-24 12:31:07 +02:00
|
|
|
|
2021-02-21 22:20:08 +01:00
|
|
|
ynh_add_config --template="../conf/db.example.inc.php" --destination="$final_path/config/db.inc.php"
|
2018-08-12 00:59:39 +02:00
|
|
|
|
2021-08-09 23:58:08 +02:00
|
|
|
chmod 400 "$final_path/config/db.inc.php"
|
|
|
|
chown $app:$app "$final_path/config/db.inc.php"
|
2018-08-12 00:59:39 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
2020-07-24 12:31:07 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
# Create a dedicated systemd config
|
2018-08-12 00:22:31 +02:00
|
|
|
ynh_add_systemd_config
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2018-08-12 00:59:39 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
# BUILD MOVIM
|
2018-08-12 00:59:39 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Building Movim..."
|
2020-09-17 10:38:35 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path"
|
|
|
|
ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$final_path" --commands="movim:migrate"
|
|
|
|
ynh_exec_as $app php$phpversion $final_path/daemon.php config --username=$admin --password=$password --quiet
|
2020-09-17 18:12:53 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2020-07-24 18:17:18 +02:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2020-07-24 18:17:18 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
yunohost service add $app --description="Responsive web-based XMPP client"
|
2020-07-24 18:17:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2020-07-24 18:17:18 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Movim daemon launched"
|
2020-07-24 18:17:18 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
# Make app public if necessary
|
2020-09-17 19:47:35 +02:00
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2022-01-31 08:47:43 +01:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
2021-02-21 22:20:08 +01:00
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2020-09-17 19:47:35 +02:00
|
|
|
fi
|
2020-09-17 18:12:53 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2020-07-24 17:32:44 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|