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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# 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
|
|
|
|
#=================================================
|
2020-07-24 12:31:07 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2018-08-10 16:36:04 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "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
|
|
|
|
#=================================================
|
2020-07-24 12:31:07 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=2
|
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
|
|
|
|
#=================================================
|
2021-01-15 13:32:05 +01:00
|
|
|
ynh_script_progression --message="Finding an available port..." --weight=2
|
2018-08-10 17:06:29 +02:00
|
|
|
|
|
|
|
# Find a free 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
|
|
|
|
#=================================================
|
2020-09-17 08:37:00 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=1
|
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
|
|
|
|
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
|
|
|
#=================================================
|
2020-07-24 12:31:07 +02:00
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
|
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
|
2021-02-21 22:20:08 +01:00
|
|
|
ynh_psql_setup_db --db_user=$db_name --db_name=$db_name
|
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
|
|
|
#=================================================
|
2020-09-17 08:37:00 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=4
|
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
|
|
|
|
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
|
|
|
#=================================================
|
2020-09-17 08:37:00 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=11
|
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
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-09-17 08:37:00 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=3
|
2018-08-12 00:03:51 +02:00
|
|
|
|
2018-08-12 00:10:46 +02:00
|
|
|
# Create a system user
|
2020-07-24 12:31:07 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2018-08-12 00:03:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2020-09-17 08:37:00 +02:00
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..." --weight=1
|
2018-08-12 00:03:51 +02:00
|
|
|
|
2020-09-26 11:47:54 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
2020-09-26 12:17:55 +02:00
|
|
|
ynh_replace_string --match_string="__TIMEZONE__" --replace_string="$timezone" --target_file=../conf/php-fpm.conf
|
2020-09-17 19:35:57 +02:00
|
|
|
|
2020-11-23 23:39:34 +01:00
|
|
|
ynh_add_fpm_config --package="$extra_php_dependencies"
|
2020-09-17 09:02:08 +02: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
|
|
|
#=================================================
|
|
|
|
# SET CONFIGURATION FILE
|
|
|
|
#=================================================
|
2020-09-17 08:37:00 +02:00
|
|
|
ynh_script_progression --message="Modifying a config file..." --weight=1
|
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
|
|
|
|
2020-07-24 12:31:07 +02:00
|
|
|
ynh_store_file_checksum --file="$final_path/config/db.inc.php"
|
2018-08-12 00:59:39 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2016-07-10 17:34:37 +02:00
|
|
|
# Install PHP dependencies using composer
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2021-02-21 22:20:08 +01:00
|
|
|
ynh_script_progression --message="Configuring Composer..." --weight=1
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2021-05-15 08:28:00 +02:00
|
|
|
ynh_install_composer
|
2020-07-24 17:54:48 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2021-02-21 22:20:08 +01:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=12
|
2020-07-24 12:31:07 +02:00
|
|
|
|
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
|
|
|
#=================================================
|
2021-05-15 08:28:00 +02:00
|
|
|
# SET-UP DATABASE AND CONFIGURATION
|
2018-08-12 00:59:39 +02:00
|
|
|
#=================================================
|
2021-05-15 08:28:00 +02:00
|
|
|
ynh_script_progression --message="Configuring Movim..." --weight=1
|
2020-09-17 10:38:35 +02:00
|
|
|
|
2020-09-17 18:12:53 +02:00
|
|
|
# Create cachedir folder
|
2021-05-15 08:28:00 +02:00
|
|
|
cache_dir="/home/yunohost.app/$app"
|
2020-09-17 10:38:35 +02:00
|
|
|
mkdir -p $cache_dir
|
|
|
|
chown -R $app $cache_dir
|
|
|
|
|
2021-01-15 13:32:05 +01:00
|
|
|
pushd $final_path
|
2021-02-21 22:20:08 +01:00
|
|
|
php$phpversion composer.phar $app:migrate --quiet
|
|
|
|
php$phpversion daemon.php config --username=$admin --password=$password --quiet
|
2021-01-15 13:32:05 +01:00
|
|
|
popd
|
2020-09-17 18:12:53 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2018-08-12 00:59:39 +02:00
|
|
|
# SET PERMISSIONS
|
|
|
|
#=================================================
|
|
|
|
|
2021-05-15 08:28:00 +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
|
|
|
|
2020-07-24 18:17:18 +02:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2020-09-17 08:37:00 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2020-07-24 18:17:18 +02:00
|
|
|
|
2021-01-15 13:32:05 +01:00
|
|
|
yunohost service add $app --description="Responsive web-based XMPP client" --log="/var/log/$app/$app.log"
|
2020-07-24 18:17:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=2
|
|
|
|
|
|
|
|
# Start a systemd service
|
2021-01-15 13:32:05 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action=start --log_path="systemd" #--line_match="HTTP Server listening"
|
2020-07-24 18:17:18 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-02-21 22:20:08 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2020-09-17 19:47:35 +02:00
|
|
|
# Make app public if necessary or protect it
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
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
|
|
|
|
#=================================================
|
2020-09-17 08:37:00 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
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
|
|
|
|
#=================================================
|
|
|
|
|
2020-09-26 10:19:46 +02:00
|
|
|
ynh_script_progression --message="Installation of Movim completed" --last
|