Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to work out the kinks for this RPM I'm trying to create. Basically, I'm trying to make it so that if mark does not exist on the system, I want to create a mark user account. I've got this in a %pre block in my .spec file:

id mark &>/dev/null
if [ "$?" != "0" ]; then
    echo "Adding 'mark' user..."
    useradd -g $GROUP_ID \
        -s /bin/bash -d mark

Now, after I build the RPM and run rpm -ivh iPackage-1.0.0-1.noarch.rpm, I check the output and see "Adding 'mark' user...", but when I run id mark on the command line, I get id: mark: No such user. Also, /etc/passwd doesn't have a mark account, either. Any ideas?

Edit: See my answer. Turns out, the variables need to be defined.

share|improve this question
There is an error in your script. Add another space before the closing ']'. And make sure you run this script as root. – Matt H Nov 8 '10 at 19:44
Another error is that the useradd command line is obviously incomplete (unless this is an unusual variant of useradd). @Pat: please copy-paste your actual code, and say which distribution you're targetting. – Gilles Nov 8 '10 at 23:52

In my distro useradd should be invoked like this:

# useradd -ms /bin/bash mark

Use -m if you want to create the home directory (see man useradd).

Also as Matt H said, fix that space.

share|improve this answer
up vote 0 down vote accepted

I'm a moron. I had a &2>/dev/null in my code, so I wasn't seeing my errors. After fixing that, I found out that a variable I was using wasn't defined for the -g switch of useradd.

I've edited the question to further demonstrate what I was doing.

share|improve this answer

useradd must be run as root.

I don't use an RPM-based Linux, but I guess your pre-install script is running as an under-privileged user.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .