1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/scripts/install

217 lines
7.8 KiB
Text
Raw Normal View History

#!/bin/bash
2018-08-10 15:55:41 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2018-08-10 15:55:41 +02:00
source _common.sh
2018-08-10 14:59:24 +02:00
source /usr/share/yunohost/helpers
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
#=================================================
# FIND AND OPEN A PORT
#=================================================
2021-01-15 13:32:05 +01:00
ynh_script_progression --message="Finding an available port..." --weight=2
# 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
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
ynh_psql_setup_db --db_user=$db_name --db_name=$db_name
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"
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
# 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
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
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
#=================================================
# Install PHP dependencies using composer
2018-08-10 15:55:41 +02:00
#=================================================
ynh_script_progression --message="Configuring Composer..." --weight=1
2018-08-10 15:55:41 +02:00
2021-01-15 13:32:05 +01:00
pushd $final_path
2020-08-03 13:51:46 +02:00
export COMPOSER_HOME=$final_path
2021-01-15 13:32:05 +01:00
ynh_exec_warn_less curl -sS https://getcomposer.org/installer | php${phpversion} -- --version="1.10.16" --install-dir="$final_path" \
&& php${phpversion} composer.phar install --no-interaction --quiet
popd
2020-07-24 17:54:48 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=12
2020-07-24 12:31:07 +02:00
2020-09-17 09:02:08 +02:00
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file=../conf/systemd.service
2020-09-18 22:44:58 +02:00
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file=../conf/systemd.service
2021-01-15 13:32:05 +01:00
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=../conf/systemd.service
ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file=../conf/systemd.service
2018-08-10 15:55:41 +02:00
2018-08-12 00:22:31 +02:00
ynh_add_systemd_config
2018-08-12 00:59:39 +02:00
#=================================================
# Set-up database and configuration
#=================================================
2020-09-17 10:38:35 +02:00
ynh_script_progression --message="Configuring database..." --weight=1
cache_dir="/home/$app"
2020-09-17 18:12:53 +02:00
# Create cachedir folder
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
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
#=================================================
2020-09-17 18:12:53 +02:00
chown -R $app:www-data $final_path
2020-09-17 19:00:03 +02:00
chown -R $app $final_path/src/Movim/
chmod u+rwx $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
#=================================================
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
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