qubes_download_dom0_updates.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. DOM0_UPDATES_DIR=/var/lib/qubes/dom0-updates
  3. DOIT=0
  4. GUI=1
  5. CLEAN=0
  6. CHECK_ONLY=0
  7. OPTS="--installroot $DOM0_UPDATES_DIR --config=$DOM0_UPDATES_DIR/etc/yum.conf"
  8. PKGLIST=
  9. while [ -n "$1" ]; do
  10. case "$1" in
  11. --doit)
  12. DOIT=1
  13. ;;
  14. --nogui)
  15. GUI=0
  16. ;;
  17. --gui)
  18. GUI=1
  19. ;;
  20. --clean)
  21. CLEAN=1
  22. ;;
  23. --check-only)
  24. CHECK_ONLY=1
  25. ;;
  26. -*)
  27. OPTS="$OPTS $1"
  28. ;;
  29. *)
  30. PKGLIST="$PKGLIST $1"
  31. ;;
  32. esac
  33. shift
  34. done
  35. if ! [ -d "$DOM0_UPDATES_DIR" ]; then
  36. echo "Dom0 updates dir does not exists: $DOM0_UPDATES_DIR" >&2
  37. exit 1
  38. fi
  39. mkdir -p $DOM0_UPDATES_DIR/etc
  40. sed -i '/^reposdir\s*=/d' $DOM0_UPDATES_DIR/etc/yum.conf
  41. if [ "$CLEAN" = "1" ]; then
  42. yum $OPTS clean all
  43. rm -f $DOM0_UPDATES_DIR/packages/*
  44. fi
  45. if [ "x$PKGLIST" = "x" ]; then
  46. echo "Checking for dom0 updates..." >&2
  47. PKGLIST=`yum $OPTS check-update -q | cut -f 1 -d ' '`
  48. else
  49. PKGS_FROM_CMDLINE=1
  50. fi
  51. if [ -z "$PKGLIST" ]; then
  52. # No new updates
  53. exit 0
  54. fi
  55. if [ "$CHECK_ONLY" = "1" ]; then
  56. echo "Available updates: $PKGLIST"
  57. exit 100
  58. fi
  59. if [ "$DOIT" != "1" -a "$PKGS_FROM_CMDLINE" != "1" ]; then
  60. zenity --question --title="Qubes Dom0 updates" \
  61. --text="There are updates for dom0 available, do you want to download them now?" || exit 0
  62. fi
  63. if [ "$PKGS_FROM_CMDLINE" == 1 ]; then
  64. GUI=0
  65. fi
  66. mkdir -p "$DOM0_UPDATES_DIR/packages"
  67. set -e
  68. if [ "$GUI" = 1 ]; then
  69. ( echo "1"
  70. yumdownloader --resolve --destdir "$DOM0_UPDATES_DIR/packages" $OPTS $PKGLIST
  71. echo 100 ) | zenity --progress --pulsate --auto-close --auto-kill \
  72. --text="Downloading updates for Dom0, please wait..." --title="Qubes Dom0 updates"
  73. else
  74. yumdownloader --resolve --destdir "$DOM0_UPDATES_DIR/packages" $OPTS $PKGLIST
  75. fi
  76. if ls $DOM0_UPDATES_DIR/packages/*.rpm > /dev/null 2>&1; then
  77. /usr/lib/qubes/qrexec_client_vm dom0 qubes.ReceiveUpdates /usr/lib/qubes/qfile-agent $DOM0_UPDATES_DIR/packages/*.rpm
  78. else
  79. echo "No packages downloaded"
  80. fi