%useradd/%groupadd macros

Elan Ruusamäe glen at delfi.ee
Sat Apr 9 00:19:15 CEST 2005


version four
http://glen.alkohol.ee/pld/useradd-4.txt

found out that user being useradded is always last rpm argument %{%#}}
but impossible to catch it in rpm, so shell magic cames into play.

yeah i know. it's very ugly :)

the A=`cat <<'EOF'` magic is needed to get rpm args to $A, because it's 
usually broken string (begins with quote, but doesn't end with)

string cutting could be done probably better with awk.



%useradd -u 51 -r -d %{httpdir} -s /bin/false -c "HTTP User #2" -g http apache

 
user=apache 
comment="HTTP User #2"  
if [ -n "`id -u $user 2>/dev/null`" ]; then 
        if [ "`id -u $user`" != "51" ]; then 
                echo "Error: user $user doesn't have uid=51. Correct this 
before installing goddamnit." 1>&2 
                exit 1 
        fi 
else 
        echo "Adding user $user UID=51." 
        /usr/sbin/useradd \
                -u 51 \
                -r \
                -d /tmp \
                -s /bin/false \
                -c "$comment" \
                -g http \
                 \
                $user 1>&2 \
fi



-- 
glen




More information about the pld-devel-en mailing list