#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= # ynh_script_progression --message="Ensuring downward compatibility..." #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Upgrading source files..." --weight=6 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="app/config/parameters.yml var/logs" # Create log dir/file FIXME: is it useless? mkdir -p "$install_dir/var/logs/" touch "$install_dir/var/logs/prod.log" chown -R "$app:www-data" "$install_dir" #================================================= # CONFIGURE WALLABAG #================================================= ynh_script_progression --message="Reconfiguring wallabag..." --weight=11 # Copy and set Wallabag dist configuration cp "$install_dir/app/config/parameters.yml.dist" "$wb_conf" ynh_replace_string --target_file="$wb_conf" --match_string="fosuser_registration: true" --replace_string="fosuser_registration: false" ynh_replace_string --target_file="$wb_conf" --match_string="database_name: wallabag" --replace_string="database_name: $db_name" ynh_replace_string --target_file="$wb_conf" --match_string="database_user: root" --replace_string="database_user: $db_user" ynh_replace_string --target_file="$wb_conf" --match_string="database_password: ~" --replace_string="database_password: $db_pwd" ynh_replace_string --target_file="$wb_conf" --match_string="database_table_prefix: wallabag_" --replace_string="database_table_prefix: null" ynh_replace_string --target_file="$wb_conf" --match_string="secret: ovmpmAWXRCabNlMgzlzFXDYmCFfzGv" --replace_string="secret: $deskey" ynh_replace_string --target_file="$wb_conf" --match_string="domain_name: https://your-wallabag-url-instance.com" --replace_string="domain_name: https://$domain$path" chown -R "$app:www-data" "$install_dir" # Alias for php-cli execution command php_exec=("php$YNH_PHP_VERSION" "$install_dir/bin/console" --no-interaction --env=prod) # Upgrade database and clear the cache ynh_exec_as "$app" "${php_exec[@]}" doctrine:migrations:migrate ynh_exec_as "$app" "${php_exec[@]}" cache:clear # Configure Wallabag instance URL ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name"\ <<< "UPDATE internal_setting SET value = 'https://$domain$path' WHERE name = 'wallabag_url'" set_permissions #================================================= # SETUP HOOKS #================================================= ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_user_create" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_user_delete" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config # Create a dedicated PHP-FPM config ynh_add_fpm_config ynh_use_logrotate --non-append # Add fail2ban config ynh_add_fail2ban_config --logpath="$install_dir/var/logs/prod.log" --failregex='app.ERROR: Authentication failure for user "([\w]+)?", from IP ""' --max_retry=5 # same as install config #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last