简体   繁体   中英

network manager dispatcher script fail to restart the awesome wm

I want the awesome wm to run with different configuration when the network environment is changed. Therefore I wrote a script in the network manager dispatcher so that when the network environment change the script will be executed;

#!/bin/bash
# Restart awesome through awesome-client

USER=dreamingo

awesome_restart(){
    /bin/su $USER -c "echo 'local awful = require (\"awful\"); return awful.util.restart()' | awesome-client"
}

#To check the cable insert or not
wire_insert_state=$(cat /sys/class/net/eth0/carrier)
#Check which config the current awesome taking(wired or wireless)
current_config=$(cat ~/.config/awesome/flag)

# if [[ $wire_insert_state = 1 ]] && [[ $current_config == "wireless" ]];then
if [[ $wire_insert_state = 1 ]];then
    cp /home/dreamingo/.config/awesome/rc.lua.wire /home/dreamingo/.config/awesome/rc.lua
    echo wired > ~/.config/awesome/flag
    awesome_restart

# elif [[ $wire_insert_state = 0 ]] && [[ $current_config == "wired" ]];then
elif [[ $wire_insert_state = 0 ]];then
    cp /home/dreamingo/.config/awesome/rc.lua.wireless /home/dreamingo/.config/awesome/rc.lua
    echo wireless > ~/.config/awesome/flag
    awesome_restart
fi

However, this script does run when the enviroment change, but the awesome wm won't restart.

I thought it was the reason that the script was executed by root, therefore I use the following command:

/bin/su $USER -c "echo 'local awful = require (\"awful\"); return awful.util.restart()' | awesome-client"

This command will work(restart the awesome wm) when I su to root; However, when i use:

sudo ./02check_wireless    #02check_wireless was the name of the script

to run the script, the script fail to restart wm; But when i just run it as current user(dreamingo), it works;

Moreover, both the above result(success or not), the script will output:

Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.naquadah.awesome.awful was not provided by any .service files

I thought the failed one also try to restart the awesome, but something covered or stop it....

This variant works fine for me with awesome 3.5.5 when I run it as root

#!/bin/bash
# Restart awesome through awesome-client

USER=my_username_here

awesome_restart(){
    /bin/su $USER -c "echo 'awesome.restart()' | awesome-client"
}

awesome_restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM