From 7c691a28a72830b36a466d6bf4174749eedabfb8 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Mon, 6 May 2013 20:12:47 -0400
Subject: [PATCH] Fixed incorrect JNI_JAR_DIR.

The JNI_JAR_DIR is supposed to be architecture-specific but the
pki-base package is architecture-neutral. So, to ensure it has the
correct value, the variable will be set at post installation.
Also, to simplify the upgrade process, the variable has been moved
from /etc/pki/pki.conf into /usr/share/pki/etc/pki.conf. The build,
deployment, startup, and upgrade scripts have been modified
accordingly.
---
 base/common/CMakeLists.txt                 |  7 ++++++-
 base/common/etc/pki.conf                   |  2 ++
 base/common/share/etc/pki.conf             |  3 ---
 base/common/upgrade/10.0.1/01-AddJniJarDir |  2 ++
 base/server/scripts/operations             |  6 +++---
 base/server/src/engine/pkiparser.py        |  2 +-
 specs/pki-core.spec                        | 25 +++++++++++++++----------
 7 files changed, 29 insertions(+), 18 deletions(-)
 create mode 100644 base/common/etc/pki.conf

diff --git a/base/common/CMakeLists.txt b/base/common/CMakeLists.txt
index efdec85c44c9a0eb4daf4ea35bd676da5012163b..3798503c06c9fa44df1354f4e0654e34964bd670 100644
--- a/base/common/CMakeLists.txt
+++ b/base/common/CMakeLists.txt
@@ -6,6 +6,11 @@ configure_file(
     ${CMAKE_CURRENT_BINARY_DIR}/share/etc/pki.conf
 )
 
+configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/etc/pki.conf
+    ${CMAKE_CURRENT_BINARY_DIR}/etc/pki.conf
+)
+
 install(
     FILES
         ${CMAKE_CURRENT_BINARY_DIR}/share/etc/pki.conf
@@ -15,7 +20,7 @@ install(
 
 install(
     FILES
-        ${CMAKE_CURRENT_BINARY_DIR}/share/etc/pki.conf
+        ${CMAKE_CURRENT_BINARY_DIR}/etc/pki.conf
     DESTINATION
         ${SYSCONF_INSTALL_DIR}/pki/
 )
diff --git a/base/common/etc/pki.conf b/base/common/etc/pki.conf
new file mode 100644
index 0000000000000000000000000000000000000000..3e5a5e154ff6ef95eb75d1a4d4344daa4e4c4d44
--- /dev/null
+++ b/base/common/etc/pki.conf
@@ -0,0 +1,2 @@
+# RESTEasy library
+RESTEASY_LIB=${RESTEASY_LIB}
diff --git a/base/common/share/etc/pki.conf b/base/common/share/etc/pki.conf
index 8b16efd4b898289beb8fac097bf5ef37288a8010..f3523442addfb671f905eb8a97538f434223d517 100644
--- a/base/common/share/etc/pki.conf
+++ b/base/common/share/etc/pki.conf
@@ -1,5 +1,2 @@
-# RESTEasy library
-RESTEASY_LIB=${RESTEASY_LIB}
-
 # JNI jar file location
 JNI_JAR_DIR=${JNI_JAR_DIR}
diff --git a/base/common/upgrade/10.0.1/01-AddJniJarDir b/base/common/upgrade/10.0.1/01-AddJniJarDir
index ea92640b5692264b838781f3376ae06244aa18a9..212ffbdebde77b4cb94a056e9bb727edf5b919e5 100755
--- a/base/common/upgrade/10.0.1/01-AddJniJarDir
+++ b/base/common/upgrade/10.0.1/01-AddJniJarDir
@@ -47,6 +47,8 @@ class AddJniJarDir(pki.upgrade.PKIUpgradeScriptlet):
         # find JNI_JAR_DIR
         if conf.index('JNI_JAR_DIR') >= 0:
             # already exists
+            conf.set('JNI_JAR_DIR', default_path)
+            conf.write()
             return
 
         # find RESTEASY_LIB
diff --git a/base/server/scripts/operations b/base/server/scripts/operations
index 50dd4e4fd8bc19a76e8af42658bac96f10413c5c..616c28dd6bc8f924667f3f63d45eee3e34259743 100644
--- a/base/server/scripts/operations
+++ b/base/server/scripts/operations
@@ -1088,7 +1088,7 @@ verify_symlinks()
     declare -A systemd_symlinks
 
     # Dogtag 10 Conditional Variables
-    jni_dir=`source /etc/pki/pki.conf && echo $JNI_JAR_DIR`
+    jni_jar_dir=`source /usr/share/pki/etc/pki.conf && echo $JNI_JAR_DIR`
 
     # Dogtag 10 Symbolic Link Target Variables
     java_dir="/usr/share/java"
@@ -1198,7 +1198,7 @@ verify_symlinks()
         [javassist.jar]=${java_dir}/javassist.jar
         [jaxrs-api.jar]=${RESTEASY_LIB}/jaxrs-api.jar
         [jettison.jar]=${java_dir}/jettison.jar
-        [jss4.jar]=${jni_dir}/jss4.jar
+        [jss4.jar]=${jni_jar_dir}/jss4.jar
         [ldapjdk.jar]=${java_dir}/ldapjdk.jar
         [pki-tomcat.jar]=${java_dir}/pki/pki-tomcat.jar
         [resteasy-atom-provider.jar]=${RESTEASY_LIB}/resteasy-atom-provider.jar
@@ -1213,7 +1213,7 @@ verify_symlinks()
         [xml-commons-resolver.jar]=${java_dir}/xml-commons-resolver.jar)
 
     if [ -e ${PKI_INSTANCE_PATH}/tks ]; then
-        common_jar_symlinks[symkey.jar]=${jni_dir}/symkey.jar
+        common_jar_symlinks[symkey.jar]=${jni_jar_dir}/symkey.jar
     fi
 
     # '${pki_systemd_dir}' symlinks
diff --git a/base/server/src/engine/pkiparser.py b/base/server/src/engine/pkiparser.py
index f10706ac644d9e1b013d37512c9197815dcde682..dfb2652794d5535363f2c72bd7f9744a8451688b 100644
--- a/base/server/src/engine/pkiparser.py
+++ b/base/server/src/engine/pkiparser.py
@@ -163,7 +163,7 @@ class PKIConfigParser:
 
         # JNI jar location
         jni_jar_dir = subprocess.check_output(\
-            'source /etc/pki/pki.conf && echo $JNI_JAR_DIR',
+            'source /usr/share/pki/etc/pki.conf && echo $JNI_JAR_DIR',
             shell=True).strip()
 
         if config.pki_subsystem in config.PKI_TOMCAT_SUBSYSTEMS:
diff --git a/specs/pki-core.spec b/specs/pki-core.spec
index 00398141161556febbb2a417ff257f08765318f8..3870a0b2e9615294fe9d36168d5add431298da91 100644
--- a/specs/pki-core.spec
+++ b/specs/pki-core.spec
@@ -5,7 +5,7 @@ distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
 
 Name:             pki-core
 Version:          10.0.2
-Release:          4%{?dist}
+Release:          5%{?dist}
 Summary:          Certificate System - PKI Core Components
 URL:              http://pki.fedoraproject.org/
 License:          GPLv2
@@ -501,15 +501,6 @@ cd build
 %else
 	-DRESTEASY_LIB=/usr/share/java/resteasy \
 %endif
-%if 0%{?fedora} <= 18
-%ifarch x86_64
-	-DJNI_JAR_DIR=/usr/lib64/java \
-%else
-	-DJNI_JAR_DIR=/usr/lib/java \
-%endif
-%else
-	-DJNI_JAR_DIR=/usr/lib/java \
-%endif
 	%{?_without_javadoc:-DWITH_JAVADOC:BOOL=OFF} \
 %if ! 0%{?rhel} && 0%{?fedora} <= 17
         -DBUILD_PKI_SELINUX:BOOL=ON \
@@ -615,6 +606,16 @@ end
 
 %post -n pki-base
 
+%if 0%{?fedora} <= 18
+%ifarch x86_64
+	sed -i -e 's/^JNI_JAR_DIR=.*$/JNI_JAR_DIR=\/usr\/lib64\/java/' %{_datadir}/pki/etc/pki.conf
+%else
+	sed -i -e 's/^JNI_JAR_DIR=.*$/JNI_JAR_DIR=\/usr\/lib\/java/' %{_datadir}/pki/etc/pki.conf
+%endif
+%else
+	sed -i -e 's/^JNI_JAR_DIR=.*$/JNI_JAR_DIR=\/usr\/lib\/java/' %{_datadir}/pki/etc/pki.conf
+%endif
+
 if [ $1 -eq 1 ]
 then
     # On RPM installation create system upgrade tracker
@@ -623,6 +624,7 @@ then
 else
     # On RPM upgrade run system upgrade
     echo "Upgrading system at `/bin/date`." >> /var/log/pki/pki-upgrade-%{version}.log 2>&1
+    /sbin/pki-upgrade --remove-tracker >> /var/log/pki/pki-upgrade-%{version}.log 2>&1
     /sbin/pki-upgrade --silent >> /var/log/pki/pki-upgrade-%{version}.log 2>&1
     echo >> /var/log/pki/pki-upgrade-%{version}.log 2>&1
 fi
@@ -1071,6 +1073,9 @@ fi
 
 
 %changelog
+* Mon May 6 2013 Endi S. Dewata <edewata@redhat.com> 10.0.2-5
+- Fixed incorrect JNI_JAR_DIR.
+
 * Sat May 4 2013 Ade Lee <alee@redhat.com> 10.0.2-4
 - TRAC Ticket 605 Junit internal function used in TestRunner,
   breaks F19 build
-- 
1.8.1.4

