Browse Source

enhance %pre and %post

Ralf S. Engelschall 24 years ago
parent
commit
0297a6ecfd
1 changed files with 358 additions and 319 deletions
  1. 358 319
      openpkg/openpkg.spec

+ 358 - 319
openpkg/openpkg.spec

@@ -39,7 +39,7 @@
 
 #   the package version and release
 %define       V_openpkg 0.9
-%define       R_openpkg 33
+%define       R_openpkg 34
 
 #   the used software versions
 %define       V_rpm     4.0.2
@@ -746,9 +746,6 @@ Provides:     OpenPKG
               (whoami) 2>/dev/null ||\
               (who am i | cut "-d " -f1) 2>/dev/null ||\
               echo $LOGNAME`
-    if [ ".$thisuser" = ".root" ]; then
-        exit 0
-    fi
 
     #   determine runtime details (for both inside and outside RPM!!)
     user="$fsusr";  [ ".$fsusr" = . ]  && fsusr="%{l_fsusr}"
@@ -765,247 +762,266 @@ Provides:     OpenPKG
     #   create the hierarchy user/group
     exists=`(cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^$user:"`
     if [ ".$exists" = . ]; then
-  
-        #   seek for a reasonably uid/gid pair
-        ugid=1000
-        ok=0
-        while [ ".$ok" = .0 ]; do
-            u_exists=`(cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^[^:]*:[^:]*:$ugid:"`
-            g_exists=`(cat /etc/group;  ypcat group)  2>/dev/null | grep "^[^:]*:[^:]*:$ugid:"`
-            if [ ".$u_exists" = . -a ".$g_exists" = . ]; then
-                ok=1
-                break
-            fi
-            ugid=`expr $ugid + 1`
-        done
+        if [ ".$thisuser" != ".root" ]; then
+            echo "openpkg:WARNING: skipping creation of dedicated OpenPKG user/group $ugid" 1>&2
+            echo "openpkg:WARNING: (would require root-priviledges)" 1>&2
+        else
+            #   seek for a reasonably uid/gid pair
+            ugid=1000
+            ok=0
+            while [ ".$ok" = .0 ]; do
+                u_exists=`(cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^[^:]*:[^:]*:$ugid:"`
+                g_exists=`(cat /etc/group;  ypcat group)  2>/dev/null | grep "^[^:]*:[^:]*:$ugid:"`
+                if [ ".$u_exists" = . -a ".$g_exists" = . ]; then
+                    ok=1
+                    break
+                fi
+                ugid=`expr $ugid + 1`
+            done
 
-        #   add entry to passwd database
-        shell="${prefix}/lib/rpm/bash"
-        realname="${prefix} OpenPKG"
-        case "$plid" in
-            FreeBSD/* | NetBSD/* )
-                file=/etc/master.passwd
-                entry="${user}:*:${ugid}:${ugid}::0:0:${realname}:${prefix}:${shell}" 
-                update="(PATH=\$PATH:/usr/sbin; pwd_mkdb -p /etc/master.passwd)"
-                ;;
-            Linux/* )
-                file=/etc/passwd
-                entry="${user}:*:${ugid}:${ugid}:${realname}:${prefix}:${shell}"
-                update="(PATH=\$PATH:/usr/sbin; pwconv)"
-                ;;
-            SunOS/5.* )
-                file=/etc/passwd
-                entry="${user}:*:${ugid}:${ugid}:${realname}:${prefix}:${shell}"
-                update="(PATH=\$PATH:/usr/sbin; pwconv)"
-                ;;
-            OSF1/V5.* )
-                file=/etc/passwd
-                entry="${user}:*:${ugid}:${ugid}:${realname}:${prefix}:${shell}"
-                update="(PATH=\$PATH:/usr/sbin; mkpasswd /etc/passwd)"
-                ;;
-        esac
-        cp $file $file.old
-        (grep -v '^+:' $file.old; echo $entry; grep '^+:' $file.old) >$file
-        rm -f $file.old >/dev/null 2>&1
-        eval $update
-        
-        #   add entry to group database
-        file=/etc/group
-        entry="${user}:*:${ugid}:${user}"
-        cp $file $file.old
-        (grep -v '^+:' $file.old; echo $entry; grep '^+:' $file.old) >$file
-        rm -f $file.old >/dev/null 2>&1
+            #   add entry to passwd database
+            shell="${prefix}/lib/rpm/bash"
+            realname="${prefix} OpenPKG"
+            case "$plid" in
+                FreeBSD/* | NetBSD/* )
+                    file=/etc/master.passwd
+                    entry="${user}:*:${ugid}:${ugid}::0:0:${realname}:${prefix}:${shell}" 
+                    update="(PATH=\$PATH:/usr/sbin; pwd_mkdb -p /etc/master.passwd)"
+                    ;;
+                Linux/* )
+                    file=/etc/passwd
+                    entry="${user}:*:${ugid}:${ugid}:${realname}:${prefix}:${shell}"
+                    update="(PATH=\$PATH:/usr/sbin; pwconv)"
+                    ;;
+                SunOS/5.* )
+                    file=/etc/passwd
+                    entry="${user}:*:${ugid}:${ugid}:${realname}:${prefix}:${shell}"
+                    update="(PATH=\$PATH:/usr/sbin; pwconv)"
+                    ;;
+                OSF1/V5.* )
+                    file=/etc/passwd
+                    entry="${user}:*:${ugid}:${ugid}:${realname}:${prefix}:${shell}"
+                    update="(PATH=\$PATH:/usr/sbin; mkpasswd /etc/passwd)"
+                    ;;
+            esac
+            cp $file $file.old
+            (grep -v '^+:' $file.old; echo $entry; grep '^+:' $file.old) >$file
+            rm -f $file.old >/dev/null 2>&1
+            eval $update
+            
+            #   add entry to group database
+            file=/etc/group
+            entry="${user}:*:${ugid}:${user}"
+            cp $file $file.old
+            (grep -v '^+:' $file.old; echo $entry; grep '^+:' $file.old) >$file
+            rm -f $file.old >/dev/null 2>&1
+        fi
     fi
 
     #   add entry to /etc/shells
     shell="${prefix}/lib/rpm/bash"
     exists=`cat /etc/shells 2>/dev/null | grep "^$shell"`
     if [ ".$exists" = . ]; then
-        echo "${shell}" >>/etc/shells
+        if [ ".$thisuser" != ".root" ]; then
+            echo "openpkg:WARNING: skipping addition of $shell to /etc/shells" 1>&2
+            echo "openpkg:WARNING: (would require root-priviledges)" 1>&2
+        else
+            echo "${shell}" >>/etc/shells
+        fi
     fi
   
     #   create the startup/shutdown transfer script
-    case "$plid" in
-        FreeBSD/* )
-            if [ ! -f /etc/rc.d/${name}.sh ]; then
-                #   make sure /etc/rc.d exists
-                if [ ! -d /etc/rc.d ]; then
-                    mkdir /etc/rc.d
-                fi
-                #   make sure /etc/rc.d is activated
-                (   . /etc/defaults/rc.conf
-                    . /etc/rc.conf
-                    found=0
-                    for p in ${local_startup-x}; do
-                        if [ ".$p" = "./etc/rc.d" ]; then
-                            found=1
-                            break
+    if [ ".$thisuser" != ".root" ]; then
+        echo "openpkg:WARNING: skipping creation of system run-command hooks" 1>&2
+        echo "openpkg:WARNING: (would require root-priviledges)" 1>&2
+    else
+        case "$plid" in
+            FreeBSD/* )
+                if [ ! -f /etc/rc.d/${name}.sh ]; then
+                    #   make sure /etc/rc.d exists
+                    if [ ! -d /etc/rc.d ]; then
+                        mkdir /etc/rc.d
+                    fi
+                    #   make sure /etc/rc.d is activated
+                    (   . /etc/defaults/rc.conf
+                        . /etc/rc.conf
+                        found=0
+                        for p in ${local_startup-x}; do
+                            if [ ".$p" = "./etc/rc.d" ]; then
+                                found=1
+                                break
+                            fi
+                        done
+                        if [ ".$found" = .0 ]; then
+                          cp -p /etc/rc.conf /etc/rc.conf.bak
+                          (
+                            grep -v local_startup /etc/rc.conf.bak 
+                            echo "local_startup=\"/etc/rc.d $local_startup\""
+                          ) >/etc/rc.conf
                         fi
+                    )
+                    #   install transfer script
+                    rm -f /etc/rc.d/${name}.sh >/dev/null 2>&1
+                    (   echo "#!/bin/sh"
+                        echo "#"
+                        echo "# ${name}.sh -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
+                        echo "#"
+                        echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
+                        echo "case \$1 in"
+                        echo "    start ) exec ${prefix}/etc/rc all start ;;"
+                        echo "    stop  ) exec ${prefix}/etc/rc all stop  ;;"
+                        echo "esac"
+                    ) >/etc/rc.d/${name}.sh
+                    chmod 755 /etc/rc.d/${name}.sh
+                fi
+                ;;
+            NetBSD/* )
+                if [ ! -f /etc/rc.d/${name} ]; then
+                    (   echo "#!/bin/sh"
+                        echo "#"
+                        echo "# ${name} -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
+                        echo "#"
+                        echo "# PROVIDE: ${name}"
+                        echo "# REQUIRE: DAEMON LOGIN NETWORK SERVERS"
+                        echo "#"
+                        echo ""
+                        echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
+                        echo "case \$1 in"
+                        echo "    start   ) exec ${prefix}/etc/rc all start ;;"
+                        echo "    stop    ) exec ${prefix}/etc/rc all stop  ;;"
+                        echo "    restart ) exec ${prefix}/etc/rc all stop start ;;"
+                        echo "    status  ) ;;"
+                        echo "esac"
+                    ) >/etc/rc.d/${name}
+                    chmod 755 /etc/rc.d/${name}
+                fi
+                ;;
+            Linux/* )
+                # sroot: script root directory
+                # lroot: link   root directory
+                if [ -f /etc/debian_version ]; then
+                    sroot=/etc/init.d
+                    lroot=/etc/rc%d.d
+                elif [ -f /etc/SuSE-release ]; then
+                    sroot=/sbin/init.d
+                    lroot=/sbin/init.d/rc%d.d
+                elif [ -f /etc/redhat-release ]; then
+                    sroot=/etc/rc.d/init.d
+                    lroot=/etc/rc.d/rc%d.d
+                fi
+                if [ ! -f $sroot/${name} ]; then
+                    #   install transfer script
+                    (   echo "#!/bin/sh"
+                        echo "#"
+                        echo "# ${name} -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
+                        echo "#"
+                        echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
+                        echo "case \$1 in"
+                        echo "    start ) exec ${prefix}/etc/rc all start ;;"
+                        echo "    stop  ) exec ${prefix}/etc/rc all stop  ;;"
+                        echo "esac"
+                    ) >$sroot/${name}
+                    chmod 755 $sroot/${name}
+                    #   create corresponding symbolic links
+                    for i in 2 3 4 5; do
+                        ln -s $sroot/${name} `echo $lroot | sed -e "s;%d;$i;"`/S99${name}
                     done
-                    if [ ".$found" = .0 ]; then
-                      cp -p /etc/rc.conf /etc/rc.conf.bak
-                      (
-                        grep -v local_startup /etc/rc.conf.bak 
-                        echo "local_startup=\"/etc/rc.d $local_startup\""
-                      ) >/etc/rc.conf
-                    fi
-                )
-                #   install transfer script
-                rm -f /etc/rc.d/${name}.sh >/dev/null 2>&1
-                (   echo "#!/bin/sh"
-                    echo "#"
-                    echo "# ${name}.sh -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
-                    echo "#"
-                    echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
-                    echo "case \$1 in"
-                    echo "    start ) exec ${prefix}/etc/rc all start ;;"
-                    echo "    stop  ) exec ${prefix}/etc/rc all stop  ;;"
-                    echo "esac"
-                ) >/etc/rc.d/${name}.sh
-                chmod 755 /etc/rc.d/${name}.sh
-            fi
-            ;;
-        NetBSD/* )
-            if [ ! -f /etc/rc.d/${name} ]; then
-                (   echo "#!/bin/sh"
-                    echo "#"
-                    echo "# ${name} -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
-                    echo "#"
-                    echo "# PROVIDE: ${name}"
-                    echo "# REQUIRE: DAEMON LOGIN NETWORK SERVERS"
-                    echo "#"
-                    echo ""
-                    echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
-                    echo "case \$1 in"
-                    echo "    start   ) exec ${prefix}/etc/rc all start ;;"
-                    echo "    stop    ) exec ${prefix}/etc/rc all stop  ;;"
-                    echo "    restart ) exec ${prefix}/etc/rc all stop start ;;"
-                    echo "    status  ) ;;"
-                    echo "esac"
-                ) >/etc/rc.d/${name}
-                chmod 755 /etc/rc.d/${name}
-            fi
-            ;;
-        Linux/* )
-            # sroot: script root directory
-            # lroot: link   root directory
-            if [ -f /etc/debian_version ]; then
-                sroot=/etc/init.d
-                lroot=/etc/rc%d.d
-            elif [ -f /etc/SuSE-release ]; then
-                sroot=/sbin/init.d
-                lroot=/sbin/init.d/rc%d.d
-            elif [ -f /etc/redhat-release ]; then
-                sroot=/etc/rc.d/init.d
-                lroot=/etc/rc.d/rc%d.d
-            fi
-            if [ ! -f $sroot/${name} ]; then
-                #   install transfer script
-                (   echo "#!/bin/sh"
-                    echo "#"
-                    echo "# ${name} -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
-                    echo "#"
-                    echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
-                    echo "case \$1 in"
-                    echo "    start ) exec ${prefix}/etc/rc all start ;;"
-                    echo "    stop  ) exec ${prefix}/etc/rc all stop  ;;"
-                    echo "esac"
-                ) >$sroot/${name}
-                chmod 755 $sroot/${name}
-                #   create corresponding symbolic links
-                for i in 2 3 4 5; do
-                    ln -s $sroot/${name} `echo $lroot | sed -e "s;%d;$i;"`/S99${name}
-                done
-                for i in 0 1 6; do
-                    ln -s $sroot/${name} `echo $lroot | sed -e "s;%d;$i;"`/K00${name}
-                done
-            fi
-            ;;
-        SunOS/5.* )
-            if [ ! -f /etc/init.d/${name} ]; then
-                #   install transfer script
-                (   echo "#!/bin/sh"
-                    echo "#"
-                    echo "# ${name} -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
-                    echo "#"
-                    echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
-                    echo "case \$1 in"
-                    echo "    start ) exec ${prefix}/etc/rc all start ;;"
-                    echo "    stop  ) exec ${prefix}/etc/rc all stop  ;;"
-                    echo "esac"
-                ) >/etc/init.d/${name}
-                chmod 755 /etc/init.d/${name}
-                #   create corresponding symbolic links
-                ( cd /etc
-                  ln init.d/${name} rc3.d/S99${name}
-                  ln init.d/${name} rc0.d/K00${name}
-                  ln init.d/${name} rc1.d/K00${name}
-                )
-            fi
-            ;;
-        OSF1/V5.* )
-            if [ ! -f /sbin/init.d/${name} ]; then
-                #   install transfer script
-                (   echo "#!/bin/sh"
-                    echo "#"
-                    echo "# ${name} -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
-                    echo "#"
-                    echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
-                    echo "case \$1 in"
-                    echo "    start ) exec ${prefix}/etc/rc all start ;;"
-                    echo "    stop  ) exec ${prefix}/etc/rc all stop  ;;"
-                    echo "esac"
-                ) >/sbin/init.d/${name}
-                chmod 755 /sbin/init.d/${name}
-                #   create corresponding symbolic links
-                ( cd /sbin
-                  ln -s ../init.d/${name} rc3.d/S99${name}
-                  ln -s ../init.d/${name} rc0.d/K00${name}
-                )
-            fi
-            ;;
-    esac
+                    for i in 0 1 6; do
+                        ln -s $sroot/${name} `echo $lroot | sed -e "s;%d;$i;"`/K00${name}
+                    done
+                fi
+                ;;
+            SunOS/5.* )
+                if [ ! -f /etc/init.d/${name} ]; then
+                    #   install transfer script
+                    (   echo "#!/bin/sh"
+                        echo "#"
+                        echo "# ${name} -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
+                        echo "#"
+                        echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
+                        echo "case \$1 in"
+                        echo "    start ) exec ${prefix}/etc/rc all start ;;"
+                        echo "    stop  ) exec ${prefix}/etc/rc all stop  ;;"
+                        echo "esac"
+                    ) >/etc/init.d/${name}
+                    chmod 755 /etc/init.d/${name}
+                    #   create corresponding symbolic links
+                    ( cd /etc
+                      ln init.d/${name} rc3.d/S99${name}
+                      ln init.d/${name} rc0.d/K00${name}
+                      ln init.d/${name} rc1.d/K00${name}
+                    )
+                fi
+                ;;
+            OSF1/V5.* )
+                if [ ! -f /sbin/init.d/${name} ]; then
+                    #   install transfer script
+                    (   echo "#!/bin/sh"
+                        echo "#"
+                        echo "# ${name} -- startup/shutdown transfer script for ${prefix} OpenPKG hierarchy"
+                        echo "#"
+                        echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
+                        echo "case \$1 in"
+                        echo "    start ) exec ${prefix}/etc/rc all start ;;"
+                        echo "    stop  ) exec ${prefix}/etc/rc all stop  ;;"
+                        echo "esac"
+                    ) >/sbin/init.d/${name}
+                    chmod 755 /sbin/init.d/${name}
+                    #   create corresponding symbolic links
+                    ( cd /sbin
+                      ln -s ../init.d/${name} rc3.d/S99${name}
+                      ln -s ../init.d/${name} rc0.d/K00${name}
+                    )
+                fi
+                ;;
+        esac
+    fi
 
     #   create the cron transfer entries
-    case "$plid" in
-        FreeBSD/* | Linux/* )
-            exists=`grep "$prefix/etc/rc" /etc/crontab`
-            if [ ".$exists" = . ]; then
-                (   echo "# <OpenPKG prefix=$prefix pkg=openpkg>"
-                    echo "# chronological tasks of ${prefix} OpenPKG hierarchy"
-                    echo "0    0  1  *  *  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all monthly"
-                    echo "0    0  *  *  0  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all weekly"
-                    echo "0    0  *  *  *  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all daily"
-                    echo "0    *  *  *  *  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all hourly"
-                    echo "*/15 *  *  *  *  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all quarterly"
-                    echo "# </OpenPKG>"
-                ) >>/etc/crontab
-            fi
-            ;;
-        SunOS/5.* | OSF1/V5.* | NetBSD/* )
-            exists=`crontab -l | grep "$prefix/etc/rc"`
-            if [ ".$exists" = . ]; then
-                EDITOR=/tmp/vipw.$$
-                VISUAL="$EDITOR"
-                export EDITOR
-                export VISUAL
-                ( echo "#!/bin/sh"
-                  echo "(   echo \"# <OpenPKG prefix=$prefix pkg=openpkg>\""
-                  echo "    echo \"# chronological tasks of ${prefix} OpenPKG hierarchy\""
-                  echo "    echo \"0          0  1  *  *  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all monthly\""
-                  echo "    echo \"0          0  *  *  0  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all weekly\""
-                  echo "    echo \"0          0  *  *  *  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all daily\""
-                  echo "    echo \"0          *  *  *  *  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all hourly\""
-                  echo "    echo \"0,15,30,45 *  *  *  *  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all quarterly\""
-                  echo "    echo \"# </OpenPKG>\""
-                  echo ") >>\$1"
-                ) >$EDITOR
-                chmod a+x $EDITOR
-                (PATH="$PATH:/usr/bin"; crontab -e)
-                rm -f $EDITOR
-            fi
-            ;;
-    esac
+    if [ ".$thisuser" != ".root" ]; then
+        echo "openpkg:WARNING: skipping creation of system cron hooks" 1>&2
+        echo "openpkg:WARNING: (would require root-priviledges)" 1>&2
+    else
+        case "$plid" in
+            FreeBSD/* | Linux/* )
+                exists=`grep "$prefix/etc/rc" /etc/crontab`
+                if [ ".$exists" = . ]; then
+                    (   echo "# <OpenPKG prefix=$prefix pkg=openpkg>"
+                        echo "# chronological tasks of ${prefix} OpenPKG hierarchy"
+                        echo "0    0  1  *  *  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all monthly"
+                        echo "0    0  *  *  0  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all weekly"
+                        echo "0    0  *  *  *  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all daily"
+                        echo "0    *  *  *  *  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all hourly"
+                        echo "*/15 *  *  *  *  root  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all quarterly"
+                        echo "# </OpenPKG>"
+                    ) >>/etc/crontab
+                fi
+                ;;
+            SunOS/5.* | OSF1/V5.* | NetBSD/* )
+                exists=`crontab -l | grep "$prefix/etc/rc"`
+                if [ ".$exists" = . ]; then
+                    EDITOR=/tmp/vipw.$$
+                    VISUAL="$EDITOR"
+                    export EDITOR
+                    export VISUAL
+                    ( echo "#!/bin/sh"
+                      echo "(   echo \"# <OpenPKG prefix=$prefix pkg=openpkg>\""
+                      echo "    echo \"# chronological tasks of ${prefix} OpenPKG hierarchy\""
+                      echo "    echo \"0          0  1  *  *  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all monthly\""
+                      echo "    echo \"0          0  *  *  0  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all weekly\""
+                      echo "    echo \"0          0  *  *  *  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all daily\""
+                      echo "    echo \"0          *  *  *  *  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all hourly\""
+                      echo "    echo \"0,15,30,45 *  *  *  *  [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all quarterly\""
+                      echo "    echo \"# </OpenPKG>\""
+                      echo ") >>\$1"
+                    ) >$EDITOR
+                    chmod a+x $EDITOR
+                    (PATH="$PATH:/usr/bin"; crontab -e)
+                    rm -f $EDITOR
+                fi
+                ;;
+        esac
+    fi
   
 %post
     #   Finally, rebuild the RPM database with the newly installed RPM
@@ -1062,103 +1078,126 @@ Provides:     OpenPKG
     plid="${s}/${r}"
 
     #   remove the hierarchy user/group
-    case "$plid" in
-        FreeBSD/* | NetBSD/* )
-            cp /etc/master.passwd /etc/master.passwd.bak
-            grep -v "^${user}:" /etc/master.passwd.bak >/etc/master.passwd
-            (PATH="$PATH:/usr/sbin"; pwd_mkdb -p /etc/master.passwd)
-            ;;
-        Linux/* | SunOS/5.* )
-            cp /etc/passwd /etc/passwd.bak
-            grep -v "^${user}:" /etc/passwd.bak >/etc/passwd
-            (PATH="$PATH:/usr/sbin"; pwconv)
-            ;;
-        OSF1/V5.* )
-            cp /etc/passwd /etc/passwd.bak
-            grep -v "^${user}:" /etc/passwd.bak >/etc/passwd
-            (PATH="$PATH:/usr/sbin"; mkpasswd /etc/passwd)
-            ;;
-    esac
-    cp /etc/group /etc/group.bak
-    grep -v "^${user}:" /etc/group.bak >/etc/group
+    exists=`(cat /etc/passwd; cat /etc/master.passwd; ypcat passwd) 2>/dev/null | grep "^$user:"`
+    if [ ".$exists" != . ]; then
+        if [ ".$thisuser" != ".root" ]; then
+            echo "openpkg:WARNING: skipping deletion of dedicated OpenPKG user/group $ugid" 1>&2
+            echo "openpkg:WARNING: (would require root-priviledges)" 1>&2
+        else
+            case "$plid" in
+                FreeBSD/* | NetBSD/* )
+                    cp /etc/master.passwd /etc/master.passwd.bak
+                    grep -v "^${user}:" /etc/master.passwd.bak >/etc/master.passwd
+                    (PATH="$PATH:/usr/sbin"; pwd_mkdb -p /etc/master.passwd)
+                    ;;
+                Linux/* | SunOS/5.* )
+                    cp /etc/passwd /etc/passwd.bak
+                    grep -v "^${user}:" /etc/passwd.bak >/etc/passwd
+                    (PATH="$PATH:/usr/sbin"; pwconv)
+                    ;;
+                OSF1/V5.* )
+                    cp /etc/passwd /etc/passwd.bak
+                    grep -v "^${user}:" /etc/passwd.bak >/etc/passwd
+                    (PATH="$PATH:/usr/sbin"; mkpasswd /etc/passwd)
+                    ;;
+            esac
+            cp /etc/group /etc/group.bak
+            grep -v "^${user}:" /etc/group.bak >/etc/group
+        fi
+    fi
 
     #   remove entry in /etc/shells
     shell="${prefix}/lib/rpm/bash"
     exists=`cat /etc/shells 2>/dev/null | grep "^$shell"`
-    if [ ".$exists" = . ]; then
-        cp /etc/shells /etc/shells.bak
-        grep -v "^${shell}" /etc/shells.bak >/etc/shells
+    if [ ".$exists" != . ]; then
+        if [ ".$thisuser" != ".root" ]; then
+            echo "openpkg:WARNING: skipping deletion of $shell from /etc/shells" 1>&2
+            echo "openpkg:WARNING: (would require root-priviledges)" 1>&2
+        else
+            cp /etc/shells /etc/shells.bak
+            grep -v "^${shell}" /etc/shells.bak >/etc/shells
+        fi
     fi
   
     #   remove the startup/shutdown transfer ripts
-    case "$plid" in
-        FreeBSD/* )
-            rm -f /etc/rc.d/${name}.sh >/dev/null 2>&1
-            ;;
-        NetBSD/* )
-            rm -f /etc/rc.d/${name} >/dev/null 2>&1
-            ;;
-        Linux/* )
-            # sroot: script root directory
-            # lroot: link   root directory
-            if [ -f /etc/debian_version ]; then
-                sroot=/etc/init.d
-                lroot=/etc/rc%d.d
-            elif [ -f /etc/SuSE-release ]; then
-                sroot=/sbin/init.d
-                lroot=/sbin/init.d/rc%d.d
-            elif [ -f /etc/redhat-release ]; then
-                sroot=/etc/rc.d/init.d
-                lroot=/etc/rc.d/rc%d.d
-            fi
-            rm -f ${sroot}/${name} >/dev/null 2>&1
-            for i in 2 3 4 5; do
-                rm -f `echo $lroot | sed -e "s;%d;$i;"`/S99${name} >/dev/null 2>&1
-            done
-            for i in 0 1 6; do
-                rm -f `echo $lroot | sed -e "s;%d;$i;"`/K00${name} >/dev/null 2>&1
-            done
-            ;;
-        SunOS/5.* )
-            rm -f /etc/init.d/${name} >/dev/null 2>&1
-            rm -f /etc/rc3.d/S99${name} >/dev/null 2>&1
-            rm -f /etc/rc0.d/K00${name} >/dev/null 2>&1
-            rm -f /etc/rc1.d/K00${name} >/dev/null 2>&1
-            ;;
-        OSF1/V5.* )
-            rm -f /sbin/init.d/${name} >/dev/null 2>&1
-            rm -f /sbin/rc3.d/S99${name} >/dev/null 2>&1
-            rm -f /sbin/rc0.d/K00${name} >/dev/null 2>&1
-            ;;
-    esac
+    if [ ".$thisuser" != ".root" ]; then
+        echo "openpkg:WARNING: skipping deletion of system run-command hooks" 1>&2
+        echo "openpkg:WARNING: (would require root-priviledges)" 1>&2
+    else
+        case "$plid" in
+            FreeBSD/* )
+                rm -f /etc/rc.d/${name}.sh >/dev/null 2>&1
+                ;;
+            NetBSD/* )
+                rm -f /etc/rc.d/${name} >/dev/null 2>&1
+                ;;
+            Linux/* )
+                # sroot: script root directory
+                # lroot: link   root directory
+                if [ -f /etc/debian_version ]; then
+                    sroot=/etc/init.d
+                    lroot=/etc/rc%d.d
+                elif [ -f /etc/SuSE-release ]; then
+                    sroot=/sbin/init.d
+                    lroot=/sbin/init.d/rc%d.d
+                elif [ -f /etc/redhat-release ]; then
+                    sroot=/etc/rc.d/init.d
+                    lroot=/etc/rc.d/rc%d.d
+                fi
+                rm -f ${sroot}/${name} >/dev/null 2>&1
+                for i in 2 3 4 5; do
+                    rm -f `echo $lroot | sed -e "s;%d;$i;"`/S99${name} >/dev/null 2>&1
+                done
+                for i in 0 1 6; do
+                    rm -f `echo $lroot | sed -e "s;%d;$i;"`/K00${name} >/dev/null 2>&1
+                done
+                ;;
+            SunOS/5.* )
+                rm -f /etc/init.d/${name} >/dev/null 2>&1
+                rm -f /etc/rc3.d/S99${name} >/dev/null 2>&1
+                rm -f /etc/rc0.d/K00${name} >/dev/null 2>&1
+                rm -f /etc/rc1.d/K00${name} >/dev/null 2>&1
+                ;;
+            OSF1/V5.* )
+                rm -f /sbin/init.d/${name} >/dev/null 2>&1
+                rm -f /sbin/rc3.d/S99${name} >/dev/null 2>&1
+                rm -f /sbin/rc0.d/K00${name} >/dev/null 2>&1
+                ;;
+        esac
+    fi
 
     #   remove the cron transfer entries
-    case "$plid" in
-        FreeBSD/* | Linux/* )
-            exists=`grep "<OpenPKG prefix=$prefix pkg=openpkg>" /etc/crontab`
-            if [ ".$exists" != . ]; then
-                p=`echo $prefix | sed -e 's;/;\\\\/;g'`
-                cp /etc/crontab /etc/crontab.bak
-                cat /etc/crontab.bak |\
-                sed -e "/<OpenPKG prefix=$p pkg=openpkg>/,/<\\/OpenPKG>/d" \
-                >/etc/crontab 
-            fi
-            ;;
-        SunOS/5.* | OSF1/V5.* | NetBSD/* )
-            EDITOR=/tmp/vipw.$$
-            VISUAL="$EDITOR"
-            export EDITOR
-            export VISUAL
-            p=`echo $prefix | sed -e 's;/;\\\\\\\\/;g'`
-            ( echo "cp \$1 \$1.old"
-              echo "cat \$1.old | sed -e \"/<OpenPKG prefix=$p pkg=openpkg>/,/<\\\\/OpenPKG>/d\" >\$1"
-              echo "rm -f \$1.old"
-            ) >$EDITOR
-            chmod a+x $EDITOR
-            (PATH="$PATH:/usr/bin"; crontab -e)
-            rm -f $EDITOR
-            ;;
-    esac
+    if [ ".$thisuser" != ".root" ]; then
+        echo "openpkg:WARNING: skipping deletion of system cron hooks" 1>&2
+        echo "openpkg:WARNING: (would require root-priviledges)" 1>&2
+    else
+        case "$plid" in
+            FreeBSD/* | Linux/* )
+                exists=`grep "<OpenPKG prefix=$prefix pkg=openpkg>" /etc/crontab`
+                if [ ".$exists" != . ]; then
+                    p=`echo $prefix | sed -e 's;/;\\\\/;g'`
+                    cp /etc/crontab /etc/crontab.bak
+                    cat /etc/crontab.bak |\
+                    sed -e "/<OpenPKG prefix=$p pkg=openpkg>/,/<\\/OpenPKG>/d" \
+                    >/etc/crontab 
+                fi
+                ;;
+            SunOS/5.* | OSF1/V5.* | NetBSD/* )
+                EDITOR=/tmp/vipw.$$
+                VISUAL="$EDITOR"
+                export EDITOR
+                export VISUAL
+                p=`echo $prefix | sed -e 's;/;\\\\\\\\/;g'`
+                ( echo "cp \$1 \$1.old"
+                  echo "cat \$1.old | sed -e \"/<OpenPKG prefix=$p pkg=openpkg>/,/<\\\\/OpenPKG>/d\" >\$1"
+                  echo "rm -f \$1.old"
+                ) >$EDITOR
+                chmod a+x $EDITOR
+                (PATH="$PATH:/usr/bin"; crontab -e)
+                rm -f $EDITOR
+                ;;
+        esac
+    fi
 
     #   delayed removal of top-level directory.
     ( sleep 10