2016-11-26 16:25:18 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-11-26 16:25:18 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-01-03 18:32:00 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Loading installation settings..."
|
2016-11-26 16:25:18 +01:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-01-03 18:32:00 +01:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
|
|
admin=$(ynh_app_setting_get $app admin)
|
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
language=$(ynh_app_setting_get $app language)
|
|
|
|
db_name=$(ynh_app_setting_get $app db_name)
|
|
|
|
admin_pwd=$(ynh_app_setting_get $app admin_pwd)
|
2017-09-22 21:21:52 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Ensuring downward compatibility..."
|
2017-09-22 21:21:52 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
if [ -z $db_name ]; then
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
ynh_app_setting_set $app db_name $db_name
|
2017-06-03 18:13:29 +02:00
|
|
|
fi
|
2017-09-22 21:21:52 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z $final_path ]; then
|
|
|
|
final_path=/var/www/$app
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2017-06-03 18:13:29 +02:00
|
|
|
fi
|
2017-09-22 21:21:52 +02:00
|
|
|
|
|
|
|
# Compatibility with previous version; password was not set
|
2017-06-03 18:13:29 +02:00
|
|
|
if [ -z "$admin_pwd" ] ; then
|
|
|
|
# Generate a new password
|
2017-10-01 21:59:40 +02:00
|
|
|
admin_pwd=$(ynh_string_random 24)
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Compute password hash with the Piwigo function
|
2017-09-11 22:00:57 +02:00
|
|
|
cp ../conf/hash_password.php $final_path
|
2017-06-03 18:13:29 +02:00
|
|
|
hashed_password=$(cd $final_path ; php hash_password.php $admin_pwd)
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Update password hash in database
|
2019-02-17 19:28:37 +01:00
|
|
|
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "UPDATE users SET password='$hashed_password' WHERE username='$admin';"
|
2017-06-03 18:13:29 +02:00
|
|
|
ynh_app_setting_set $app admin_pwd "$admin_pwd"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-09-22 21:21:52 +02:00
|
|
|
# Remove the temporary hash generation script
|
2017-06-03 18:13:29 +02:00
|
|
|
ynh_secure_remove "$final_path/hash_password.php"
|
|
|
|
fi
|
2017-09-22 21:21:52 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# Use path instead of path_url in settings.yml...
|
|
|
|
if [ -z "$path_url" ]
|
|
|
|
then
|
|
|
|
path_url=$(ynh_app_setting_get $app path_url)
|
|
|
|
ynh_app_setting_set $app path $path_url
|
|
|
|
ynh_app_setting_delete $app path_url
|
2017-06-03 18:13:29 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Backing up the app before upgrading (may take a while)..."
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2017-09-23 10:25:23 +02:00
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
# CHECK THE PATH
|
2017-09-23 10:25:23 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# Normalize the URL path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
2017-09-23 10:25:23 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Upgrading source files..."
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
# Create tmp directory and fetch app inside
|
2019-02-17 19:28:37 +01:00
|
|
|
tmpdir="$(ynh_smart_mktemp --min_size=300)"
|
2017-10-19 21:06:34 +02:00
|
|
|
ynh_setup_source "$tmpdir"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-06-18 18:24:10 +02:00
|
|
|
# Fetch needed plugins
|
2017-10-19 21:06:34 +02:00
|
|
|
mkdir -p $tmpdir/plugins/Ldap_Login
|
|
|
|
ynh_setup_source "$tmpdir/plugins/Ldap_Login" ldap_plugin
|
|
|
|
ynh_setup_source "$tmpdir/plugins" log_failed_logins_plugin
|
2016-11-26 16:25:18 +01:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Upgrading nginx web server configuration..."
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Upgrading dependencies..."
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
|
|
ynh_install_app_dependencies "$pkg_dependencies"
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Making sure dedicated system user exists..."
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Upgrading php-fpm configuration..."
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
|
|
# Create a dedicated php-fpm config
|
|
|
|
ynh_add_fpm_config
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# COPY FILES TO $FINAL_PATH
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# sets extended pattern matching options in the bash shell
|
|
|
|
shopt -s extglob
|
|
|
|
|
2017-10-01 21:59:40 +02:00
|
|
|
datapath=/home/yunohost.app/$app
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Install files and set permissions
|
2018-07-31 21:35:38 +02:00
|
|
|
cp -a $tmpdir/!(upload|_data|galleries) $final_path
|
2017-10-01 21:59:40 +02:00
|
|
|
|
|
|
|
# Backward compatibility:
|
|
|
|
# If the _data subdirectory wasn't already moved to /home/yunohost.app/$app,
|
|
|
|
# then move it there
|
|
|
|
if [ ! -h $final_path/_data ] ; then
|
|
|
|
mv $final_path/_data $datapath
|
|
|
|
ln -sd $datapath/_data $final_path/_data
|
|
|
|
fi
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2018-07-31 21:35:38 +02:00
|
|
|
# Backward compatibility:
|
|
|
|
# If the galleries subdirectory wasn't already moved to /home/yunohost.app/$app,
|
|
|
|
# then move it there
|
|
|
|
if [ ! -h $final_path/galleries ] ; then
|
|
|
|
mv $final_path/galleries $datapath
|
|
|
|
ln -sd $datapath/galleries $final_path/galleries
|
|
|
|
fi
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
chown -R $app: $final_path
|
2017-10-01 21:59:40 +02:00
|
|
|
chown -R $app: $datapath
|
|
|
|
chmod 755 -R $final_path/_data
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
ynh_secure_remove "$tmpdir"
|
|
|
|
|
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
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Upgrading piwigo with Curl..."
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
|
|
# Reload SSOwat config
|
|
|
|
yunohost app ssowatconf
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# Reload Nginx
|
|
|
|
systemctl reload nginx
|
|
|
|
|
|
|
|
if [ "$language" = "fr" ] ; then
|
|
|
|
applanguage="fr_FR"
|
|
|
|
else
|
|
|
|
applanguage="en_UK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Upgrade piwigo via curl
|
|
|
|
ynh_local_curl "/upgrade.php?language=$applanguage&now=true" "language=$applanguage" "username=$admin" "password=$admin_pwd"
|
2017-02-08 18:32:46 +01:00
|
|
|
|
2017-09-22 21:21:52 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE PIWIGO
|
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
ynh_print_info "Configuring piwigo..."
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
# Make a backup of the original config file if modified
|
|
|
|
ynh_backup_if_checksum_is_different "$final_path/local/config/config.inc.php"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Change local config
|
2017-09-11 22:00:57 +02:00
|
|
|
cp ../conf/config.inc.php $final_path/local/config/
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
# Calculate and store the config file checksum
|
|
|
|
ynh_store_file_checksum "$final_path/local/config/config.inc.php"
|
2016-11-26 16:25:18 +01:00
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
# Make a backup of the original database config file if modified
|
|
|
|
ynh_backup_if_checksum_is_different "$final_path/local/config/database.inc.php"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Setup database in local/config/database.inc.php
|
2019-02-17 19:28:37 +01:00
|
|
|
ynh_replace_string "__DBTOCHANGE__" "$db_name" ../conf/database.inc.php
|
|
|
|
ynh_replace_string "__USERTOCHANGE__" "$db_name" ../conf/database.inc.php
|
|
|
|
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
|
|
|
ynh_replace_string "__PASSTOCHANGE__" "$db_pwd" ../conf/database.inc.php
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
cp ../conf/database.inc.php $final_path/local/config/database.inc.php
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
# Calculate and store the database config file checksum
|
|
|
|
ynh_store_file_checksum "$final_path/local/config/database.inc.php"
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2017-09-22 21:21:52 +02:00
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
# ADD LDAP PLUGINS
|
2017-09-22 21:21:52 +02:00
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Configuring LDAP plugin..."
|
2017-09-22 21:21:52 +02:00
|
|
|
|
2017-11-19 19:42:54 +01:00
|
|
|
# Configure and activate LDAP plugin
|
2019-02-17 19:28:37 +01:00
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "UPDATE plugins SET state='active' WHERE id='Ldap_Login';"
|
2017-11-19 19:42:54 +01:00
|
|
|
cp ../conf/data.dat $final_path/plugins/Ldap_Login
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE FAIL2BAN
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Upgrading fail2ban..."
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2017-06-18 18:24:10 +02:00
|
|
|
# Configure and activate log_failed_logins plugin
|
2019-02-17 19:28:37 +01:00
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "INSERT INTO plugins (id,state,version) VALUES ('log_failed_logins','active','1.2');" 2>&1 > /dev/null ||ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "UPDATE plugins SET state='active' WHERE id='log_failed_logins';"
|
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "INSERT INTO config (param, value) VALUES ('logFailedLoginsFilename','/var/log/${app}FailedLogins.log');" 2>&1 > /dev/null || ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "UPDATE config SET value='/var/log/${app}FailedLogins.log' WHERE param='logFailedLoginsFilename';"
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
touch "/var/log/${app}FailedLogins.log"
|
|
|
|
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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Upgrading SSOwat configuration..."
|
2017-06-18 18:24:10 +02:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Protect URIs if private
|
2019-02-17 19:28:37 +01:00
|
|
|
if [ $is_public -eq 0 ]
|
2016-11-26 16:25:18 +01:00
|
|
|
then
|
2019-02-17 19:28:37 +01:00
|
|
|
ynh_app_setting_delete $app unprotected_uris
|
|
|
|
ynh_app_setting_set $app protected_uris "/"
|
2017-06-03 18:13:29 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-02-17 20:58:31 +01:00
|
|
|
ynh_print_info "Reloading nginx web server..."
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
|
|
systemctl reload nginx
|
|
|
|
|
2019-02-17 20:58:31 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_print_info "Upgrade of $app completed"
|