diff --git a/functions/menu.sh b/functions/menu.sh index 67543d08..82a04e03 100644 --- a/functions/menu.sh +++ b/functions/menu.sh @@ -14,6 +14,7 @@ echo "5) Update HeavyScript" echo "6) Update Applications" echo "7) Command to Container" echo "8) Patch 22.12.0" +echo "9) Patch 22.12.0 (2)" echo echo "0) Exit" read -rt 120 -p "Please select an option by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } @@ -83,6 +84,9 @@ case $selection in 8) patch_2212_backups ;; + 9) + patch_2212_backups2 + ;; *) echo "\"$selection\" was not an option, please try agian" && sleep 3 && menu ;; diff --git a/functions/misc.sh b/functions/misc.sh index 25501cf7..efb503d6 100644 --- a/functions/misc.sh +++ b/functions/misc.sh @@ -173,3 +173,61 @@ do done } + +patch_2212_backups2(){ +clear -x +#Check TrueNAS version, skip if not 22.12.0 +if ! [ "$(cli -m csv -c 'system version' | awk -F '-' '{print $3}')" == "22.12.0" ]; then + echo "This patch does not apply to your version of TrueNAS" + return +fi + + +#Description +echo "This patch will fix the issue certain applicattions breaking backups" +echo "You only need to run this patch once, it will not run again" +echo + + +# Apply patch +echo "Applying Backup Patch" +if patch -N --reject-file=/dev/null -s -p0 -d /usr/lib/python3/dist-packages/middlewared/plugins/kubernetes_linux/backup.py < patches/backup_patch2.patch &>/dev/null; then + echo "Backup Patch applied" +else + echo "Backup Patch already applied" + exit +fi + +echo + +#Restart middlewared +while true +do + echo "We need to restart middlewared to finish the patch" + echo "This will cause a short downtime for some minor services approximately 10-30 seconds" + echo "Applications should not be affected" + read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } + case $yesno in + [Yy] | [Yy][Ee][Ss]) + echo "Restarting middlewared" + service middlewared restart & + wait $! + echo "Restarted middlewared" + echo "You are set, there is no need to run this patch again" + break + ;; + [Nn] | [Nn][Oo]) + echo "Exiting" + echo "Please restart middlewared manually" + echo "You can do: service middlewared restart" + exit + ;; + *) + echo "That was not an option, try again" + sleep 3 + continue + ;; + esac +done +} + diff --git a/patches/backup_patch2.patch b/patches/backup_patch2.patch new file mode 100644 index 00000000..3ce5de06 --- /dev/null +++ b/patches/backup_patch2.patch @@ -0,0 +1,11 @@ +--- /usr/lib/python3/dist-packages/middlewared/plugins/kubernetes_linux/backup.py 2022-12-13 05:32:23.000000000 -0700 ++++ backups.patch 2022-12-26 14:14:25.075037767 -0700 +@@ -61,7 +61,8 @@ + ['metadata.namespace', '=', chart_release['namespace']] + ] + ) +- for secret in sorted(secrets, key=lambda d: d['metadata']['name']): ++ # We ignore this keeping in line with helm behaviour where the secret malformed is ignored by helm ++ for secret in sorted(filter(lambda d: d.get('data'), secrets), key=lambda d: d['metadata']['name']): + with open(os.path.join(secrets_dir, secret['metadata']['name']), 'w') as f: + f.write(self.middleware.call_sync('k8s.secret.export_to_yaml_internal', secret)) \ No newline at end of file