From 2abede8e4fe0ae6795697ae3e6ae40785cd74363 Mon Sep 17 00:00:00 2001 From: caglarkilimci <110826807+caglarkilimci@users.noreply.github.com> Date: Thu, 22 Feb 2024 13:14:46 +0100 Subject: [PATCH] SW-4388 Set config fields if the value is presented at the backed up one (#128) SW-4388 Set config fields if the value is presented at the backed up one. --- .../filesystem/migration/usr/bin/migration.sh | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 8846435..0532b96 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -378,19 +378,46 @@ do_restore_data () { migrationoperator="workshop" #accessControl needed for users.yaml echo "$(timestamp) $0: Restoring accessControl for $configfile" - sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"accessControl":select(fileIndex==1).accessControl}' $applyfile - + accessControl=$(sudo yq eval '.accessControl' $backupfile) + salt=$(sudo yq eval '.accessControl.salt' $backupfile) + # Check if the accessControl field is empty or salt is null + if [ -z "$accessControl" ] || [ "$salt" == "null" ]; then + echo "$(timestamp) $0: Warning - accessControl field is empty in $backupfile. Remove users.yaml files from to be restored file list." + DATA_TO_RESTORE=("${DATA_TO_RESTORE[@]/".octoprint/users.yaml"}") + DATA_TO_RESTORE=("${DATA_TO_RESTORE[@]/".octoprint/users-dev.yaml"}") + else + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"accessControl":select(fileIndex==1).accessControl}' $applyfile - + fi #plugins.findmymrbeam echo "$(timestamp) $0: Restoring plugins.findmymrbeam for $configfile" - sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"findmymrbeam":select(fileIndex==1).plugins.findmymrbeam}}' $applyfile - + findmymrbeam=$(sudo yq eval '.plugins.findmymrbeam' $backupfile) + # Check if the findmymrbeam field is empty or null + if [ -z "$findmymrbeam" ] || [ "$findmymrbeam" == "null" ]; then + echo "$(timestamp) $0: Warning - findmymrbeam field is empty in $backupfile. Skipping." + else + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"findmymrbeam":select(fileIndex==1).plugins.findmymrbeam}}' $applyfile - + fi #plugins.mrbeam.analyticsEnabled echo "$(timestamp) $0: Restoring plugins.mrbeam.analyticsEnabled for $configfile" - sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"analyticsEnabled":select(fileIndex==1).plugins.mrbeam.analyticsEnabled}}}' $applyfile - + analyticsEnabled=$(sudo yq eval '.plugins.mrbeam.analyticsEnabled' $backupfile) + # Check if the analyticsEnabled field is empty or null + if [ -z "$analyticsEnabled" ] || [ "$analyticsEnabled" == "null" ]; then + echo "$(timestamp) $0: Warning - analyticsEnabled field is empty in $backupfile. Skipping." + else + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"analyticsEnabled":select(fileIndex==1).plugins.mrbeam.analyticsEnabled}}}' $applyfile - + fi #plugins.mrbeam.review echo "$(timestamp) $0: Restoring plugins.mrbeam.review for $configfile" - sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - + review=$(sudo yq eval '.plugins.mrbeam.review' $backupfile) + # Check if the review field is empty or null + if [ -z "$review" ] || [ "$review" == "null" ]; then + echo "$(timestamp) $0: Warning - review field is empty in $backupfile. Skipping." + else + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - + fi #plugins.swupdater.attributes.migration_operator echo "$(timestamp) $0: Set plugins.swupdater.attributes.migration_operator as $migrationoperator for $configfile"