qubes-download-dom0-updates.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. # Rebuild rpm database in case of different rpm version
  42. rm -f $DOM0_UPDATES_DIR/var/lib/rpm/__*
  43. rpm --root=$DOM0_UPDATES_DIR --rebuilddb
  44. if [ "$CLEAN" = "1" ]; then
  45. yum $OPTS clean all
  46. rm -f $DOM0_UPDATES_DIR/packages/*
  47. fi
  48. if [ "x$PKGLIST" = "x" ]; then
  49. echo "Checking for dom0 updates..." >&2
  50. PKGLIST=`yum $OPTS check-update -q | cut -f 1 -d ' '`
  51. else
  52. PKGS_FROM_CMDLINE=1
  53. fi
  54. if [ -z "$PKGLIST" ]; then
  55. # No new updates
  56. if [ "$GUI" = 1 ]; then
  57. zenity --info --text="No new updates available"
  58. fi
  59. exit 0
  60. fi
  61. if [ "$CHECK_ONLY" = "1" ]; then
  62. echo "Available updates: $PKGLIST"
  63. exit 100
  64. fi
  65. if [ "$DOIT" != "1" -a "$PKGS_FROM_CMDLINE" != "1" ]; then
  66. zenity --question --title="Qubes Dom0 updates" \
  67. --text="There are updates for dom0 available, do you want to download them now?" || exit 0
  68. fi
  69. if [ "$PKGS_FROM_CMDLINE" == 1 ]; then
  70. GUI=0
  71. fi
  72. mkdir -p "$DOM0_UPDATES_DIR/packages"
  73. set -e
  74. if [ "$GUI" = 1 ]; then
  75. ( echo "1"
  76. yumdownloader --resolve --destdir "$DOM0_UPDATES_DIR/packages" $OPTS $PKGLIST
  77. echo 100 ) | zenity --progress --pulsate --auto-close --auto-kill \
  78. --text="Downloading updates for Dom0, please wait..." --title="Qubes Dom0 updates"
  79. else
  80. yumdownloader --resolve --destdir "$DOM0_UPDATES_DIR/packages" $OPTS $PKGLIST
  81. fi
  82. if ls $DOM0_UPDATES_DIR/packages/*.rpm > /dev/null 2>&1; then
  83. /usr/lib/qubes/qrexec-client-vm dom0 qubes.ReceiveUpdates /usr/lib/qubes/qfile-agent $DOM0_UPDATES_DIR/packages/*.rpm
  84. else
  85. echo "No packages downloaded"
  86. fi