diff --git a/README.md b/README.md index c98ad3a..9380609 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,35 @@ -Piwigo for YunoHost ---------------------- +# Piwigo for YunoHost +[![Integration level](https://dash.yunohost.org/integration/piwigo.svg)](https://dash.yunohost.org/appci/app/piwigo) [![Install Piwigo with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=piwigo) -[![Integration level](https://dash.yunohost.org/integration/piwigo.svg)](https://ci-apps.yunohost.org/jenkins/job/piwigo%20%28Community%29/lastBuild/consoleFull) +> *This package allow you to install Piwigo quickly and simply on a YunoHost server. +If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* -[Piwigo](http://piwigo.org) is a photo gallery software for the web, built by an active community of users and developers. +## Overview +[Piwigo](http://piwigo.org) is a photo gallery software for the web, built by an active community of users and developers Extensions make Piwigo easily customizable. Icing on the cake, Piwigo is free and opensource. **Shipped version:** 2.9.4 +## Screenshots + ![](http://piwigo.org/screenshots/homepage/piwigo-batch-manager.png) -## Features +## Demo + +* [YunoHost demo](https://demo.yunohost.org/piwigo/) +* [Official demo](http://piwigo.org/demo/) + +## Configuration + +## Documentation + + * Official documentation: https://piwigo.org/doc/doku.php + * YunoHost documentation: https://yunohost.org/#/app_piwigo + +## YunoHost specific features In addition to Piwigo core features, the following are made available with this package: @@ -25,14 +41,32 @@ this package: * allow other users management, and guest mode * Allow one YunoHost user to be the administrator (set at the installation) +#### Supported architectures + +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/piwigo%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/piwigo/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/piwigo%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/piwigo/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/piwigo%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/piwigo/) + ## Limitations -No limitation known. - -It has been tested on x86_64 and ARM. +## Additionnal informations ## Links * Report a bug: https://github.com/YunoHost-Apps/piwigo_ynh/issues * Piwigo website: http://piwigo.org/ * YunoHost website: https://yunohost.org/ + +--- + +Developers infos +---------------- + +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/piwigo_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/piwigo_ynh/tree/testing --debug +or +sudo yunohost app upgrade piwigo -u https://github.com/YunoHost-Apps/piwigo_ynh/tree/testing --debug +``` diff --git a/check_process b/check_process index 3e14e66..c40bce7 100644 --- a/check_process +++ b/check_process @@ -3,7 +3,7 @@ domain="domain.tld" (DOMAIN) path="/path" (PATH) admin="john" (USER) - language="fr" + language="fr" is_public=1 (PUBLIC|public=1|private=0) ; Checks pkg_linter=1 diff --git a/conf/app.src b/conf/app.src index bf52705..97529b6 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,3 +1,6 @@ SOURCE_URL=http://piwigo.org/download/dlcounter.php?code=2.9.4 SOURCE_SUM=00fafe6887af62e34ee97dc9b8e4be0720af9f27ea1cdb16ab6217f462574a3c +SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/database.inc.php b/conf/database.inc.php index c7db0ee..fe6160c 100644 --- a/conf/database.inc.php +++ b/conf/database.inc.php @@ -1,8 +1,8 @@ &2 - # Remove the option so that next regular backup will be complete - ynh_app_setting_delete $app backup_core_only -fi - #================================================= -# BACKUP FAIL2BAN CONFIGURATION -#================================================= -ynh_backup "/etc/fail2ban/jail.d/$app.conf" -ynh_backup "/etc/fail2ban/filter.d/$app.conf" - -#================================================= -# BACKUP NGINX CONFIGURATION +# BACKUP THE NGINX CONFIGURATION #================================================= ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# BACKUP PHP-FPM CONFIGURATION +# BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_backup "/etc/php5/fpm/pool.d/$app.conf" #================================================= -# BACKUP MYSQL DB +# BACKUP THE MYSQL DATABASE #================================================= ynh_mysql_dump_db "$db_name" > db.sql + +#================================================= +# BACKUP FAIL2BAN CONFIGURATION +#================================================= + +ynh_backup "/etc/php5/fpm/pool.d/$app.conf" +ynh_backup "/etc/fail2ban/jail.d/$app.conf" +ynh_backup "/etc/fail2ban/filter.d/$app.conf" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP THE DATA DIRECTORY +#================================================= + +# The 1 parameter indicates the directory is "big", +# so that it won't be backed up before upgrade +# This argument has to be the third one. +ynh_backup "/home/yunohost.app/${app}/upload" "/home/yunohost.app/${app}/upload" 1 + diff --git a/scripts/change_url b/scripts/change_url index 5ca358b..07c17fc 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -21,6 +21,13 @@ new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME +#================================================= +# LOAD SETTINGS +#================================================= + +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get $app final_path) + #================================================= # CHECK PATHS SYNTAX #================================================= @@ -57,24 +64,23 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf # Change the path in the nginx config file if [ $change_path -eq 1 ] then - # Make a backup of the original nginx config file if modified - ynh_backup_if_checksum_is_different "$nginx_conf_path" - # Replace locations starting with old_path - # Look for every location possible patterns (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location) - ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $old_path" "location\1 $new_path" "$nginx_conf_path" - # Replace path in "return" directives - ynh_replace_string "return \([[:digit:]]\{3\}\) $old_path" "return \1 $new_path" "$nginx_conf_path" - # Calculate and store the nginx config file checksum - ynh_store_file_checksum "$nginx_conf_path" + # Make a backup of the original nginx config file if modified + ynh_backup_if_checksum_is_different "$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated nginx config + ynh_add_nginx_config fi # Change the domain for nginx if [ $change_domain -eq 1 ] then - ynh_delete_file_checksum "$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" + # Delete file checksum for the old conf file location + ynh_delete_file_checksum "$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= @@ -84,3 +90,4 @@ fi #================================================= systemctl reload nginx + diff --git a/scripts/install b/scripts/install index 9cb15be..4967119 100644 --- a/scripts/install +++ b/scripts/install @@ -1,5 +1,4 @@ #!/bin/bash -shopt -s extglob # sets extended pattern matching options in the bash shell #================================================= # GENERIC STARTING @@ -14,39 +13,31 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_abort_if_errors # Stop script if an error is detected +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -# Retrieve app id -app=$YNH_APP_INSTANCE_NAME - -# Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE -if [ "$language" = "fr" ] ; then - applanguage="fr_FR" -else - applanguage="en_UK" -fi +app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -path_url=$(ynh_normalize_url_path $path_url) # Check and normalize path - final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" -# Check web path availability -ynh_webpath_available $domain $path_url +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + # Register (book) web path ynh_webpath_register $app $domain $path_url @@ -54,11 +45,11 @@ ynh_webpath_register $app $domain $path_url # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set $app domain "$domain" -ynh_app_setting_set $app path_url "$path_url" -ynh_app_setting_set $app admin "$admin" -ynh_app_setting_set $app is_public "$is_public" -ynh_app_setting_set $app language "$language" +ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app path $path_url +ynh_app_setting_set $app admin $admin +ynh_app_setting_set $app is_public $is_public +ynh_app_setting_set $app language $language #================================================= # STANDARD MODIFICATIONS @@ -73,20 +64,19 @@ ynh_install_app_dependencies "$pkg_dependencies" #================================================= db_name=$(ynh_sanitize_dbid $app) -db_user="$db_name" -ynh_app_setting_set "$app" db_name "$db_name" - -# Initialize database -ynh_mysql_setup_db "$db_user" "$db_name" +ynh_app_setting_set $app db_name $db_name +ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_app_setting_set $app final_path "$final_path" +ynh_app_setting_set $app final_path $final_path + # Create tmp directory and fetch app inside -tmpdir=$(mktemp -d) +tmpdir="$(ynh_smart_mktemp --min_size=300)" ynh_setup_source "$tmpdir" + # Fetch needed plugins mkdir -p $tmpdir/plugins/Ldap_Login ynh_setup_source "$tmpdir/plugins/Ldap_Login" ldap_plugin @@ -96,11 +86,24 @@ ynh_setup_source "$tmpdir/plugins" log_failed_logins_plugin # CREATE DEDICATED USER #================================================= -ynh_system_user_create $app # Create a dedicated system user +# Create a system user +ynh_system_user_create $app + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config #================================================= # SPECIFIC SETUP #================================================= +# COPY FILES TO $FINAL_PATH +#================================================= + +# sets extended pattern matching options in the bash shell +shopt -s extglob # Install files and set permissions mkdir $final_path @@ -123,69 +126,99 @@ chown -R $app: $final_path chown -R $app: $datapath chmod 755 -R $final_path/_data +ynh_secure_remove "$tmpdir" + #================================================= -# NGINX AND PHP-FPM CONFIGURATION +# PHP-FPM CONFIGURATION #================================================= -ynh_add_nginx_config - -# Copy and set php-fpm configuration +# Create a dedicated php-fpm config ynh_add_fpm_config +#================================================= +# SETUP APPLICATION WITH CURL +#================================================= + +ynh_app_setting_set $app unprotected_uris "/" +# Reload SSOwat config +yunohost app ssowatconf + +# Reload Nginx +systemctl reload nginx + +# Generate random password for admin +adm_pwd=$(ynh_string_random 24) +ynh_app_setting_set $app admin_pwd "$adm_pwd" + +if [ "$language" = "fr" ] ; then + applanguage="fr_FR" +else + applanguage="en_UK" +fi + +# Configure piwigo via curl +mail="$(ynh_user_get_info $admin mail)" + +# Installation with curl +ynh_local_curl "/install.php?language=$applanguage" "install=true" "dbuser=$db_name" "dbpasswd=$db_pwd" "dbname=$db_name" "admin_name=$admin" "admin_pass1=$adm_pwd" "admin_pass2=$adm_pwd" "admin_mail=$mail" + #================================================= # CONFIGURE PIWIGO #================================================= -ynh_app_setting_set "$app" unprotected_uris "/" -yunohost app ssowatconf - -# Generate random password for admin - -adm_pwd=$(ynh_string_random 24) -ynh_app_setting_set $app admin_pwd "$adm_pwd" - -# Configure piwigo via curl -mail="$(ynh_user_get_info $admin mail)" -ynh_local_curl "/install.php?language=$applanguage" "install=true" "dbuser=$db_user" "dbpasswd=$db_pwd" "dbname=$db_name" "admin_name=$admin" "admin_pass1=$adm_pwd" "admin_pass2=$adm_pwd" "admin_mail=$mail" - # Change local config cp ../conf/config.inc.php $final_path/local/config/ + # Calculate and store the config file checksum ynh_store_file_checksum "$final_path/local/config/config.inc.php" # Setup database in local/config/database.inc.php -ynh_replace_string "DBTOCHANGE" "$db_name" ../conf/database.inc.php -ynh_replace_string "USERTOCHANGE" "$db_user" ../conf/database.inc.php -ynh_replace_string "PASSTOCHANGE" "$db_pwd" ../conf/database.inc.php +ynh_replace_string "__DBTOCHANGE__" "$db_name" ../conf/database.inc.php +ynh_replace_string "__USERTOCHANGE__" "$db_name" ../conf/database.inc.php +ynh_replace_string "__PASSTOCHANGE__" "$db_pwd" ../conf/database.inc.php + cp ../conf/database.inc.php $final_path/local/config/database.inc.php + # Calculate and store the database config file checksum ynh_store_file_checksum "$final_path/local/config/database.inc.php" #================================================= -# ADD LDAP & FAIL2BAN PLUGINS +# ADD LDAP PLUGINS #================================================= # Configure and activate LDAP plugin -ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "INSERT INTO plugins (id,state,version) VALUES ('Ldap_Login','active','1.1');" +ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "INSERT INTO plugins (id,state,version) VALUES ('Ldap_Login','active','1.1');" cp ../conf/data.dat $final_path/plugins/Ldap_Login +#================================================= +# CONFIGURE FAIL2BAN +#================================================= + # Configure and activate log_failed_logins plugin -ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "INSERT INTO plugins (id,state,version) VALUES ('log_failed_logins','active','1.2');" -ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "INSERT INTO config (param, value) VALUES ('logFailedLoginsFilename','/var/log/${app}FailedLogins.log');" +ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "INSERT INTO plugins (id,state,version) VALUES ('log_failed_logins','active','1.2');" +ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "INSERT INTO config (param, value) VALUES ('logFailedLoginsFilename','/var/log/${app}FailedLogins.log');" + touch "/var/log/${app}FailedLogins.log" chown $app: "/var/log/${app}FailedLogins.log" -# Set-up fail2ban -ynh_add_fail2ban_config "/var/log/${app}FailedLogins.log" "ip=" 6 +ynh_add_fail2ban_config --logpath="/var/log/${app}FailedLogins.log" --failregex="ip=" --max_retry=6 + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SETUP SSOWAT +#================================================= # Protect URIs if private -if [ $is_public -eq 0 ]; +if [ $is_public -eq 0 ] then - ynh_app_setting_delete "$app" unprotected_uris - ynh_app_setting_set "$app" protected_uris "/" + ynh_app_setting_delete $app unprotected_uris + ynh_app_setting_set $app protected_uris "/" fi #================================================= # RELOAD NGINX #================================================= + systemctl reload nginx + diff --git a/scripts/remove b/scripts/remove index 6106ac3..ce8a17a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -17,6 +17,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get $app db_name) +final_path=$(ynh_app_setting_get $app final_path) #================================================= # STANDARD REMOVE @@ -28,16 +29,32 @@ db_name=$(ynh_app_setting_get $app db_name) ynh_remove_app_dependencies #================================================= -# REMOVE THE MYSQL DB +# REMOVE THE MYSQL DATABASE #================================================= -ynh_mysql_remove_db "$app" "$db_name" +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db $db_name $db_name #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_secure_remove "/var/www/$app" +# Remove the app directory securely +ynh_secure_remove "$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= + +# Remove the dedicated php-fpm config +ynh_remove_fpm_config #================================================= # REMOVE FAIL2BAN CONFIGURATION @@ -46,14 +63,11 @@ ynh_secure_remove "/var/www/$app" ynh_remove_fail2ban_config #================================================= -# REMOVE NGINX AND PHP-FPM CONFIGURATION -#================================================= - -ynh_remove_fpm_config -ynh_remove_nginx_config - +# GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= -ynh_system_user_delete $app \ No newline at end of file +# Delete a system user +ynh_system_user_delete $app + diff --git a/scripts/restore b/scripts/restore index 7b7bdd5..c69de96 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,15 +1,12 @@ #!/bin/bash +#================================================= +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Fetch helpers file if not in current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= @@ -41,53 +38,42 @@ test ! -d $final_path \ || ynh_die "There is already a directory: $final_path " #================================================= -# STANDARD RESTORE STEPS +# STANDARD RESTORATION STEPS #================================================= -# RESTORE NGINX CONFIGURATION +# RESTORE THE NGINX CONFIGURATION #================================================= ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# RESTORE APP MAIN DIR +# RESTORE THE APP MAIN DIR #================================================= ynh_restore_file "$final_path" -# Restore data directory if backed-up -if [ -d "$YNH_BACKUP_DIR/apps/${app}/backup/home/yunohost.app/${app}/upload" ] ; then - ynh_restore_file "/home/yunohost.app/${app}/upload" -else - # Create app data folder - mkdir /home/yunohost.app/${app}/upload -fi -# Create temporary data folder -mkdir -p /home/yunohost.app/${app}/_data -# Remove the option backup_core_only if it's in the settings.yml file -ynh_app_setting_delete $app backup_core_only #================================================= -# RESTORE MYSQL DB +# RESTORE THE MYSQL DATABASE #================================================= db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_create_db $db_name $db_name $db_pwd +ynh_mysql_setup_db $db_name $db_name $db_pwd ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql #================================================= -# RECREATE OF THE DEDICATED USER +# RECREATE THE DEDICATED USER #================================================= -ynh_system_user_create $app # Recreate the dedicated user, if not existing +# Create the dedicated user (if not existing) +ynh_system_user_create $app #================================================= -# RESTORE USER RIGHTS +# RESTORE THE PHP-FPM CONFIGURATION #================================================= -chown -R $app: $final_path -chown -R $app: /home/yunohost.app/${app} +ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= -# RESTORE FAIL2BAN CONFIGURATION +# RESTORE THE FAIL2BAN CONFIGURATION #================================================= ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" @@ -98,10 +84,30 @@ chown $app: "/var/log/${app}FailedLogins.log" systemctl restart fail2ban #================================================= -# RESTORE PHP-FPM CONFIGURATION +# SPECIFIC RESTORATION +#================================================= +# RESTORE THE DATA DIRECTORY +#================================================= + +# The data directory will be restored only if it exists in the backup archive +# So only if it was backup previously. +if [ -d "$YNH_BACKUP_DIR/apps/$app/backup/home/yunohost.app/${app}/upload" ] +then + ynh_restore_file "/home/yunohost.app/${app}/upload" +else + # Create app folders + mkdir -p "/home/yunohost.app/${app}/upload" +fi +# Create temporary data folder +mkdir -p /home/yunohost.app/${app}/_data + +#================================================= +# RESTORE USER RIGHTS #================================================= ynh_restore_file /etc/php5/fpm/pool.d/$app.conf +chown -R $app: $final_path +chown -R $app: /home/yunohost.app/${app} #================================================= # GENERIC FINALIZATION @@ -111,3 +117,4 @@ ynh_restore_file /etc/php5/fpm/pool.d/$app.conf systemctl reload php5-fpm systemctl reload nginx + diff --git a/scripts/upgrade b/scripts/upgrade index 518363c..bd6dd5d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,8 +1,5 @@ #!/bin/bash -shopt -s extglob # sets extended pattern matching options in the bash shell -# Exit on command errors and treat unset variables as an error -set -eu #================================================= # GENERIC STARTING #================================================= @@ -15,123 +12,137 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -# Set app specific variables + app=$YNH_APP_INSTANCE_NAME -# Check destination directory -destdir="/var/www/$app" -[[ ! -d $destdir ]] && ynh_die \ -"The destination directory '$destdir' does not exist.\ - The app is not correctly installed, you should remove it first." +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) -# Retrieve arguments -domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= -path_url=$(ynh_app_setting_get "$app" path_url) -# Compatibility with previous version -if [ -z "$path_url" ] ; then - path_url=$(ynh_app_setting_get "$app" path) - ynh_app_setting_set $app path_url "$path_url" -fi -path_url=$(ynh_normalize_url_path $path_url) - -final_path=$(ynh_app_setting_get "$app" final_path) -# Compatibility with previous version -if [ -z "$final_path" ] ; then - final_path="/var/www/$app" - ynh_app_setting_set $app final_path "$final_path" +# 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 fi -db_name=$(ynh_app_setting_get "$app" db_name) -# Compatibility with previous version -if [ -z "$db_name" ] ; then - db_name=$app - ynh_app_setting_set "$app" db_name "$db_name" +# 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 fi -db_user="$db_name" -db_pwd=$(ynh_app_setting_get "$app" mysqlpwd) -admin=$(ynh_app_setting_get "$app" admin) - -admin_pwd=$(ynh_app_setting_get "$app" admin_pwd) # Compatibility with previous version; password was not set if [ -z "$admin_pwd" ] ; then # Generate a new password admin_pwd=$(ynh_string_random 24) - + # Compute password hash with the Piwigo function cp ../conf/hash_password.php $final_path hashed_password=$(cd $final_path ; php hash_password.php $admin_pwd) - + # Update password hash in database - ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "UPDATE users SET password='$hashed_password' WHERE username='$admin';" + 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';" ynh_app_setting_set $app admin_pwd "$admin_pwd" - + # Remove the temporary hash generation script ynh_secure_remove "$final_path/hash_password.php" fi -language=$(ynh_app_setting_get "$app" language) -if [ "$language" = "fr" ] ; then - applanguage="fr_FR" -else - applanguage="en_UK" -fi - -is_public=$(ynh_app_setting_get "$app" is_public) - -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Use prior backup and restore on error only if backup feature -# exists on installed instance -if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then - # Notify the backup process that it should not save the data directory - ynh_app_setting_set $app backup_core_only 1 - - ynh_backup_before_upgrade # Backup the current version of the app - ynh_clean_setup () { - ynh_restore_upgradebackup - } - ynh_abort_if_errors # Stop script if an error is detected +# 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 fi #================================================= -# INSTALL DEPENDENCIES +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_install_app_dependencies "$pkg_dependencies" +# 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 +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= # Create tmp directory and fetch app inside tmpdir=$(ynh_mkdir_tmp) +tmpdir="$(ynh_smart_mktemp --min_size=300)" ynh_setup_source "$tmpdir" + # Fetch needed plugins mkdir -p $tmpdir/plugins/Ldap_Login ynh_setup_source "$tmpdir/plugins/Ldap_Login" ldap_plugin ynh_setup_source "$tmpdir/plugins" log_failed_logins_plugin +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= + +ynh_install_app_dependencies "$pkg_dependencies" + #================================================= # CREATE DEDICATED USER #================================================= -ynh_system_user_create $app # Create dedicated user if not existing +# Create a dedicated user (if not existing) +ynh_system_user_create $app #================================================= -# SPECIFIC SETUP +# PHP-FPM CONFIGURATION #================================================= -# We store photos (potentially large data) on /home/yunohost.app +# Create a dedicated php-fpm config +ynh_add_fpm_config + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# COPY FILES TO $FINAL_PATH +#================================================= + +# sets extended pattern matching options in the bash shell +shopt -s extglob + datapath=/home/yunohost.app/$app # Install files and set permissions cp -a $tmpdir/!(upload|_data|galleries) $final_path - # Backward compatibility: # If the _data subdirectory wasn't already moved to /home/yunohost.app/$app, # then move it there @@ -152,68 +163,93 @@ chown -R $app: $final_path chown -R $app: $datapath chmod 755 -R $final_path/_data +ynh_secure_remove "$tmpdir" + #================================================= -# NGINX AND PHP-FPM CONFIGURATION +# UPGRADE APPLICATION WITH CURL #================================================= -ynh_add_nginx_config -ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_app_setting_set $app unprotected_uris "/" +# Reload SSOwat config +yunohost app ssowatconf -# Copy and set php-fpm configuration -ynh_add_fpm_config +# 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" #================================================= # CONFIGURE PIWIGO #================================================= - -ynh_app_setting_set "$app" unprotected_uris "/" -yunohost app ssowatconf - -# Configure piwigo via curl -ynh_local_curl "/upgrade.php?language=$applanguage&now=true" "language=$applanguage" "username=$admin" "password=$admin_pwd" +ynh_print_info "Configuring piwigo..." # Make a backup of the original config file if modified ynh_backup_if_checksum_is_different "$final_path/local/config/config.inc.php" + # Change local config cp ../conf/config.inc.php $final_path/local/config/ + # Calculate and store the config file checksum ynh_store_file_checksum "$final_path/local/config/config.inc.php" # Make a backup of the original database config file if modified ynh_backup_if_checksum_is_different "$final_path/local/config/database.inc.php" + # Setup database in local/config/database.inc.php -ynh_replace_string "DBTOCHANGE" "$db_name" ../conf/database.inc.php -ynh_replace_string "USERTOCHANGE" "$db_user" ../conf/database.inc.php -ynh_replace_string "PASSTOCHANGE" "$db_pwd" ../conf/database.inc.php +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 + cp ../conf/database.inc.php $final_path/local/config/database.inc.php + # Calculate and store the database config file checksum ynh_store_file_checksum "$final_path/local/config/database.inc.php" #================================================= -# ADD LDAP & FAIL2BAN PLUGINS +# ADD LDAP PLUGINS #================================================= # Configure and activate LDAP plugin -ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "UPDATE plugins SET state='active' WHERE id='Ldap_Login';" +ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "UPDATE plugins SET state='active' WHERE id='Ldap_Login';" cp ../conf/data.dat $final_path/plugins/Ldap_Login +#================================================= +# UPGRADE FAIL2BAN +#================================================= + # Configure and activate log_failed_logins plugin -ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "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_user <<< "UPDATE plugins SET state='active' WHERE id='log_failed_logins';" -ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "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_user <<< "UPDATE config SET value='/var/log/${app}FailedLogins.log' WHERE param='logFailedLoginsFilename';" +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';" + touch "/var/log/${app}FailedLogins.log" chown $app: "/var/log/${app}FailedLogins.log" -# Set-up fail2ban -ynh_add_fail2ban_config "/var/log/${app}FailedLogins.log" "ip=" 6 +ynh_add_fail2ban_config --logpath="/var/log/${app}FailedLogins.log" --failregex="ip=" --max_retry=6 + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SETUP SSOWAT +#================================================= # Protect URIs if private -if [ $is_public -eq 0 ]; +if [ $is_public -eq 0 ] then - ynh_app_setting_delete "$app" unprotected_uris - ynh_app_setting_set "$app" protected_uris "/" + ynh_app_setting_delete $app unprotected_uris + ynh_app_setting_set $app protected_uris "/" fi #================================================= # RELOAD NGINX #================================================= -systemctl reload nginx \ No newline at end of file + +systemctl reload nginx +