%useradd/%groupadd macros

Elan Ruusamäe glen at delfi.ee
Thu Apr 7 00:02:37 CEST 2005


On Thursday 24 February 2005 16:07, Andrzej Krzysztofowicz wrote:
> Elan =?iso-8859-1?q?Ruusam=E4e?= wrote:
> > hi
> >
> > messed it up, produced something:
> > http://glen.alkohol.ee/pld/useradd.txt
>
> Good work.
thanks :)

> > comments welcome!
> > you can ./builder -bb goddammit.spec and later see the scripts result:
> > rpm -qp --scripts goddamnit-6.6.6-77.noarch.rpm | less
> >
> > known issues
> > - you may not do shell-style wrapping with backslashes when using these
> > macros - it is impossible (afaik) to have arguments with spaces
> > - -c is working with spaces (logically) only if it's FINAL argument
>
> Maybe it would help if we assume that no word contained in -c argument may
> begin with "-" ?

version two:
http://glen.alkohol.ee/pld/useradd-2.txt

it includes two samples for workarounds of args with spaces

and your suggestion won't work. as it's rpm who parses cmdline args, and then
passes the words.. and it will switch the arguments order.

and besides that i don't know how to compare the strings in rpm,
ie check for existence of double quote in %2

ie in
%useradd -u 51 -r -d /tmp -s /bin/false -c "HTTP User" -g http apache

'User"' becames %1
'apache' on that line becames %2

would be parsed as:

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 "HTTP apache \
                -g http \
                 \
                User" 1>&2; \
fi; \

one option would be do the argument parsing in shell script using getopt:
$ which getopt | xargs rpm -qf
util-linux-2.12-15
$ rpm -q --whatrequires util-linux
fakeroot-1.2.1-1
rc-scripts-0.4.0.18-0.1




-- 
glen




More information about the pld-devel-en mailing list