2016-11-26 16:25:18 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-01-03 18:32:00 +01:00
|
|
|
|
2024-03-22 22:13:52 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
|
2024-01-06 19:17:03 +01:00
|
|
|
# Boring backward compatibility
|
|
|
|
if [ "${language:-}" == "fr" ] ; then
|
|
|
|
language="fr_FR"
|
|
|
|
else
|
|
|
|
language="en_UK"
|
|
|
|
fi
|
|
|
|
|
2024-03-22 22:13:52 +01:00
|
|
|
if [ -z "${password:-}" ]; then
|
|
|
|
password="$admin_pwd"
|
2024-01-07 04:54:47 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=password --value="$password"
|
|
|
|
fi
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2024-03-22 22:13:52 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=3
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2024-06-20 07:48:11 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir" --keep="local/config/config.inc.php local/config/database.inc.php" #--full_replace=1
|
2024-03-23 12:29:27 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir/plugins/Ldap_Login" --source_id=ldap_plugin --full_replace=1
|
|
|
|
ynh_setup_source --dest_dir="$install_dir/plugins" --source_id=log_failed_logins_plugin --full_replace=1
|
2024-01-06 19:40:17 +01:00
|
|
|
|
2023-10-05 21:38:07 +02:00
|
|
|
chmod -R o-rwx "$install_dir"
|
2024-03-22 22:13:52 +01:00
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2021-05-18 03:42:43 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2023-12-27 13:51:24 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2023-12-05 01:34:25 +01:00
|
|
|
ynh_add_fpm_config
|
2022-06-24 05:33:16 +02:00
|
|
|
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
# UPGRADE APPLICATION WITH CURL
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
2020-11-12 18:28:43 +01:00
|
|
|
ynh_script_progression --message="Upgrading Piwigo with cURL..." --weight=6
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2021-02-18 19:52:56 +01:00
|
|
|
# Upgrade Piwigo via cURL
|
2024-01-06 19:45:31 +01:00
|
|
|
# Why can't we trigger the migration from the command line somehow ...
|
2024-01-06 21:53:16 +01:00
|
|
|
ynh_local_curl "/upgrade.php?language=$language&now=true" "language=$language" "username=$admin" "password=$password"
|
2017-02-08 18:32:46 +01:00
|
|
|
|
2017-09-22 21:21:52 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE PIWIGO
|
|
|
|
#=================================================
|
2023-12-27 13:52:03 +01:00
|
|
|
ynh_script_progression --message="Configuring $app..." --weight=2
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
# Change local config
|
2023-12-27 13:48:16 +01:00
|
|
|
ynh_add_config --template="config.inc.php" --destination="$install_dir/local/config/config.inc.php"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2021-06-16 00:09:21 +02:00
|
|
|
# Setup database in local/config/database.inc.php
|
2023-12-27 13:48:16 +01:00
|
|
|
ynh_add_config --template="database.inc.php" --destination="$install_dir/local/config/database.inc.php"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2023-10-05 21:38:07 +02:00
|
|
|
chmod -R o-rwx "$install_dir"
|
2024-03-22 22:13:52 +01:00
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2017-09-22 21:21:52 +02:00
|
|
|
#=================================================
|
2020-02-29 21:56:40 +01:00
|
|
|
# CONFIGURE LDAP PLUGIN
|
2017-09-22 21:21:52 +02:00
|
|
|
#=================================================
|
2023-12-27 13:52:03 +01:00
|
|
|
ynh_script_progression --message="Configuring LDAP plugin..." --weight=2
|
2017-09-22 21:21:52 +02:00
|
|
|
|
2020-03-28 10:17:23 +01:00
|
|
|
# Disable LDAP plugin to avoid warning messages during API call
|
2024-03-22 22:13:52 +01:00
|
|
|
ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" <<< "DELETE FROM plugins WHERE id='Ldap_Login';"
|
2020-03-28 10:17:23 +01:00
|
|
|
|
2020-02-29 21:56:40 +01:00
|
|
|
# Activate the LDAP plugin using the WS API
|
|
|
|
|
|
|
|
# Login with admin account
|
2023-12-04 22:43:13 +01:00
|
|
|
|
2024-01-06 19:45:31 +01:00
|
|
|
# ... isn't there a way to enable the damn LDAP login plugin from the command line or something ...
|
2024-01-07 04:52:35 +01:00
|
|
|
ynh_local_curl "/ws.php?format=json" "method=pwg.session.login" "username=$admin" "password=$password"
|
2021-08-26 23:39:52 +02:00
|
|
|
# Get session token
|
2020-02-29 21:56:40 +01:00
|
|
|
status=$(ynh_local_curl "/ws.php?format=json" "method=pwg.session.getStatus")
|
2024-03-22 22:13:52 +01:00
|
|
|
pwg_token=$(jq --raw-output .result.pwg_token <<< "$status")
|
2020-02-29 21:56:40 +01:00
|
|
|
# Activate the Ldap_Login plugin
|
|
|
|
ynh_local_curl "/ws.php?format=json" "method=pwg.plugins.performAction" "action=activate" "plugin=Ldap_Login" "pwg_token=$pwg_token"
|
2021-08-26 23:39:52 +02:00
|
|
|
# Log out
|
2020-02-29 21:56:40 +01:00
|
|
|
ynh_local_curl "/ws.php?format=json" "method=pwg.session.logout"
|
|
|
|
|
|
|
|
# Edit Ldap_Login plugin configuration
|
2024-03-22 22:13:52 +01:00
|
|
|
ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" <<< "UPDATE piwigo_ldap_login_config SET value='ou=users,dc=yunohost,dc=org' WHERE param = 'ld_basedn';
|
2020-02-29 21:56:40 +01:00
|
|
|
UPDATE piwigo_ldap_login_config SET value='uid' WHERE param = 'ld_user_attr';
|
|
|
|
UPDATE piwigo_ldap_login_config SET value='' WHERE param = 'ld_binddn';
|
|
|
|
UPDATE piwigo_ldap_login_config SET value='0' WHERE param = 'allow_new_users';
|
|
|
|
UPDATE piwigo_ldap_login_config SET value='0' WHERE param = 'ld_group_user_active';"
|
2024-03-22 22:13:52 +01:00
|
|
|
|
2020-02-29 21:56:40 +01:00
|
|
|
# Remove configuration file for older plugin version
|
2024-03-22 22:13:52 +01:00
|
|
|
if [ -f "$install_dir/plugins/Ldap_Login/data.dat" ] ; then
|
|
|
|
ynh_secure_remove --file="$install_dir/plugins/Ldap_Login/data.dat"
|
2020-02-29 21:56:40 +01:00
|
|
|
fi
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE FAIL2BAN
|
|
|
|
#=================================================
|
2020-11-12 18:28:43 +01:00
|
|
|
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=8
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-06-18 18:24:10 +02:00
|
|
|
# Configure and activate log_failed_logins plugin
|
2024-03-22 22:13:52 +01:00
|
|
|
if ! ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" <<< "INSERT INTO plugins (id,state,version) VALUES ('log_failed_logins','active','1.2');" 2>&1 > /dev/null; then
|
|
|
|
ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" <<< "UPDATE plugins SET state='active' WHERE id='log_failed_logins';"
|
|
|
|
fi
|
|
|
|
if ! ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" <<< "INSERT INTO config (param, value) VALUES ('logFailedLoginsFilename','/var/log/${app}FailedLogins.log');" 2>&1 > /dev/null; then
|
|
|
|
ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" <<< "UPDATE config SET value='/var/log/${app}FailedLogins.log' WHERE param='logFailedLoginsFilename';"
|
|
|
|
fi
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
touch "/var/log/${app}FailedLogins.log"
|
2024-03-22 22:13:52 +01:00
|
|
|
chown "$app:" "/var/log/${app}FailedLogins.log"
|
2017-06-18 18:24:10 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
ynh_add_fail2ban_config --logpath="/var/log/${app}FailedLogins.log" --failregex="ip=<HOST>" --max_retry=6
|
|
|
|
|
2019-02-17 20:58:31 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-05-16 19:41:11 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|