From 919fa615f3dc073beb70d222f5f8d671e7d7098e Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Thu, 21 May 2020 16:14:14 +0200 Subject: [PATCH] add checksum --- scripts/install | 3 ++- scripts/upgrade | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 050bd6a..5aa5a7b 100644 --- a/scripts/install +++ b/scripts/install @@ -111,13 +111,14 @@ ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/config.json.example" ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/config.json.example" cp ../conf/config.json.example "$final_path"/config.json -ynh_store_file_checksum "$final_path/config.json" +ynh_store_file_checksum --file="$final_path/config.json" # DB Config File ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/.sequelizerc.example" ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/.sequelizerc.example" ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/.sequelizerc.example" cp ../conf/.sequelizerc.example "$final_path"/.sequelizerc +ynh_store_file_checksum --file="$final_path/.sequelizerc" #============================================== # INSTALL CODIMD diff --git a/scripts/upgrade b/scripts/upgrade index b45c092..f33f32a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -156,8 +156,46 @@ ynh_script_progression --message="Making sure dedicated system user exists..." - # Create a dedicated user (if not existing) ynh_system_user_create --username=$app + + + + #================================================= # SPECIFIC UPGRADE +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= + +### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. +### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. +ynh_backup_if_checksum_is_different --file="$final_path/config.json" +ynh_backup_if_checksum_is_different --file="$final_path/.sequelizerc" + + +# Main config File +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.json.example" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/config.json.example" +ynh_replace_string --match_string="__PATH__" --replace_string="${path_url:1}" --target_file="../conf/config.json.example" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/config.json.example" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/config.json.example" +ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/config.json.example" +cp ../conf/config.json.example "$final_path"/config.json +ynh_store_file_checksum "$final_path/config.json" + +# DB Config File +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/.sequelizerc.example" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/.sequelizerc.example" +ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/.sequelizerc.example" +cp ../conf/.sequelizerc.example "$final_path"/.sequelizerc + +# Recalculate and store the checksum of the file for the next upgrade. +ynh_store_file_checksum --file="$final_path/config.json" +ynh_store_file_checksum --file="$final_path/.sequelizerc" + + + + + #================================================= # SETUP LOGROTATE #=================================================