1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/cheky_ynh.git synced 2024-09-03 18:16:00 +02:00

Merge pull request #21 from YunoHost-Apps/4.4.1

4.4.1
This commit is contained in:
Gofannon 2019-05-11 00:33:00 +02:00 committed by GitHub
commit 29c3979225
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 43 deletions

View file

@ -20,6 +20,7 @@
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=a6b2615101887e3235aab0b95607eb1b58507a4c
backup_restore=1
multi_instance=1
incorrect_path=1

View file

@ -8,35 +8,18 @@
# EXPERIMENTAL HELPERS
#=================================================
# Taken from https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_read_manifest/ynh_read_manifest_2#L14-L28
# Idea from https://forum.yunohost.org/t/upgrade-script-how-to-modify-parameter-inside-configuration-file/5352/2
# Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...]
# Source : https://github.com/YunoHost-Apps/Experimental_helpers/tree/master/ynh_exec_as
exec_as() {
local USER=$1
shift 1
# Read the value of a key in a ynh manifest file
#
# usage: ynh_read_manifest manifest key
# | arg: manifest - Path of the manifest to read
# | arg: key - Name of the key to find
ynh_read_manifest () {
manifest="$1"
key="$2"
python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])"
}
# Read the upstream version from the manifest
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
# For example : 4.3-2~ynh3
# This include the number before ~ynh
# In the last example it return 4.3-2
#
# usage: ynh_app_upstream_version
ynh_app_upstream_version () {
manifest_path="../manifest.json"
if [ ! -e "$manifest_path" ]; then
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
if [[ $USER = $(whoami) ]]; then
eval "$@"
else
sudo -u "$USER" "$@"
fi
version_key=$(ynh_read_manifest "$manifest_path" "version")
echo "${version_key/~ynh*/}"
}
#=================================================

View file

@ -48,7 +48,7 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_print_info "Backing up php-fpm configuration..."
ynh_backup "/etc/php7.0/fpm/pool.d/$app.conf"
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE

View file

@ -23,9 +23,6 @@ is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
# Exerimental helper, see "_common.sh"
upstream_version=$(ynh_app_upstream_version)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -110,22 +107,19 @@ ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
#todo: part needed ?
# Verify the checksum and backup the file if it's different
#ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE"
# Recalculate and store the config file checksum into the app settings
#ynh_store_file_checksum "$final_path/CONFIG_FILE"
ynh_print_info "Running specific upgrade..."
# Needed so no manual operation has to be done by user while upgrading
# If missing, Cheky is stuck in an "upgrade" state and the config file
# needs to be edited with latest version
# Also avoid to make file "$final_path/version.php" writable
if [ -f "$final_path/var/config.ini" ]; then
# Change the existing version by the new one taken from the app manifest
ynh_replace_string "^version =.*" "version = \"$upstream_version\"" "$final_path/var/config.ini"
fi
# Give full access to "$app" so php script can do "its own magic stuff"
chown -R $app: $final_path
# Copy Yunohost custom script to cheky folder and launch it
cp yunohost_upgrade_cheky.php $final_path/others/update/
exec_as "$app" /usr/bin/php $final_path/others/update/yunohost_upgrade_cheky.php $final_path
#=================================================
# GENERIC FINALIZATION

View file

@ -0,0 +1,35 @@
<?php
// Script d'upgrade custom pour automatiser la MAJ sans action de l'utilisateur
// source: https://forum.cheky.net/mise-a-jour-de-cheky-en-ligne-de-commande-t659-p1.html#p2624
//$root_path = "__FINALPATH__";
$root_path = $_SERVER["argv"][1];
if (empty($root_path) || !is_dir($root_path)) {
fwrite(STDERR, "Chemin manquant dans hook : post_app_upgrade");
exit(1);
}
require $root_path."/bootstrap.php";
$storageType = $config->get("storage", "type", "files");
if ($storageType == "db") {
$userStorage = new \App\Storage\Db\User($dbConnection);
} else {
$userStorage = new \App\Storage\File\User(DOCUMENT_ROOT."/var/users.db");
}
$_POST = array(
"upgrade" => 1,
);
require $root_path."/app/admin/scripts/upgrade.php";
// S'il y a des erreurs, on les écrit dans STDERR et on quitte
// avec un code erreur.
if (!empty($errors)) {
fwrite(STDERR, str_replace(
array("<br>", "<br />"), "", implode("\n", $errors)
));
exit(1);
}