On Ubuntu 13.10, I have all of my gsettings in a file, mygset.sh. For example, mygset.sh contains many lines such as
gsettings set com.canonical.Unity.Launcher favorites "['application://nautilus.desktop', 'application://firefox.desktop', 'application://chromium-browser.desktop', 'unity://running-apps', 'unity://expo-icon', 'unity://devices']"
I have a master install script that I have to run with sudo (e.g. it does sudo apt-get install).
From that master install script I want to call mygset.sh
. However, no matter how I call it it is not changing the settings for my user. I think it is changing the settings of root. I've tried it like (from masterinstall.sh
which is being run as sudo ./masterinstall.sh
):
sudo -u "wang" ./mygset.sh
sudo -u "wang" bash -c ./mygset.sh
Neither of those works (they run without error and change the setting [I check within the script with gsetting get] but not for user "wang").
When I run mygset.sh
from the command line (without sudo: bash ./mygset.sh
). It works perfectly. Why is there this difference and what can I do to solve it within masterinstall.sh
?
By default sudo sets the uid and the gid to the user you've specified but it doesn't change the environment settings etc.
Suggest you try -H
first, which sets the $HOME
variable to the target user:
sudo -u "wang" -H ./myget.sh
If that doesn't work, try -i
which is supposed to simulate the initial login.
A slightly different tack, which I've found sometimes works, is to use su
:
sudo su - wang
/full/path/to/myget.sh
exit
You'll need to use the full path to the script because the su command changes the current working directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With