#!/bin/bash

## Copyright (C) 2019 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## Similar to live-mode-to-read-only.

set -x

error_handler() {
   exit_code="1"
}

trap error_handler ERR

exit_code="0"

source /usr/libexec/helper-scripts/live-mode.sh

if [ "$live_status_detected" = "true" ]; then
   ## Live mode.
   true "$0: INFO: Live mode detected. Doing nothing. Exiting."
   exit 0
fi
## Persistent mode.

vm_names_list="$(virsh list --all | awk '{print $2}'| grep -v Name)"

for vm_name_item in $vm_names_list ; do
   virt-xml "$vm_name_item" --edit --disk readonly=off
done

chmod --verbose --recursive ug+w "/var/lib/libvirt/images/Whonix-Gateway.qcow2"
chmod --verbose --recursive ug+w "/var/lib/libvirt/images/Whonix-Workstation.qcow2"

exit "$exit_code"
