qubes-download-dom0-updates.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. export LC_ALL=C
  10. while [ -n "$1" ]; do
  11. case "$1" in
  12. --doit)
  13. DOIT=1
  14. ;;
  15. --nogui)
  16. GUI=0
  17. ;;
  18. --gui)
  19. GUI=1
  20. ;;
  21. --clean)
  22. CLEAN=1
  23. ;;
  24. --check-only)
  25. CHECK_ONLY=1
  26. ;;
  27. -*)
  28. OPTS="$OPTS $1"
  29. ;;
  30. *)
  31. PKGLIST="$PKGLIST $1"
  32. ;;
  33. esac
  34. shift
  35. done
  36. if ! [ -d "$DOM0_UPDATES_DIR" ]; then
  37. echo "Dom0 updates dir does not exists: $DOM0_UPDATES_DIR" >&2
  38. exit 1
  39. fi
  40. mkdir -p $DOM0_UPDATES_DIR/etc
  41. sed -i '/^reposdir\s*=/d' $DOM0_UPDATES_DIR/etc/yum.conf
  42. # Rebuild rpm database in case of different rpm version
  43. rm -f $DOM0_UPDATES_DIR/var/lib/rpm/__*
  44. rpm --root=$DOM0_UPDATES_DIR --rebuilddb
  45. if [ "$CLEAN" = "1" ]; then
  46. yum $OPTS clean all
  47. rm -f $DOM0_UPDATES_DIR/packages/*
  48. fi
  49. if [ "x$PKGLIST" = "x" ]; then
  50. echo "Checking for dom0 updates..." >&2
  51. UPDATES=`yum $OPTS check-update -q | cut -f 1 -d ' ' | grep -v "^Obsoleting"`
  52. else
  53. PKGS_FROM_CMDLINE=1
  54. fi
  55. if [ -z "$PKGLIST" -a -z "$UPDATES" ]; then
  56. # No new updates
  57. if [ "$GUI" = 1 ]; then
  58. zenity --info --text="No new updates available"
  59. fi
  60. exit 0
  61. fi
  62. if [ "$CHECK_ONLY" = "1" ]; then
  63. echo "Available updates: $PKGLIST"
  64. exit 100
  65. fi
  66. if [ "$DOIT" != "1" -a "$PKGS_FROM_CMDLINE" != "1" ]; then
  67. zenity --question --title="Qubes Dom0 updates" \
  68. --text="There are updates for dom0 available, do you want to download them now?" || exit 0
  69. fi
  70. YUM_ACTION=upgrade
  71. if [ "$PKGS_FROM_CMDLINE" == 1 ]; then
  72. GUI=0
  73. YUM_ACTION=install
  74. fi
  75. mkdir -p "$DOM0_UPDATES_DIR/packages"
  76. set -e
  77. if [ "$GUI" = 1 ]; then
  78. ( echo "1"
  79. fakeroot yum $YUM_ACTION -y --downloadonly --downloaddir="$DOM0_UPDATES_DIR/packages" $OPTS $PKGLIST
  80. echo 100 ) | zenity --progress --pulsate --auto-close --auto-kill \
  81. --text="Downloading updates for Dom0, please wait..." --title="Qubes Dom0 updates"
  82. else
  83. fakeroot yum $YUM_ACTION -y --downloadonly --downloaddir="$DOM0_UPDATES_DIR/packages" $OPTS $PKGLIST
  84. fi
  85. if ls $DOM0_UPDATES_DIR/packages/*.rpm > /dev/null 2>&1; then
  86. /usr/lib/qubes/qrexec-client-vm dom0 qubes.ReceiveUpdates /usr/lib/qubes/qfile-agent $DOM0_UPDATES_DIR/packages/*.rpm
  87. else
  88. echo "No packages downloaded"
  89. fi