prepare-suspend 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. # Source Qubes library.
  3. # shellcheck source=init/functions
  4. . /usr/lib/qubes/init/functions
  5. action=$1
  6. [ -z "$action" ] && action=suspend
  7. MODULES_BLACKLIST=""
  8. if [ -r /etc/qubes-suspend-module-blacklist ]; then
  9. MODULES_BLACKLIST="$MODULES_BLACKLIST $(grep -v '^#' /etc/qubes-suspend-module-blacklist)"
  10. fi
  11. if [ -r /rw/config/suspend-module-blacklist ]; then
  12. MODULES_BLACKLIST="$MODULES_BLACKLIST $(grep -v '^#' /rw/config/suspend-module-blacklist)"
  13. fi
  14. if [ x"$action" = x"suspend" ]; then
  15. if qsvc network-manager ; then
  16. dbus-send --system --print-reply \
  17. --dest=org.freedesktop.NetworkManager \
  18. /org/freedesktop/NetworkManager \
  19. org.freedesktop.NetworkManager.Sleep boolean:true || \
  20. service NetworkManager stop
  21. fi
  22. # Force interfaces down, just in case when NM didn't done it
  23. for intf in /sys/class/net/*; do
  24. intf=$(basename "$intf")
  25. if [ "$intf" = "lo" ] || [[ "$intf" = "vif"* ]]; then
  26. continue
  27. fi
  28. if [ "$(cat "/sys/class/net/$intf/device/devtype" 2>/dev/null$)" = "vif" ]; then
  29. continue
  30. fi
  31. ip l s "$intf" down
  32. done
  33. LOADED_MODULES=""
  34. for mod in $MODULES_BLACKLIST; do
  35. if lsmod |grep -q "$mod"; then
  36. LOADED_MODULES="$LOADED_MODULES $mod"
  37. modprobe -r "$mod"
  38. fi
  39. done
  40. echo "$LOADED_MODULES" > /var/run/qubes/suspend-modules-loaded
  41. else
  42. # shellcheck disable=SC2013
  43. for mod in $(cat /var/run/qubes/suspend-modules-loaded); do
  44. modprobe "$mod"
  45. done
  46. if qsvc network-manager ; then
  47. dbus-send --system --print-reply \
  48. --dest=org.freedesktop.NetworkManager \
  49. /org/freedesktop/NetworkManager \
  50. org.freedesktop.NetworkManager.Sleep boolean:false || \
  51. { under_systemd && systemctl start NetworkManager.service; } || service qubes-core-netvm start
  52. fi
  53. fi