When I calling my script with sudo
it would set $USER
to root.
$ sudo ./myscript.sh
I tried the chown ${USER:=$(/usr/bin/id -run)}:$USER /var/www/$sitename
but it would still return root.
I found if I used who
with awk
I was able to get the current user that called the script with sudo
.
currentuser=$(who | awk '{print $1}')}
chown -R $currentuser:$currentuser /var/www/$sitename`