prepare-suspend 1.9 KB

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