private void updateLinuxServiceInstaller() { try { File dir = new File(directory, "CTP"); if (suppressFirstPathElement) dir = dir.getParentFile(); Properties props = new Properties(); String ctpHome = dir.getAbsolutePath(); cp.appendln(Color.black, "...CTP_HOME: " + ctpHome); ctpHome = ctpHome.replaceAll("\\\\", "\\\\\\\\"); props.put("CTP_HOME", ctpHome); File javaHome = new File(System.getProperty("java.home")); String javaBin = (new File(javaHome, "bin")).getAbsolutePath(); cp.appendln(Color.black, "...JAVA_BIN: " + javaBin); javaBin = javaBin.replaceAll("\\\\", "\\\\\\\\"); props.put("JAVA_BIN", javaBin); File linux = new File(dir, "linux"); File install = new File(linux, "ctpService-ubuntu.sh"); cp.appendln(Color.black, "Linux service installer:"); cp.appendln(Color.black, "...file: " + install.getAbsolutePath()); String bat = getFileText(install); bat = replace(bat, props); // do the substitutions bat = bat.replace("\r", ""); setFileText(install, bat); // If this is an ISN installation, put the script in the correct place. String osName = System.getProperty("os.name").toLowerCase(); if (programName.equals("ISN") && !osName.contains("windows")) { install = new File(linux, "ctpService-red.sh"); cp.appendln(Color.black, "ISN service installer:"); cp.appendln(Color.black, "...file: " + install.getAbsolutePath()); bat = getFileText(install); bat = replace(bat, props); // do the substitutions bat = bat.replace("\r", ""); File initDir = new File("/etc/init.d"); File initFile = new File(initDir, "ctpService"); if (initDir.exists()) { setOwnership(initDir, "edge", "edge"); setFileText(initFile, bat); initFile.setReadable(true, false); // everybody can read //Java 1.6 initFile.setWritable(true); // only the owner can write //Java 1.6 initFile.setExecutable(true, false); // everybody can execute //Java 1.6 } } } catch (Exception ex) { ex.printStackTrace(); System.err.println("Unable to update the Linux service ctpService.sh file"); } }
private void updateWindowsServiceInstaller() { try { File dir = new File(directory, "CTP"); if (suppressFirstPathElement) dir = dir.getParentFile(); File windows = new File(dir, "windows"); File install = new File(windows, "install.bat"); cp.appendln(Color.black, "Windows service installer:"); cp.appendln(Color.black, "...file: " + install.getAbsolutePath()); String bat = getFileText(install); Properties props = new Properties(); String home = dir.getAbsolutePath(); cp.appendln(Color.black, "...home: " + home); home = home.replaceAll("\\\\", "\\\\\\\\"); props.put("home", home); bat = replace(bat, props); setFileText(install, bat); } catch (Exception ex) { ex.printStackTrace(); System.err.println("Unable to update the windows service install.barfile."); } }
private String replace(String string, Properties table) { try { Pattern pattern = Pattern.compile("\\$\\{\\w+\\}"); Matcher matcher = pattern.matcher(string); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String group = matcher.group(); String key = group.substring(2, group.length() - 1).trim(); String repl = table.getProperty(key); if (repl == null) repl = matcher.quoteReplacement(group); matcher.appendReplacement(sb, repl); } matcher.appendTail(sb); return sb.toString(); } catch (Exception ex) { return string; } }