Bug 27671 - buggy preinstall scriptlet
Summary: buggy preinstall scriptlet
Status: CLOSED FIXED
Alias: None
Product: Sisyphus
Classification: Development
Component: jetty (show other bugs)
Version: unstable
Hardware: all Linux
: P3 normal
Assignee: viy
QA Contact: qa-sisyphus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-27 08:53 MSK by (GalaxyMaster)
Modified: 2012-09-21 20:48 MSK (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description (GalaxyMaster) 2012-08-27 08:53:25 MSK
The jetty6 package has definitely a buggy preinstall scriptlet:
===
[root@galaxy ~]# rpm -q --scripts jetty6
preinstall scriptlet (through /bin/sh):
/usr/sbin/groupadd -r -r jetty &>/dev/null || :
# Use /bin/sh so init script will start properly.
/usr/sbin/useradd -r -s /bin/sh -d /usr/share/jetty6 -M          \
                    -r jetty &>/dev/null || :
===

Although the first command works (despite the redundant "-r"), the second doesn't.  The useradd command complains that the jetty group already exists and that if we want to assign the group to this user we need to use '-g jetty', but nobody sees it since everything is redirected to /dev/null.

BTW< I believe redirecting everything to /dev/null is a very bad idea for a pre/post scriptlets.  I'd prefer to see >/dev/null here with error messages still directed to the console.
Comment 1 viy 2012-08-27 19:58:40 MSK
Thank you very much for the report, 
fixed in jetty6-6.1.26-alt8_1jpp6.src.rpm
and I will be more careful from now on.
Comment 2 (GalaxyMaster) 2012-08-31 00:53:00 MSK
Well, it's not there yet :(.  The latest package has the following scriptlets:
===
[root@galaxy ~]# rpm -q --scripts jetty
preinstall scriptlet (through /bin/sh):
groupadd -r jetty || :
# Use /bin/sh so init script will start properly.
useradd  -r -s /bin/sh -d /usr/share/jetty -M          \
                    -g jetty jetty || :
postinstall scriptlet (through /bin/sh):
[ -x /sbin/chkconfig ] && /sbin/chkconfig --add jetty
preuninstall scriptlet (through /bin/sh):
if [ $1 = 0 ]; then
    [ -f /var/lock/subsys/jetty ] && /etc/rc.d/init.d/jetty stop
    [ -f /etc/rc.d/init.d/jetty -a -x /sbin/chkconfig ] && /sbin/chkconfig --del jetty

    /usr/sbin/userdel jetty >> /dev/null 2>&1 || :
fi
postuninstall scriptlet (through /bin/sh):
#userdel  jetty &>/dev/null || :
#groupdel jetty &>/dev/null || :
[root@galaxy ~]#
===

While the following would be much better:
===
[root@galaxy ~]# rpm -q --scripts jetty
preinstall scriptlet (through /bin/sh):
getent group jetty >/dev/null || groupadd -r jetty || :
# Use /bin/sh so init script will start properly.
getent passwd jetty >/dev/null || \
    useradd -r -s /bin/sh -d /usr/share/jetty -M \
                    -g jetty jetty || :
postinstall scriptlet (through /bin/sh):
[ -x /sbin/chkconfig ] && /sbin/chkconfig --add jetty
preuninstall scriptlet (through /bin/sh):
if [ $1 = 0 ]; then
    [ -f /var/lock/subsys/jetty ] && /etc/rc.d/init.d/jetty stop
    [ -f /etc/rc.d/init.d/jetty -a -x /sbin/chkconfig ] && /sbin/chkconfig --del jetty
fi
postuninstall scriptlet (through /bin/sh):
if [ $1 = 0 ]; then
    /usr/sbin/userdel jetty || :
fi
[root@galaxy ~]#
===

The changes are:

* in preinstall: add group/user only if it's not already defined;
* in preinstall: do not delete the user there, since "pre*" scriptlets may fail and we will end up with unowned files;
* in postinstall: delete user here under the condition that this was the last package (well, we still can end up with the unowned files/dirs, but at this stage there is nothing we can do about it).
Comment 3 viy 2012-08-31 15:51:51 MSK
ok, thanks, will fix in jetty-8.1.5 (next week, I guess)
Comment 4 viy 2012-09-18 22:13:34 MSK
I remember about that bug, but jetty 8.1.5 is delayed (It still does not build).
Comment 5 Repository Robot 2012-09-21 20:48:01 MSK
jetty-8.1.5-alt1_5jpp7 -> sisyphus:

* Fri Sep 21 2012 Igor Vlasenko <viy@altlinux> 8.1.5-alt1_5jpp7
- new version (closes: #27671)

* Tue Sep 18 2012 Igor Vlasenko <viy@altlinux> 8.1.5-alt1_2jpp7
- prebuild using manual depmap