0

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
fi

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.

2
  • 1
    There is an error in your script. Add another space before the closing ']'. And make sure you run this script as root.
    – hookenz
    Nov 8, 2010 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. Nov 8, 2010 at 23:52

3 Answers 3

0

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.

0

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.

0

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.

You must log in to answer this question.

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