Search code examples
terminalcentosrpm-spec

Who am i -- RPM-SPEC


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


Solution

  • 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