9953: De-duplicate Go and Python postinst/prerm scripts.
authorTom Clegg <tom@curoverse.com>
Fri, 23 Sep 2016 20:40:37 +0000 (16:40 -0400)
committerTom Clegg <tom@curoverse.com>
Wed, 28 Sep 2016 20:02:08 +0000 (16:02 -0400)
build/go-python-package-scripts/postinst [moved from build/go-package-scripts/postinst with 77% similarity]
build/go-python-package-scripts/prerm [moved from build/go-package-scripts/prerm with 59% similarity]
build/python-package-scripts/postinst [deleted file]
build/python-package-scripts/prerm [deleted file]
build/run-library.sh

similarity index 77%
rename from build/go-package-scripts/postinst
rename to build/go-python-package-scripts/postinst
index 0663465523b186a9a2fcb6ebd7cc9b261550a8c2..1e103337eaa5701cf46d3cf90130368fff360240 100755 (executable)
@@ -12,6 +12,14 @@ systemd_unit="${pkg}.service"
 case "${1}" in
     configure)
         if [ -e /run/systemd/system ]; then
+            # Python packages put all data files in /usr, so we copy
+            # them to /lib at install time.
+            py_unit="/usr/share/doc/${pkg}/${pkg}.service"
+            if [ -e "${py_unit}" ]
+            then
+                cp "${py_unit}" /lib/systemd/system/
+            fi
+
             eval "$(systemctl -p UnitFileState show "${systemd_unit}")"
             case "${UnitFileState}" in
                 disabled)
similarity index 59%
rename from build/go-package-scripts/prerm
rename to build/go-python-package-scripts/prerm
index 02772e461c44a1dfdd09a5b2c0925a16939a80cc..7f4b843d61593ee7f8e4aec49e5725bf6ea34cda 100755 (executable)
@@ -14,6 +14,14 @@ case "${1}" in
         if [ -e /run/systemd/system ]; then
             systemctl stop "${systemd_unit}" || true
             systemctl disable "${systemd_unit}" || true
+
+            # Unit files from Python packages get installed by
+            # postinst so we have to remove them explicitly here.
+            py_unit="/usr/share/doc/${pkg}/${pkg}.service"
+            if [ -e "${py_unit}" ]
+            then
+                rm "/lib/systemd/system/${pkg}.service" || true
+            fi
         fi
         ;;
 esac
diff --git a/build/python-package-scripts/postinst b/build/python-package-scripts/postinst
deleted file mode 100755 (executable)
index 27e4601..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-set -e
-
-# NOTE: This package name detection will only work on Debian.
-# If this postinst script ever starts doing work on Red Hat,
-# we'll need to adapt this code accordingly.
-script="$(basename "${0}")"
-pkg="${script%.postinst}"
-systemd_unit="${pkg}.service"
-
-case "${1}" in
-    configure)
-        if [ -e /run/systemd/system ]; then
-            cp "/usr/share/doc/${pkg}/${pkg}.service" /lib/systemd/system/
-            eval "$(systemctl -p UnitFileState show "${systemd_unit}")"
-            case "${UnitFileState}" in
-                disabled)
-                    # Failing to enable or start the service is not a
-                    # package error, so don't let errors here
-                    # propagate up.
-                    systemctl enable "${systemd_unit}" || true
-                    systemctl start "${systemd_unit}" || true
-                    ;;
-                enabled)
-                    systemctl daemon-reload || true
-                    systemctl reload-or-try-restart "${systemd_unit}" || true
-                    ;;
-            esac
-        fi
-        ;;
-esac
diff --git a/build/python-package-scripts/prerm b/build/python-package-scripts/prerm
deleted file mode 100755 (executable)
index 6d75f81..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-set -e
-
-# NOTE: This package name detection will only work on Debian.
-# If this prerm script ever starts doing work on Red Hat,
-# we'll need to adapt this code accordingly.
-script="$(basename "${0}")"
-pkg="${script%.prerm}"
-systemd_unit="${pkg}.service"
-
-case "${1}" in
-    remove)
-        if [ -e /run/systemd/system ]; then
-            systemctl stop "${systemd_unit}" || true
-            systemctl disable "${systemd_unit}" || true
-            rm "/lib/systemd/system/${pkg}.service"
-        fi
-        ;;
-esac
index e4455419af5c97751d497586226780f4533b4b67..73a99dabd7b3626582a418040e1ce6713a68ada9 100755 (executable)
@@ -105,8 +105,8 @@ package_go_binary() {
     systemd_unit="$WORKSPACE/${src_path}/${prog}.service"
     if [[ -e "${systemd_unit}" ]]; then
         switches+=(
-            --after-install "${WORKSPACE}/build/go-package-scripts/postinst"
-            --before-remove "${WORKSPACE}/build/go-package-scripts/prerm"
+            --after-install "${WORKSPACE}/build/go-python-package-scripts/postinst"
+            --before-remove "${WORKSPACE}/build/go-python-package-scripts/prerm"
             "${systemd_unit}=/lib/systemd/system/${prog}.service")
     fi
     switches+=("$WORKSPACE/${license_file}=/usr/share/doc/$prog/${license_file}")
@@ -268,8 +268,8 @@ fpm_build () {
   if [[ python = "$PACKAGE_TYPE" ]] && [[ -e "${PACKAGE}/${PACKAGE_NAME}.service" ]]
   then
       COMMAND_ARR+=(
-          --after-install "${WORKSPACE}/build/python-package-scripts/postinst"
-          --before-remove "${WORKSPACE}/build/python-package-scripts/prerm"
+          --after-install "${WORKSPACE}/build/go-python-package-scripts/postinst"
+          --before-remove "${WORKSPACE}/build/go-python-package-scripts/prerm"
       )
   fi