prepare-suspend 1.6 KB

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