I have following script saved it /lib/systemd/system-sleep/ directory, to run after every wake-up from suspend:
#!/bin/bash
if [ "$1" == "post" ]; then
sleep 5
cni=$(ip link | grep "state UP" | grep --only-matching --perl-regexp '(?<=:).*(?=:)' | tr --delete ' ')
#cni=connected(UP) network interface(s)
if [ -z "$cni" ] && [ $(nmcli radio wifi) == "disabled" ]; then
#export DISPLAY=:0
#su -c - my_user nmcli radio wifi on
nmcli radio wifi on
fi
fi
I tested it, logged in as regular user, then in terminal su - root and run it with switch "post" it works as expected and when there is no network adapter connected and wifi is down, it enables WIFI. However it's not working when I actually suspend and wake up my laptop. I was reading that maybe I have to define DISPLAY variable and run it as regular user, but still it didn't help. Any idea what am I missing here ?
EDIT - added shebang at the beginning of script, forgot to write it here, but it's my in script
Ubuntu 17.04 kernel 4.10.0-21-generic