qubes-set-updates 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/python2
  2. # -*- encoding: utf8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2014 Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. from optparse import OptionParser
  24. import optparse
  25. import os
  26. import sys
  27. from qubes.qubes import QubesVmCollection
  28. from qubes.qubesutils import updates_vms_toggle,updates_dom0_toggle,\
  29. updates_dom0_status,updates_vms_status
  30. from qubes.qubes import vmm
  31. def main():
  32. usage = "%prog enable|disable|status\n"\
  33. " Enable or disable globally checking for updates (both dom0 and VM)"
  34. parser = OptionParser (usage)
  35. parser.add_option("--offline-mode", dest="offline_mode",
  36. action="store_true", default=False,
  37. help=optparse.SUPPRESS_HELP)
  38. (options, args) = parser.parse_args()
  39. if len(args) < 1:
  40. parser.error("You must provide an action")
  41. action = args[0]
  42. if action not in ['enable', 'disable', 'status']:
  43. parser.error("Invalid action")
  44. if options.offline_mode:
  45. vmm.offline_mode = True
  46. qvm_collection = QubesVmCollection()
  47. if action == 'status':
  48. qvm_collection.lock_db_for_reading()
  49. else:
  50. qvm_collection.lock_db_for_writing()
  51. qvm_collection.load()
  52. if action == 'enable':
  53. updates_dom0_toggle(qvm_collection, True)
  54. updates_vms_toggle(qvm_collection, True)
  55. elif action == 'disable':
  56. updates_dom0_toggle(qvm_collection, False)
  57. updates_vms_toggle(qvm_collection, False)
  58. else:
  59. if updates_dom0_status(qvm_collection):
  60. print "dom0: enabled"
  61. else:
  62. print "dom0: disabled"
  63. status_vms = updates_vms_status(qvm_collection)
  64. if status_vms is None:
  65. print "vms: mixed"
  66. elif status_vms:
  67. print "vms: enabled"
  68. else:
  69. print "vms: disabled"
  70. if action != 'status':
  71. qvm_collection.save()
  72. qvm_collection.unlock_db()
  73. if __name__ == "__main__":
  74. main()