From ab1f8ae8e6113819e9c7ddd83eea69d9a9133dd8 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Wed, 11 Mar 2015 12:30:48 +0000
Subject: [PATCH] OPENDJ-1772: Code cleanup in package scripts

---
 opendj-server-legacy/resource/debian/control/preinst     |   28 ++++-----
 opendj-server-legacy/resource/rpm/specs/postuninstall.sh |    3 
 opendj-server-legacy/resource/debian/control/postinst    |   65 ++++++++++-----------
 opendj-server-legacy/resource/debian/control/prerm       |    9 +-
 opendj-server-legacy/resource/rpm/specs/preuninstall.sh  |   12 +--
 opendj-server-legacy/resource/debian/control/postrm      |    7 +-
 opendj-server-legacy/resource/rpm/specs/postinstall.sh   |   28 ++++-----
 opendj-server-legacy/resource/rpm/specs/preinstall.sh    |   15 ++---
 8 files changed, 76 insertions(+), 91 deletions(-)

diff --git a/opendj-server-legacy/resource/debian/control/postinst b/opendj-server-legacy/resource/debian/control/postinst
index 4d39ecd..7703ffd 100644
--- a/opendj-server-legacy/resource/debian/control/postinst
+++ b/opendj-server-legacy/resource/debian/control/postinst
@@ -28,48 +28,43 @@
 set -e
 # Post install script
 # Install is launched with an empty second arg.
-# If the package is already installed,
-#  the second arg. is not empty.
+# If the package is already installed, the second arg. is not empty.
+
 # Registers the service
 update-rc.d opendj defaults
+
 # Symlinks to process ID
 test -h "/var/run/opendj.pid" || ln -s ${deb.prefix}/logs/server.pid /var/run/opendj.pid
+
 # In this case, we are in upgrade mode.
-if [ "$1" = "configure" ] && [ ! -z "$2" ]
-then
-# For being secure, we check the buildinfo file too.
-  if [ -f ${deb.prefix}/config/buildinfo ]
-  then
-    echo *Starting upgrade...
-    ${deb.prefix}/./upgrade -n --acceptLicense
-    echo
-# Upgrade fails - Requires mandatory user interaction.
-# Nevertheless, exits successfully of the pkg process.
-    if [ "$?" -eq 2 ]
-    then
-      exit 0
-    fi
-# Restarts the service if needed.
-# If server is stopped by upgrade process,
-#  the server will restart after upgrade.
-# If server is stopped before the upgrade process
-#  (eg. upgrade the new package), the server will not restart.
-# Uses the flag for determining server status at this point.
-    if [ "$?" -eq 0 ]
-    then
-      if [ -f ${deb.prefix}/logs/status ]
-      then
+if [ "$1" = "configure" ] && [ ! -z "$2" ] ; then
+    # For being secure, we check the buildinfo file too.
+    if [ -f ${deb.prefix}/config/buildinfo ] ; then
+        echo *Starting upgrade...
+        ${deb.prefix}/./upgrade -n --acceptLicense
         echo
-        echo "*Restarting server..."
-        ${deb.prefix}/./bin/start-ds
-        rm -f ${deb.prefix}/logs/status
-      fi
+        if [ "$?" -eq 2 ] ; then
+            # Upgrade fails - Requires mandatory user interaction.
+            # Nevertheless, exits successfully of the pkg process.
+            exit 0
+        fi
+
+        if [ "$?" -eq 0 ] ; then
+            # Restarts the service if needed.
+            # If server is stopped by upgrade process, the server will restart after upgrade.
+            # If server is stopped before the upgrade process (eg. upgrade the new package), the server will not restart.
+            # Uses the flag for determining server status at this point.
+            if [ -f ${deb.prefix}/logs/status ] ; then
+                echo
+                echo "*Restarting server..."
+                ${deb.prefix}/./bin/start-ds
+                rm -f ${deb.prefix}/logs/status
+            fi
+        fi
+    else
+        echo "Invalid installation, could not find the build info file."
+        exit -1
     fi
-  else
-# Invalid installation, could not find the buildinfo file.
-    echo "Invalid installation, could not find the build info file."
-    exit -1
-  fi
 fi
 # End post install script
 echo
\ No newline at end of file
diff --git a/opendj-server-legacy/resource/debian/control/postrm b/opendj-server-legacy/resource/debian/control/postrm
index e713873..7144dda 100644
--- a/opendj-server-legacy/resource/debian/control/postrm
+++ b/opendj-server-legacy/resource/debian/control/postrm
@@ -27,11 +27,10 @@
 
 set -e
 # Post rm script
-# Files are removed automatically by pm. 
-if [ "$1" = "remove" ]
-then
+# Files are removed automatically by pm.
+if [ "$1" = "remove" ] ; then
   echo
   echo *OpenDJ successfully removed
 fi
-echo 
+echo
 # End of the post rm script
\ No newline at end of file
diff --git a/opendj-server-legacy/resource/debian/control/preinst b/opendj-server-legacy/resource/debian/control/preinst
index 83c6d2d..0fb0099 100644
--- a/opendj-server-legacy/resource/debian/control/preinst
+++ b/opendj-server-legacy/resource/debian/control/preinst
@@ -26,23 +26,21 @@
 #
 
 set -e
+
 # Pre installation script
-if [ "$1" = "upgrade" ]
-then
-# Only if the instance has been configured
-  if [ -f ${deb.prefix}/config/buildinfo ] && [ "$(ls -A ${deb.prefix}/config/archived-configs)" ]
-  then
-# If the server is running before upgrade, creates a flag.
-    if [ -f ${deb.prefix}/logs/server.pid ]
-    then
-      touch ${deb.prefix}/logs/status
+if [ "$1" = "upgrade" ] ; then
+    # Only if the instance has been configured
+    if [ -f ${deb.prefix}/config/buildinfo ] && [ "$(ls -A ${deb.prefix}/config/archived-configs)" ] ; then
+        # If the server is running before upgrade, creates a flag.
+        if [ -f ${deb.prefix}/logs/server.pid ] ; then
+            touch ${deb.prefix}/logs/status
+        fi
+        echo *Stopping OpenDJ server...
+        ${deb.prefix}/bin/./stop-ds
+    else
+        echo "Instance is not configured. Upgrade aborded."
+        exit -1
     fi
-    echo *Stopping OpenDJ server...
-    ${deb.prefix}/bin/./stop-ds
-  else
-    echo "Instance is not configured. Upgrade aborded."
-    exit -1
-  fi
 fi
 echo
 # End of the pre installation script
\ No newline at end of file
diff --git a/opendj-server-legacy/resource/debian/control/prerm b/opendj-server-legacy/resource/debian/control/prerm
index 43dc86a..3b329e9 100644
--- a/opendj-server-legacy/resource/debian/control/prerm
+++ b/opendj-server-legacy/resource/debian/control/prerm
@@ -27,16 +27,17 @@
 
 set -e
 # Pre rm script
+
 # Stops the service.
 /etc/init.d/opendj stop >/dev/null 2>&1
+
 # Deletes the service.
 update-rc.d -f opendj remove
+
 # Unlink the symlink to the process ID if it exists.
 test -h "/var/run/opendj.pid" && unlink /var/run/opendj.pid
-# Stops the server
-# Only if the instance has been configured
-if [ "$1" = "remove" ] && ( [ -f ${deb.prefix}/config/buildinfo ] && [ "$(ls -A ${deb.prefix}/config/archived-configs)" ] )
-then
+# Stops the server if the instance has been configured
+if [ "$1" = "remove" ] && ( [ -f ${deb.prefix}/config/buildinfo ] && [ "$(ls -A ${deb.prefix}/config/archived-configs)" ] ) ; then
   echo *Stopping OpenDJ server...
   ${deb.prefix}/bin/./stop-ds
 fi
diff --git a/opendj-server-legacy/resource/rpm/specs/postinstall.sh b/opendj-server-legacy/resource/rpm/specs/postinstall.sh
index d66a464..50e2eb6 100644
--- a/opendj-server-legacy/resource/rpm/specs/postinstall.sh
+++ b/opendj-server-legacy/resource/rpm/specs/postinstall.sh
@@ -34,29 +34,27 @@
 
 # Registers the service
 /sbin/chkconfig --add opendj
+
 # Symlinks to process ID
 test -h "/var/run/opendj.pid" || ln -s /opt/opendj/logs/server.pid /var/run/opendj.pid
+
 if [ "$1" == "1" ] ; then
     echo "Post Install - initial install"
 else if [ "$1" == "2" ] ; then
     echo "Post Install - upgrade install"
-# Only if the instance has been configured
-    if [ -e "%{_prefix}"/config/buildinfo ] && [ "$(ls -A "%{_prefix}"/config/archived-configs)" ]
-    then
+    # Only if the instance has been configured
+    if [ -e "%{_prefix}"/config/buildinfo ] && [ "$(ls -A "%{_prefix}"/config/archived-configs)" ] ; then
         "%{_prefix}"/./upgrade -n --acceptLicense
-# Upgrade ok
-        if [ "$?" == "0" ] ; then
-# Checks the server status flag for restart.
-            if [ -f "%{_prefix}"/logs/status ]
-            then
-                echo ""
-                echo "Restarting server..."
-                "%{_prefix}"/./bin/start-ds
-                echo ""
-                rm -f "%{_prefix}"/logs/status
-            fi
+        # If upgrade is ok, checks the server status flag for restart
+        if [ "$?" == "0" ] && [ -f "%{_prefix}"/logs/status ] ; then
+            echo ""
+            echo "Restarting server..."
+            "%{_prefix}"/./bin/start-ds
+            echo ""
+            rm -f "%{_prefix}"/logs/status
         fi
-# Upgrade fails, needs user interaction (eg. manual mode)
+
+        # Upgrade fails, needs user interaction (eg. manual mode)
         if [ "$?" == "2" ] ; then
             exit "0"
         fi
diff --git a/opendj-server-legacy/resource/rpm/specs/postuninstall.sh b/opendj-server-legacy/resource/rpm/specs/postuninstall.sh
index 5a95027..6cbb864 100644
--- a/opendj-server-legacy/resource/rpm/specs/postuninstall.sh
+++ b/opendj-server-legacy/resource/rpm/specs/postuninstall.sh
@@ -28,8 +28,7 @@
 # RPM Post Uninstall Script (%postun)
 # ===================================
 
-# If the first argument to %preun and %postun is 0, the action is
-#  uninstallation.
+# If the first argument to %preun and %postun is 0, the action is uninstallation.
 # If the first argument to %preun and %postun is 1, the action is an upgrade.
 
 if [ "$1" == "0" ] ; then
diff --git a/opendj-server-legacy/resource/rpm/specs/preinstall.sh b/opendj-server-legacy/resource/rpm/specs/preinstall.sh
index 473f458..40025f9 100644
--- a/opendj-server-legacy/resource/rpm/specs/preinstall.sh
+++ b/opendj-server-legacy/resource/rpm/specs/preinstall.sh
@@ -28,20 +28,17 @@
 # RPM Pre Install Script (%pre)
 # =============================
 
-# If the first argument to %pre is 1, the RPM operation is an initial
-#  installation. If the argument to %pre is 2, the operation is an upgrade
-#  from an existing version to a new one.
+# If the first argument to %pre is 1, the RPM operation is an initial installation.
+# If the argument to %pre is 2, the operation is an upgrade from an existing version to a new one.
 
 if [ "$1" == "1" ]; then
     echo "Pre Install - initial install"
 else if [ "$1" == "2" ] ; then
-# Only if the instance has been configured
-    if [ -e "%{_prefix}"/config/buildinfo ] && [ "$(ls -A "%{_prefix}"/config/archived-configs)" ]
-    then
+    # Only if the instance has been configured
+    if [ -e "%{_prefix}"/config/buildinfo ] && [ "$(ls -A "%{_prefix}"/config/archived-configs)" ] ; then
         echo "Pre Install - upgrade install"
-# If the server is running before upgrade, creates a file flag
-        if [ -f "%{_prefix}"/logs/server.pid ]
-        then
+        # If the server is running before upgrade, creates a file flag
+        if [ -f "%{_prefix}"/logs/server.pid ] ; then
             touch "%{_prefix}"/logs/status
         fi
         "%{_prefix}"/bin/./stop-ds
diff --git a/opendj-server-legacy/resource/rpm/specs/preuninstall.sh b/opendj-server-legacy/resource/rpm/specs/preuninstall.sh
index 137cf04..5066592 100644
--- a/opendj-server-legacy/resource/rpm/specs/preuninstall.sh
+++ b/opendj-server-legacy/resource/rpm/specs/preuninstall.sh
@@ -28,21 +28,19 @@
 # RPM Pre Uninstall Script (%preun)
 # =================================
 
-# If the first argument to %preun and %postun is 0, the action is
-#  uninstallation.
+# If the first argument to %preun and %postun is 0, the action is uninstallation.
 # If the first argument to %preun and %postun is 1, the action is an upgrade.
 
 if [ "$1" == "0" ] ; then
     echo "Pre Uninstall - uninstall"
-# Stops the service and delete it.
+    # Stops the service and delete it.
     /etc/init.d/opendj stop >/dev/null 2>&1
     /sbin/chkconfig --del opendj
     # Unlink the symlink to the process ID.
     test -h "/var/run/opendj.pid" && unlink /var/run/opendj.pid
-# Only if the instance has been configured
-    if [ -e "%{_prefix}"/config/buildinfo ] && [ "$(ls -A "%{_prefix}"/config/archived-configs)" ]
-    then
-	"%{_prefix}"/bin/./stop-ds
+    # Only if the instance has been configured
+    if [ -e "%{_prefix}"/config/buildinfo ] && [ "$(ls -A "%{_prefix}"/config/archived-configs)" ] ; then
+	   "%{_prefix}"/bin/./stop-ds
     fi
 else if [ "$1" == "1" ] ; then
     echo "Pre Uninstall - upgrade uninstall"

--
Gitblit v1.10.0