qubes-set-updates 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. import os
  24. import sys
  25. from qubes.qubes import QubesVmCollection
  26. from qubes.qubesutils import updates_vms_toggle,updates_dom0_toggle,\
  27. updates_dom0_status
  28. def usage():
  29. print "Usage: qubes-set-updates enable|disable|status"
  30. print " Enable or disable globally checking for updates (both dom0 and VM)"
  31. print " Status option checks only dom0 updates status"
  32. def main():
  33. if len(sys.argv) < 2:
  34. usage()
  35. return 1
  36. action = sys.argv[1]
  37. if action not in ['enable', 'disable', 'status']:
  38. usage()
  39. return 1
  40. qvm_collection = QubesVmCollection()
  41. if action == 'status':
  42. qvm_collection.lock_db_for_reading()
  43. else:
  44. qvm_collection.lock_db_for_writing()
  45. qvm_collection.load()
  46. if action == 'enable':
  47. updates_dom0_toggle(qvm_collection, True)
  48. updates_vms_toggle(qvm_collection, True)
  49. elif action == 'disable':
  50. updates_dom0_toggle(qvm_collection, False)
  51. updates_vms_toggle(qvm_collection, False)
  52. else:
  53. if updates_dom0_status(qvm_collection):
  54. print "enabled"
  55. else:
  56. print "disabled"
  57. if action != 'status':
  58. qvm_collection.save()
  59. qvm_collection.unlock_db()
  60. if __name__ == "__main__":
  61. main()