2016-10-22 17:43:16 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Source Qubes library.
|
2017-09-30 04:56:02 +02:00
|
|
|
# shellcheck source=init/functions
|
2016-10-22 17:43:16 +02:00
|
|
|
. /usr/lib/qubes/init/functions
|
2012-07-13 14:40:52 +02:00
|
|
|
|
|
|
|
action=$1
|
|
|
|
[ -z "$action" ] && action=suspend
|
|
|
|
|
2013-10-24 04:13:27 +02:00
|
|
|
MODULES_BLACKLIST=""
|
2013-10-23 04:34:47 +02:00
|
|
|
if [ -r /etc/qubes-suspend-module-blacklist ]; then
|
2017-09-30 04:45:31 +02:00
|
|
|
MODULES_BLACKLIST="$MODULES_BLACKLIST $(grep -v '^#' /etc/qubes-suspend-module-blacklist)"
|
2013-10-23 04:34:47 +02:00
|
|
|
fi
|
|
|
|
if [ -r /rw/config/suspend-module-blacklist ]; then
|
2017-09-30 04:45:31 +02:00
|
|
|
MODULES_BLACKLIST="$MODULES_BLACKLIST $(grep -v '^#' /rw/config/suspend-module-blacklist)"
|
2013-10-23 04:34:47 +02:00
|
|
|
fi
|
|
|
|
|
2015-02-05 03:14:41 +01:00
|
|
|
if [ x"$action" = x"suspend" ]; then
|
2016-10-22 17:43:16 +02:00
|
|
|
if qsvc network-manager ; then
|
2016-01-11 19:40:32 +01:00
|
|
|
dbus-send --system --print-reply \
|
|
|
|
--dest=org.freedesktop.NetworkManager \
|
|
|
|
/org/freedesktop/NetworkManager \
|
|
|
|
org.freedesktop.NetworkManager.Sleep boolean:true || \
|
|
|
|
service NetworkManager stop
|
|
|
|
fi
|
2012-07-13 14:40:52 +02:00
|
|
|
# Force interfaces down, just in case when NM didn't done it
|
2017-09-30 04:45:31 +02:00
|
|
|
for intf in /sys/class/net/*; do
|
|
|
|
intf=$(basename "$intf")
|
|
|
|
if [ "$intf" = "lo" ] || [[ "$intf" = "vif"* ]]; then
|
2014-10-27 15:07:06 +01:00
|
|
|
continue
|
|
|
|
fi
|
2017-09-30 04:45:31 +02:00
|
|
|
if [ "$(cat "/sys/class/net/$intf/device/devtype" 2>/dev/null$)" = "vif" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
ip l s "$intf" down
|
2012-07-13 14:40:52 +02:00
|
|
|
done
|
2013-10-23 04:34:47 +02:00
|
|
|
LOADED_MODULES=""
|
|
|
|
for mod in $MODULES_BLACKLIST; do
|
2017-09-30 04:45:31 +02:00
|
|
|
if lsmod |grep -q "$mod"; then
|
2013-10-23 04:34:47 +02:00
|
|
|
LOADED_MODULES="$LOADED_MODULES $mod"
|
2017-09-30 04:45:31 +02:00
|
|
|
modprobe -r "$mod"
|
2013-10-23 04:34:47 +02:00
|
|
|
fi
|
|
|
|
done
|
2017-09-30 04:45:31 +02:00
|
|
|
echo "$LOADED_MODULES" > /var/run/qubes/suspend-modules-loaded
|
2012-07-13 14:40:52 +02:00
|
|
|
else
|
2017-09-30 04:45:31 +02:00
|
|
|
# shellcheck disable=SC2013
|
|
|
|
for mod in $(cat /var/run/qubes/suspend-modules-loaded); do
|
|
|
|
modprobe "$mod"
|
2013-10-23 04:34:47 +02:00
|
|
|
done
|
2016-10-22 17:43:16 +02:00
|
|
|
if qsvc network-manager ; then
|
2016-01-11 19:40:32 +01:00
|
|
|
dbus-send --system --print-reply \
|
|
|
|
--dest=org.freedesktop.NetworkManager \
|
|
|
|
/org/freedesktop/NetworkManager \
|
|
|
|
org.freedesktop.NetworkManager.Sleep boolean:false || \
|
2016-10-22 17:43:16 +02:00
|
|
|
{ under_systemd && systemctl start NetworkManager.service; } || service qubes-core-netvm start
|
2016-01-11 19:40:32 +01:00
|
|
|
fi
|
2012-07-13 14:40:52 +02:00
|
|
|
fi
|