Add JAVA_HOME to check.sh
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / configure / PlaceArtifactScripts.java
index 2393c4c..05ffdbf 100644 (file)
@@ -24,6 +24,8 @@ package org.onap.aaf.cadi.configure;
 import java.io.File;
 
 import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.aaf.Defaults;
+import org.onap.aaf.cadi.config.Config;
 import org.onap.aaf.cadi.util.Chmod;
 import org.onap.aaf.misc.env.Trans;
 import org.onap.aaf.misc.env.util.Chrono;
@@ -40,7 +42,7 @@ public class PlaceArtifactScripts extends ArtifactDir {
             String filename = arti.getNs()+".check.sh";
             File f1 = new File(dir,filename);
             String email = arti.getNotification() + '\n';
-            if(email.startsWith("mailto:")) {
+            if (email.startsWith("mailto:")) {
                 email=email.substring(7);
             }  else {
                 email=arti.getOsUser() + '\n';
@@ -48,14 +50,14 @@ public class PlaceArtifactScripts extends ArtifactDir {
             
             StringBuilder classpath = new StringBuilder();
             boolean first = true;
-            for(String pth : Split.split(File.pathSeparatorChar, System.getProperty("java.class.path"))) {
-                if(first) {
+            for (String pth : Split.split(File.pathSeparatorChar, System.getProperty("java.class.path"))) {
+                if (first) {
                     first=false;
                 } else {
                     classpath.append(File.pathSeparatorChar);
                 }
                 File f = new File(pth);
-                classpath.append(f.getCanonicalPath().replaceAll("[0-9]+\\.[0-9]+\\.[0-9]+","*"));
+                classpath.append(f.getCanonicalPath().replaceAll("[0-9]+\\.[0-9]+\\.[0-9]+",Defaults.AAF_VERSION+".*"));
             }
             
             write(f1,Chmod.to644,
@@ -63,10 +65,19 @@ public class PlaceArtifactScripts extends ArtifactDir {
                     "# Certificate Manager Check Script\n",
                     "# Check on Certificate, and renew if needed.\n",
                     "# Generated by Certificate Manager " + Chrono.timeStamp()+'\n',
+                    "#   by Deployer " + trans.getProperty(Config.AAF_APPID,"") + '\n', 
+                    "#\n",
                     "DIR="+arti.getDir()+'\n',
+                    "APP_ID=" + arti.getMechid() + '\n',
+                    "FQDN=" + arti.getMachine()+ '\n',
                     "APP="+arti.getNs()+'\n',
-                    "EMAIL="+email,
-                    "CP=\""+classpath.toString()+"\"\n",
+                    "EMAIL="+email+ '\n',
+                    "JAR=\""+classpath.toString()+"\"\n",
+                    "if [ -z \"$JAVA_HOME\" ]; then \n",
+                    "  JAVA=\""+javaHome() + "/bin/" +"java\"\n",
+                    "else\n",
+                    "  JAVA=\"$JAVA_HOME/bin/java\"\n",
+                    "fi\n",
                     checkScript
                     );
             
@@ -100,7 +111,6 @@ public class PlaceArtifactScripts extends ArtifactDir {
         return rc==null?System.getProperty("java.home"):rc;
     }
     private final static String checkScript = 
-            "> $DIR/$APP.msg\n\n" +
             "function mailit {\n" +
             "  if [ -e /bin/mail ]; then\n" +
             "     MAILER=/bin/mail\n" +
@@ -115,9 +125,8 @@ public class PlaceArtifactScripts extends ArtifactDir {
             "    printf \"$*\" | $MAILER -s \"AAF Certman Notification for `uname -n`\" $EMAIL\n"+
             " fi\n" +
             "}\n\n" +
-            javaHome() + "/bin/" +"java -cp $CP " +
-                Agent.class.getName() + 
-                " cadi_prop_files=$DIR/$APP.props check 2>  $DIR/$APP.STDERR > $DIR/$APP.STDOUT\n" +
+            "> $DIR/$APP.msg\n\n" +
+            "$JAVA -jar $JAR check $APP_ID $FQDN cadi_prop_files=$DIR/$APP.props 2>  $DIR/$APP.STDERR > $DIR/$APP.STDOUT\n" +
             "case \"$?\" in\n" +
             "  0)\n" +
             "    # Note: Validation will be mailed only the first day after any modification\n" +