1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lufi_ynh.git synced 2024-09-03 19:36:28 +02:00

[fix] Upgrade

This commit is contained in:
magikcypress 2017-04-19 14:52:02 +02:00
parent 463baa34e7
commit 7c99664f3f
2 changed files with 18 additions and 49 deletions

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
ynh_version="2.4" ynh_version="2.5"
YNH_VERSION () { # Returns the version number of the Yunohost moulinette YNH_VERSION () { # Returns the version number of the Yunohost moulinette
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
@ -109,12 +109,21 @@ CHECK_MD5_CONFIG () { # Created a backup of the config file if it was changed.
} }
FIND_PORT () { # Search free port FIND_PORT () { # Search free port
if [ YNH_VERSION = "2.5" ]; then
# $1 = Port number to start the search. # $1 = Port number to start the search.
port=$1 port=$1
while ! sudo yunohost app checkport $port ; do while ! sudo yunohost app checkport $port ; do
port=$((port+1)) port=$((port+1))
done done
CHECK_VAR "$port" "port empty" CHECK_VAR "$port" "port empty"
else
# $1 = Port number to start the search.
port=$1
if [ "$(sudo yunohost tools port-available $port)" = "True" ]; then
port=$((port+1))
fi
CHECK_VAR "$port" "port empty"
fi
} }
@ -174,35 +183,6 @@ REMOVE_SYS_USER () { # Delete user
# BACKUP # BACKUP
#================================================= #=================================================
BACKUP_FAIL_UPGRADE () {
WARNING echo "Upgrade failed."
app_bck=${app//_/-} # Replace all '_' by '-'
if sudo yunohost backup list | grep -q $app_bck-pre-upgrade$backup_number; then # Vérifie l'existence de l'archive avant de supprimer l'application et de restaurer
sudo yunohost app remove $app # Supprime l'application avant de la restaurer.
sudo yunohost backup restore --ignore-hooks $app_bck-pre-upgrade$backup_number --apps $app --force # Restore the backup if upgrade failed
ynh_die "The app was restored to the way it was before the failed upgrade."
fi
}
BACKUP_BEFORE_UPGRADE () { # Backup the current version of the app, restore it if the upgrade fails
backup_number=1
old_backup_number=2
app_bck=${app//_/-} # Replace all '_' by '-'
if sudo yunohost backup list | grep -q $app_bck-pre-upgrade1; then # Vérifie l'existence d'une archive déjà numéroté à 1.
backup_number=2 # Et passe le numéro de l'archive à 2
old_backup_number=1
fi
sudo yunohost backup create --ignore-hooks --apps $app --name $app_bck-pre-upgrade$backup_number # Créer un backup différent de celui existant.
if [ "$?" -eq 0 ]; then # Si le backup est un succès, supprime l'archive précédente.
if sudo yunohost backup list | grep -q $app_bck-pre-upgrade$old_backup_number; then # Vérifie l'existence de l'ancienne archive avant de la supprimer, pour éviter une erreur.
QUIET sudo yunohost backup delete $app_bck-pre-upgrade$old_backup_number
fi
else # Si le backup a échoué
ynh_die "Backup failed, the upgrade process was aborted."
fi
}
# Manage a fail of the script # Manage a fail of the script
# #
# Print a warning to inform that the script was failed # Print a warning to inform that the script was failed

View file

@ -41,17 +41,6 @@ then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien
final_path=/var/www/$app final_path=/var/www/$app
fi fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
BACKUP_BEFORE_UPGRADE # Backup the current version of the app
ynh_clean_setup () {
BACKUP_FAIL_UPGRADE # restore it if the upgrade fails
}
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
CHECK_PATH # Checks and corrects the syntax of the path. CHECK_PATH # Checks and corrects the syntax of the path.
# Get source # Get source
@ -120,13 +109,13 @@ popd # Revient au dossier courant avant pushd
# SECURING FILES AND DIRECTORIES # SECURING FILES AND DIRECTORIES
#================================================= #=================================================
sudo chown -R root: $final_path sudo chown -R www-data: $final_path
#================================================= #=================================================
# RESTART LUFI # RESTART LUFI
#================================================= #=================================================
sudo systemctl restart lufi sudo systemctl restart lufi.service
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT