[tango] 01/02: create the user in the postinst to deal with piuparts remaining files

Frédéric-Emmanuel Picca picca at moszumanska.debian.org
Thu May 1 20:50:43 UTC 2014


This is an automated email from the git hooks/post-receive script.

picca pushed a commit to branch master
in repository tango.

commit 9a2426dfe061a612f69c942ec3e3e930a36aa898
Author: Picca Frédéric-Emmanuel <picca at debian.org>
Date:   Sun Jan 26 11:13:43 2014 +0100

    create the user in the postinst to deal with piuparts remaining files
---
 debian/tango-common.postinst | 60 ++++++++++++++++++++++++++++++++++++++++++++
 debian/tango-common.preinst  | 43 -------------------------------
 2 files changed, 60 insertions(+), 43 deletions(-)

diff --git a/debian/tango-common.postinst b/debian/tango-common.postinst
index a403441..3d90ea9 100644
--- a/debian/tango-common.postinst
+++ b/debian/tango-common.postinst
@@ -5,6 +5,66 @@ CONFIGFILE=/etc/tangorc
 set -e
 . /usr/share/debconf/confmodule
 
+case "$1" in 
+       install|upgrade)
+     
+       # If the package has default file it could be sourced, so that
+       # the local admin can overwrite the defaults
+     
+       [ -f "/etc/default/tango" ] && . /etc/default/tango
+     
+       # Sane defaults:
+     
+       [ -z "$SERVER_HOME" ] && SERVER_HOME=/var/lib/tango
+       [ -z "$SERVER_USER" ] && SERVER_USER=tango
+       [ -z "$SERVER_NAME" ] && SERVER_NAME="Tango Control System Server"
+       [ -z "$SERVER_GROUP" ] && SERVER_GROUP=tango
+     
+       # Groups that the user will be added to, if undefined, then none.
+       ADDGROUP=""
+     
+       # create user to avoid running server as root
+       # 1. create group if not existing
+       if ! getent group | grep -q "^$SERVER_GROUP:" ; then
+          echo -n "Adding group $SERVER_GROUP.."
+          addgroup --quiet --system $SERVER_GROUP 2>/dev/null ||true
+          echo "..done"
+       fi
+       # 2. create homedir if not existing
+       test -d $SERVER_HOME || mkdir $SERVER_HOME
+       # 3. create user if not existing
+       if ! getent passwd | grep -q "^$SERVER_USER:"; then
+         echo -n "Adding system user $SERVER_USER.."
+         adduser --quiet \
+                 --system \
+                 --ingroup $SERVER_GROUP \
+                 --no-create-home \
+                 --disabled-password \
+                 $SERVER_USER 2>/dev/null || true
+         echo "..done"
+       fi
+       # 4. adjust passwd entry
+       usermod -c "$SERVER_NAME" \
+               -d $SERVER_HOME   \
+               -g $SERVER_GROUP  \
+                  $SERVER_USER
+       # 5. adjust file and directory permissions
+       if ! dpkg-statoverride --list $SERVER_HOME >/dev/null
+       then
+           chown -R $SERVER_USER:adm $SERVER_HOME
+           chmod u=rwx,g=rxs,o= $SERVER_HOME
+       fi
+       # 6. Add the user to the ADDGROUP group
+       if test -n $ADDGROUP
+       then
+           if ! groups $SERVER_USER | cut -d: -f2 | \
+              grep -qw $ADDGROUP; then
+                adduser $SERVER_USER $ADDGROUP
+           fi
+       fi
+       ;;
+esac
+
 # Generate config file, if it doesn't exist.
 # An alternative is to copy in a template
 # file from elsewhere.
diff --git a/debian/tango-common.preinst b/debian/tango-common.preinst
deleted file mode 100644
index 34c7e55..0000000
--- a/debian/tango-common.preinst
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-
-DATADIR=/var/lib/tango
-
-#DEBHELPER#
-
-# If we use NIS then errors should be tolerated. It's up to the
-# user to ensure that the tango user is correctly setup.
-# Beware that there are two ypwhich one of them needs the 2>/dev/null!
-if test -n "`which ypwhich 2>/dev/null`"  &&  ypwhich >/dev/null 2>&1; then
-  set +e
-fi
-
-#
-# Now we have to ensure the following state:
-# /etc/passwd: tango:x:100:101:Tango Server:/var/lib/tango:/bin/false
-# /etc/group:  tango:x:101:
-# 
-# Sadly there could any state be present on the system so we have to
-# modify everything carefully i.e. not doing a chown before creating
-# the user etc...
-#
-
-# creating tango group if he isn't already there
-if ! getent group tango >/dev/null; then
-        # Adding system group: tango.
-        addgroup --system tango >/dev/null
-fi
-
-# creating tango user if he isn't already there
-if ! getent passwd tango >/dev/null; then
-        # Adding system user: tango.
-        adduser \
-          --system \
-          --ingroup tango \
-          --home $DATADIR \
-          --gecos "Tango Server" \
-          --shell /bin/false \
-          tango  >/dev/null
-fi
-
-# end of NIS tolerance zone
-set -e

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/tango.git



More information about the debian-science-commits mailing list