Hi everybody.
I've tried to google for answers first but without any luck, so if I missed an answer please excuse and redirect me.
My Situation
I'm writing an post-install tweak script in /bin/bash, and because I don't want to have 15 sudo's and
be asked for the password to many times etc. I'm running it as root
Code:
sudo bash MyPostTweaks.sh
The script looks basically like this:
Code:
#!/bin/bash
apt-apt-repository -y $ppa_one
apt-get update
apt-get install -y $app_one
#Now some tweaks for the user
wget $WebAddress --directory-prefix=$HOME/Pictures
# or something like
cp ../myconfs/myapp2.conf $HOME/.config/myapp2/
Now my Problem
I have had problems where programs have worked badly, by not having permissions, or even worse even though the *.desktop was install and present /usr/share/applications clicking on it would not work. I began to notice whats wrong because it tried to run the program from the terminal and read some error messages. The same problem was not present if I stated the program from a second user account. I understand that the reason for the permissions/privileges issues is the script being ran as root. I also know about sudo chmod or sudo chown but since I don't know where the issue lies because I've even tried
Code:
sudo chmod -R 755 ~/* && sudo chown -R octius4u:octius4u ~/*
.
My Question
While in user octius4u i run the script as sudo bash MyPostTweaks.sh essentially putting me in root's account. If I run the script on a computer where the user name has changed, for example because I got bored of the old user name, how can I determine it?
In order to run some thing like
Code:
sudo -u $NormalUser cp ../myconfs/myapp2.conf $HOME/.config/myapp2/
Can I use or combine some of the following commands?
w
id -un
whoami
in order to get something similar to
Code:
if [ $w_user = $(id -un) ]; then; sudo -u $w_user cp $path/$file /$newpath
Thank you in advance for any help or insights you can provide.
Bookmarks