prepare-suspend 1.7 KB

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