prepare-suspend 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 if in `ls /sys/class/net|grep -v "lo\|vif"`; do
  23. if [ "`cat /sys/class/net/$if/device/devtype 2>/dev/null`" = "vif" ]; then
  24. continue
  25. fi
  26. ip l s $if down
  27. done
  28. LOADED_MODULES=""
  29. for mod in $MODULES_BLACKLIST; do
  30. if lsmod |grep -q $mod; then
  31. LOADED_MODULES="$LOADED_MODULES $mod"
  32. modprobe -r $mod
  33. fi
  34. done
  35. echo $LOADED_MODULES > /var/run/qubes/suspend-modules-loaded
  36. else
  37. for mod in `cat /var/run/qubes/suspend-modules-loaded`; do
  38. modprobe $mod
  39. done
  40. if qsvc network-manager ; then
  41. dbus-send --system --print-reply \
  42. --dest=org.freedesktop.NetworkManager \
  43. /org/freedesktop/NetworkManager \
  44. org.freedesktop.NetworkManager.Sleep boolean:false || \
  45. { under_systemd && systemctl start NetworkManager.service; } || service qubes-core-netvm start
  46. fi
  47. fi