Skip to content

Instantly share code, notes, and snippets.

@dnaeon
Created January 6, 2012 12:26
Show Gist options
  • Save dnaeon/1570368 to your computer and use it in GitHub Desktop.
Save dnaeon/1570368 to your computer and use it in GitHub Desktop.
ewafermapping-ui patch
From 1af110a6b3a267f99a00a945f9842c8a41185ad6 Mon Sep 17 00:00:00 2001
From: Marin Atanasov Nikolov <[email protected]>
Date: Fri, 6 Jan 2012 14:20:48 +0200
Subject: [PATCH] Update postinst and preinst scripts
* Create user in preinst script
* Fix permssions in postinst script
* Add adduser as dependency to ewafermapping-ui
* INKLESS-736
---
ewafermapping-ui/src/deb/control/control | 2 +-
ewafermapping-ui/src/deb/control/postinst | 50 +++++++++++++++-
ewafermapping-ui/src/deb/control/preinst | 88 ++++++++++++++++++++++++++++-
3 files changed, 135 insertions(+), 5 deletions(-)
diff --git a/ewafermapping-ui/src/deb/control/control b/ewafermapping-ui/src/deb/control/control
index 9019fd2..12a72a0 100644
--- a/ewafermapping-ui/src/deb/control/control
+++ b/ewafermapping-ui/src/deb/control/control
@@ -5,4 +5,4 @@ Priority: low
Architecture: all
Description: This is the userinterface for electronic wafermapping.
Maintainer: [email protected]
-Depends: daemon, sun-java6-jre
+Depends: daemon, sun-java6-jre, adduser
diff --git a/ewafermapping-ui/src/deb/control/postinst b/ewafermapping-ui/src/deb/control/postinst
index bc54292..1a7d82b 100644
--- a/ewafermapping-ui/src/deb/control/postinst
+++ b/ewafermapping-ui/src/deb/control/postinst
@@ -1,5 +1,49 @@
#!/bin/sh
+# postinst script for gam
+#
+# see: dh_installdeb(1)
-useradd -M -U -s /bin/false ewafermapping
-chown -R ewafermapping.ewafermapping /var/log/ewafermapping
-/etc/init.d/ewafermapping-ui start
\ No newline at end of file
+set -e
+
+# summary of how this script can be called:
+# * <postinst> `configure' <most-recently-configured-version>
+# * <old-postinst> `abort-upgrade' <new version>
+# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+# <new-version>
+# * <postinst> `abort-remove'
+# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+# <failed-install-package> <version> `removing'
+# <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+ configure)
+ [ -f "/etc/default/ewafermapping-ui" ] && . /etc/default/ewafermapping-ui
+
+ # Sane defaults:
+
+ [ -z "$USER_HOME" ] && USER_HOME=/home/ewafermapping
+ [ -z "$USER_NAME" ] && USER_NAME=ewafermapping
+ [ -z "$USER_FULLNAME" ] && USER_FULLNAME="Electronic Wafermapping User"
+ [ -z "$USER_GROUP" ] && USER_GROUP=ewafermapping
+
+ chown -R ${USER_NAME}:${USER_GROUP} /var/log/ewafermapping
+ ;;
+
+ abort-upgrade|abort-remove|abort-deconfigure)
+ ;;
+
+ *)
+ echo "postinst called with unknown argument \`$1'" >&2
+ exit 1
+ ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
diff --git a/ewafermapping-ui/src/deb/control/preinst b/ewafermapping-ui/src/deb/control/preinst
index 2f2fbfa..d4f39d4 100644
--- a/ewafermapping-ui/src/deb/control/preinst
+++ b/ewafermapping-ui/src/deb/control/preinst
@@ -1,3 +1,89 @@
#!/bin/sh
+# preinst script for gam
+#
+# see: dh_installdeb(1)
-/etc/init.d/ewafermapping-ui stop
+set -e
+
+# summary of how this script can be called:
+# * <new-preinst> `install'
+# * <new-preinst> `install' <old-version>
+# * <new-preinst> `upgrade' <old-version>
+# * <old-preinst> `abort-upgrade' <new-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+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/ewafermapping-ui" ] && . /etc/default/ewafermapping-ui
+
+ # Sane defaults:
+
+ [ -z "$USER_HOME" ] && USER_HOME=/home/ewafermapping
+ [ -z "$USER_NAME" ] && USER_NAME=ewafermapping
+ [ -z "$USER_FULLNAME" ] && USER_FULLNAME="Electronic Wafermapping User"
+ [ -z "$USER_GROUP" ] && USER_GROUP=ewafermapping
+
+ # 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 "^$USER_GROUP:" ; then
+ echo -n "Adding group $USER_GROUP.."
+ addgroup --quiet --system $USER_GROUP 2>/dev/null || true
+ echo "..done"
+ fi
+ # 2. create homedir if not existing
+ test -d $USER_HOME || mkdir $USER_HOME
+ # 3. create user if not existing
+ if ! getent passwd | grep -q "^$USER_NAME:"; then
+ echo -n "Adding system user $USER_NAME.."
+ adduser --quiet \
+ --system \
+ --ingroup $USER_GROUP \
+ --no-create-home \
+ --disabled-password \
+ $USER_NAME 2>/dev/null || true
+ echo "..done"
+ fi
+ # 4. adjust passwd entry
+ usermod -c "$USER_FULLNAME" \
+ -d $USER_HOME \
+ -g $USER_GROUP \
+ $USER_NAME
+ # 5. adjust file and directory permissions
+ if ! dpkg-statoverride --list $USER_HOME >/dev/null
+ then
+ chown -R $USER_NAME:${USER_GROUP} $USER_HOME
+ chmod u=rwx,g=rxs,o= $USER_HOME
+ fi
+ # 6. Add the user to the ADDGROUP group
+ if test -n $ADDGROUP
+ then
+ if ! groups $USER_NAME | cut -d: -f2 | \
+ grep -qw $ADDGROUP; then
+ adduser $USER_NAME $ADDGROUP
+ fi
+ fi
+ ;;
+ abort-upgrade)
+ ;;
+
+ *)
+ echo "preinst called with unknown argument \`$1'" >&2
+ exit 1
+ ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
--
1.7.6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment