prepare-suspend 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 `cat /etc/qubes-suspend-module-blacklist`"
  7. fi
  8. if [ -r /rw/config/suspend-module-blacklist ]; then
  9. MODULES_BLACKLIST="$MODULES_BLACKLIST `cat /rw/config/suspend-module-blacklist`"
  10. fi
  11. if [ x"$action" == x"suspend" ]; then
  12. dbus-send --system --print-reply \
  13. --dest=org.freedesktop.NetworkManager \
  14. /org/freedesktop/NetworkManager \
  15. org.freedesktop.NetworkManager.Sleep boolean:true || \
  16. service NetworkManager stop
  17. # Force interfaces down, just in case when NM didn't done it
  18. for if in `ls /sys/class/net|grep -v "lo\|vif"`; do
  19. ip l s $if down
  20. done
  21. LOADED_MODULES=""
  22. for mod in $MODULES_BLACKLIST; do
  23. if lsmod |grep -q $mod; then
  24. LOADED_MODULES="$LOADED_MODULES $mod"
  25. modprobe -r $mod
  26. fi
  27. done
  28. echo $LOADED_MODULES > /var/run/qubes/suspend-modules-loaded
  29. else
  30. for mod in `cat /var/run/qubes/suspend-modules-loaded`; do
  31. modprobe $mod
  32. done
  33. dbus-send --system --print-reply \
  34. --dest=org.freedesktop.NetworkManager \
  35. /org/freedesktop/NetworkManager \
  36. org.freedesktop.NetworkManager.Sleep boolean:false || \
  37. { [ -x /bin/systemctl ] && systemctl start NetworkManager.service; } || service qubes-core-netvm start
  38. fi