qubes-download-dom0-updates.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. YUM_ACTION=
  10. export LC_ALL=C
  11. while [ -n "$1" ]; do
  12. case "$1" in
  13. --doit)
  14. DOIT=1
  15. ;;
  16. --nogui)
  17. GUI=0
  18. ;;
  19. --gui)
  20. GUI=1
  21. ;;
  22. --clean)
  23. CLEAN=1
  24. ;;
  25. --check-only)
  26. CHECK_ONLY=1
  27. ;;
  28. --action=*)
  29. YUM_ACTION=${1#--action=}
  30. ;;
  31. -*)
  32. OPTS="$OPTS $1"
  33. ;;
  34. *)
  35. PKGLIST="$PKGLIST $1"
  36. if [ -z "$YUM_ACTION" ]; then
  37. YUM_ACTION=install
  38. fi
  39. ;;
  40. esac
  41. shift
  42. done
  43. if [ -z "$YUM_ACTION" ]; then
  44. YUM_ACTION=upgrade
  45. fi
  46. if ! [ -d "$DOM0_UPDATES_DIR" ]; then
  47. echo "Dom0 updates dir does not exists: $DOM0_UPDATES_DIR" >&2
  48. exit 1
  49. fi
  50. mkdir -p $DOM0_UPDATES_DIR/etc
  51. sed -i '/^reposdir\s*=/d' $DOM0_UPDATES_DIR/etc/yum.conf
  52. if [ -e /etc/debian_version ]; then
  53. # Default rpm configuration on Debian uses ~/.rpmdb for rpm database (as
  54. # rpm isn't native package manager there)
  55. mkdir -p "$DOM0_UPDATES_DIR$HOME"
  56. ln -nsf "$DOM0_UPDATES_DIR/var/lib/rpm" "$DOM0_UPDATES_DIR$HOME/.rpmdb"
  57. fi
  58. # Rebuild rpm database in case of different rpm version
  59. rm -f $DOM0_UPDATES_DIR/var/lib/rpm/__*
  60. rpm --root=$DOM0_UPDATES_DIR --rebuilddb
  61. if [ "$CLEAN" = "1" ]; then
  62. yum $OPTS clean all
  63. rm -f $DOM0_UPDATES_DIR/packages/*
  64. fi
  65. if [ "x$PKGLIST" = "x" ]; then
  66. echo "Checking for dom0 updates..." >&2
  67. UPDATES=`yum $OPTS check-update -q | cut -f 1 -d ' ' | grep -v "^Obsoleting"`
  68. else
  69. PKGS_FROM_CMDLINE=1
  70. fi
  71. if [ -z "$PKGLIST" -a -z "$UPDATES" ]; then
  72. echo "No new updates available"
  73. if [ "$GUI" = 1 ]; then
  74. zenity --info --text="No new updates available"
  75. fi
  76. exit 0
  77. fi
  78. if [ "$CHECK_ONLY" = "1" ]; then
  79. echo "Available updates: $PKGLIST"
  80. exit 100
  81. fi
  82. if [ "$DOIT" != "1" -a "$PKGS_FROM_CMDLINE" != "1" ]; then
  83. zenity --question --title="Qubes Dom0 updates" \
  84. --text="There are updates for dom0 available, do you want to download them now?" || exit 0
  85. fi
  86. YUM_COMMAND="fakeroot yum $YUM_ACTION -y --downloadonly --downloaddir=$DOM0_UPDATES_DIR/packages"
  87. # check for --downloadonly option - if not supported (Debian), fallback to
  88. # yumdownloader
  89. if ! yum --help | grep -q downloadonly; then
  90. if [ "$YUM_ACTION" != "install" -a "$YUM_ACTION" != "upgrade" ]; then
  91. echo "ERROR: yum version installed in VM $HOSTNAME does not suppport --downloadonly option" >&2
  92. echo "ERROR: only 'install' and 'upgrade' actions supported ($YUM_ACTION not)" >&2
  93. if [ "$GUI" = 1 ]; then
  94. zenity --error --text="yum version too old for '$YUM_ACTION' action, see console for details"
  95. fi
  96. exit 1
  97. fi
  98. if [ "$YUM_ACTION" = "upgrade" ]; then
  99. PKGLIST=$UPDATES
  100. fi
  101. YUM_COMMAND="yumdownloader --destdir=$DOM0_UPDATES_DIR/packages --resolve"
  102. fi
  103. mkdir -p "$DOM0_UPDATES_DIR/packages"
  104. set -e
  105. if [ "$GUI" = 1 ]; then
  106. ( echo "1"
  107. $YUM_COMMAND $OPTS $PKGLIST
  108. echo 100 ) | zenity --progress --pulsate --auto-close --auto-kill \
  109. --text="Downloading updates for Dom0, please wait..." --title="Qubes Dom0 updates"
  110. else
  111. $YUM_COMMAND $OPTS $PKGLIST
  112. fi
  113. if ls $DOM0_UPDATES_DIR/packages/*.rpm > /dev/null 2>&1; then
  114. /usr/lib/qubes/qrexec-client-vm dom0 qubes.ReceiveUpdates /usr/lib/qubes/qfile-agent $DOM0_UPDATES_DIR/packages/*.rpm
  115. else
  116. echo "No packages downloaded"
  117. fi