0

im just try to figure out who call root or sudo,cuz i dont want to set some things in root's home folder, when i try this in terminal its work perfect, but doesnt work for spec, what im doing wrong?

terminal:

[Mcfly@Mcfly ~]$ whoami=$(who am i | awk '{print $1}')
[Mcfly@Mcfly ~]$ echo $whoami
Mcfly

SPEC

%define whoami %(who am i | awk '{print $1}')
echo "The user that built this is %{whoami}"
the user that built this is '%{whoami}'

can you help me ?

or there is a easy way to know the user path in rpm-spec, i mean /home/mcfly/ no /root?

regards

2 Answers2

0

I'm not a Linux guru and you don't explain how your current approach fails to work but the id command looks a simpler alternative.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Thanks for the fast reply. – Carlos Dueñas Feb 11 '13 at 16:39
  • Thanks for the fast reply. (oh god this thing post when i press enter button) well, the Problem here is, when i try to use the first part if code from terminal, in RPM-SPEC, if i run the whole script (%prep and %post) from rpm-spec in terminal run perfec, the problem comes when it get build in a rpm, i get "" in the user variable. I try to use this to make a folder inside the user home folder(like /home/mcfly/THEFOLDER). also need to be the "normal" user, in other words, the rpm its executed by root, or using sudo, and whit id command i dont know how a method to sget who call sudo – Carlos Dueñas Feb 11 '13 at 16:46
  • 1
    The only time a non-root user would be doing an install is if they are playing around with the base install directory, etc, which is going to cause all kinds of problems anyway... – Aaron D. Marasco Feb 12 '13 at 01:28
  • well, i find a way to work around whit the problem of the username in the variable, now a new problem come whit this, i move the script part to the %post part, its work great in my computer, but when i execute the rpm in another machine, it look for my user, i mean, the variable still have my username, so its impossible at this moment to beed used in a diferent user... i just did this whit the variable "%define whoami %(eval who am i | awk '{print $1}')" – Carlos Dueñas Feb 12 '13 at 14:18
  • @AaronD.Marasco in my rpm, i just need to know how is the non-root user executing the rpm, because some archives of configuration and scripts need to be in the home folder, that archives and configuration can't cause problems to the system, actually if that configuration doesnt exist in the home folder, the app dont run. thanks for the reply. – Carlos Dueñas Feb 12 '13 at 17:47
0

What you want is $SUDO_USER, a variable conveniently set by sudo for you.

If you want to ensure that root doesn't do the install, put this in your %pre:

if [ -z "$SUDO_USER" ]; then echo "Please use sudo to ensure configuration files are installed in proper location."; exit 99; fi
if [ z"$SUDO_USER" == "zroot" ]; then echo "Please use sudo from a non-root account to ensure configuration files are installed in proper location."; exit 99; fi
Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39
  • BTW, for various reasons I think that putting things into a user's home directory isn't the best idea, but I won't get into it here. – Aaron D. Marasco Feb 13 '13 at 02:24
  • thanks so much for the reply, actually this is what i need, the $SUDO_USER variable can handle this has a sudo user, i just copy&paste the code and i get a build error, but doesn't matter, now i can share the rpm and install in another machine. – Carlos Dueñas Feb 13 '13 at 15:17