From edef84d443080df64be3ffe3cbe33968cc7c7feb Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Mon, 17 Sep 2012 13:04:45 -0500
Subject: [PATCH] Fixed problems with optional pki-symkey.

The deployment and init scripts have been fixed to create and check
the link to symkey.jar if a TKS instance is added, and remove the
link if the instance is removed.

Ticket #331
---
 base/deploy/scripts/operations                |  5 ++++-
 base/deploy/src/scriptlets/instance_layout.py | 10 +++++++---
 base/deploy/src/scriptlets/pkihelper.py       |  6 +++---
 base/setup/scripts/functions                  |  5 ++++-
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/base/deploy/scripts/operations b/base/deploy/scripts/operations
index 61e4e5de95ff7757f13ce9e58c975764bed1a8eb..60b66efdc560c4617db4f80497514d6880999a52 100644
--- a/base/deploy/scripts/operations
+++ b/base/deploy/scripts/operations
@@ -1058,13 +1058,16 @@ verify_symlinks()
         [resteasy-jaxrs.jar]=${resteasy_java_dir}/resteasy-jaxrs.jar
         [resteasy-jettison-provider.jar]=${resteasy_java_dir}/resteasy-jettison-provider.jar
         [scannotation.jar]=${java_dir}/scannotation.jar
-        [symkey.jar]=${jni_dir}/symkey.jar
         [tomcatjss.jar]=${java_dir}/tomcat7jss.jar
         [velocity.jar]=${java_dir}/velocity.jar
         [xerces-j2.jar]=${java_dir}/xerces-j2.jar
         [xml-commons-apis.jar]=${java_dir}/xml-commons-apis.jar
         [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
+    fi
+
     # '${pki_systemd_dir}' symlinks
     systemd_symlinks[${pki_systemd_link}]=${systemd_dir}/${pki_systemd_service}
 
diff --git a/base/deploy/src/scriptlets/instance_layout.py b/base/deploy/src/scriptlets/instance_layout.py
index 245df5a5f4563eb4308cf926f556bf24d0edb9cd..c5f884ec3e2187c584266ddea81914ab458336f3 100644
--- a/base/deploy/src/scriptlets/instance_layout.py
+++ b/base/deploy/src/scriptlets/instance_layout.py
@@ -125,8 +125,9 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
                 master['pki_resteasy_jettison_provider_jar_link'])
             util.symlink.create(master['pki_scannotation_jar'],
                 master['pki_scannotation_jar_link'])
-            util.symlink.create(master['pki_symkey_jar'],
-                master['pki_symkey_jar_link'])
+            if master['pki_subsystem'] == 'TKS':
+                util.symlink.create(master['pki_symkey_jar'],
+                    master['pki_symkey_jar_link'])
             util.symlink.create(master['pki_tomcatjss_jar'],
                 master['pki_tomcatjss_jar_link'])
             util.symlink.create(master['pki_velocity_jar'],
@@ -225,7 +226,8 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
             util.symlink.modify(
                 master['pki_resteasy_jettison_provider_jar_link'])
             util.symlink.modify(master['pki_scannotation_jar_link'])
-            util.symlink.modify(master['pki_symkey_jar_link'])
+            if master['pki_subsystem'] == 'TKS':
+                util.symlink.modify(master['pki_symkey_jar_link'])
             util.symlink.modify(master['pki_tomcatjss_jar_link'])
             util.symlink.modify(master['pki_velocity_jar_link'])
             util.symlink.modify(master['pki_xerces_j2_jar_link'])
@@ -245,6 +247,8 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
     def destroy(self):
         config.pki_log.info(log.INSTANCE_DESTROY_1, __name__,
                             extra=config.PKI_INDENTATION_LEVEL_1)
+        if master['pki_subsystem'] == 'TKS':
+            util.symlink.delete(master['pki_symkey_jar_link'])
         if not config.pki_dry_run_flag:
             if master['pki_subsystem'] in config.PKI_APACHE_SUBSYSTEMS and\
                util.instance.apache_instance_subsystems() == 0:
diff --git a/base/deploy/src/scriptlets/pkihelper.py b/base/deploy/src/scriptlets/pkihelper.py
index adbbe7cb5e6e5c91e30e56a0f15eb1c85d3484f7..8145a02d83a4ea7bb5cd72cf2ed62cc9cc842b07 100644
--- a/base/deploy/src/scriptlets/pkihelper.py
+++ b/base/deploy/src/scriptlets/pkihelper.py
@@ -1224,12 +1224,12 @@ class directory:
                                 #            systems since 'chmod' CANNOT be
                                 #            run directly against symbolic
                                 #            links!
-                                # chown -h <uid>:<gid> <link>
+                                # chown -h <uid>:<gid> <symlink>
                                 config.pki_log.debug(log.PKIHELPER_CHOWN_H_3,
-                                    uid, gid, link,
+                                    uid, gid, symlink,
                                     extra=config.PKI_INDENTATION_LEVEL_3)
                                 if not config.pki_dry_run_flag:
-                                    os.lchown(link, uid, gid)
+                                    os.lchown(symlink, uid, gid)
                                 # Store record in installation manifest
                                 record = manifest.record()
                                 record.name = name
diff --git a/base/setup/scripts/functions b/base/setup/scripts/functions
index 71685fe6d421fa5c930df9f0b10b3096c1754c24..2242063b28ed2cea35b28edf85d56d26927a8337 100644
--- a/base/setup/scripts/functions
+++ b/base/setup/scripts/functions
@@ -971,12 +971,15 @@ verify_symlinks()
         [pki-cmscore.jar]=/usr/share/java/pki/pki-cmscore.jar
         [pki-cmsutil.jar]=/usr/share/java/pki/pki-cmsutil.jar
         [pki-nsutil.jar]=/usr/share/java/pki/pki-nsutil.jar
-        [symkey.jar]=${jni_dir}/symkey.jar
         [velocity.jar]=/usr/share/java/velocity.jar
         [xerces-j2.jar]=/usr/share/java/xerces-j2.jar
         [xml-commons-apis.jar]=/usr/share/java/xml-commons-apis.jar
         [xml-commons-resolver.jar]=/usr/share/java/xml-commons-resolver.jar)
 
+    if [ "${PKI_SUBSYSTEM_TYPE}" == "tks"  ]; then
+        webapps_jar_symlinks[symkey.jar]=${jni_dir}/symkey.jar
+    fi
+
     # '${pki_systemd_dir}' symlinks
     systemd_symlinks[${pki_systemd_link}]=${systemd_dir}/${pki_systemd_service}
 
-- 
1.7.11.2

