Esempio n. 1
0
  /**
   * Starts the configuration service
   *
   * @param bundleContext the <tt>BundleContext</tt> as provided by the OSGi framework.
   * @throws Exception if anything goes wrong
   */
  public void start(BundleContext bundleContext) throws Exception {
    FileAccessService fas = ServiceUtils.getService(bundleContext, FileAccessService.class);

    if (fas != null) {
      File usePropFileConfig;
      try {
        usePropFileConfig =
            fas.getPrivatePersistentFile(".usepropfileconfig", FileCategory.PROFILE);
      } catch (Exception ise) {
        // There is somewhat of a chicken-and-egg dependency between
        // FileConfigurationServiceImpl and ConfigurationServiceImpl:
        // FileConfigurationServiceImpl throws IllegalStateException if
        // certain System properties are not set,
        // ConfigurationServiceImpl will make sure that these properties
        // are set but it will do that later.
        // A SecurityException is thrown when the destination
        // is not writable or we do not have access to that folder
        usePropFileConfig = null;
      }

      if (usePropFileConfig != null && usePropFileConfig.exists()) {
        logger.info("Using properties file configuration store.");
        this.cs = LibJitsi.getConfigurationService();
      }
    }

    if (this.cs == null) {
      this.cs = new JdbcConfigService(fas);
    }

    bundleContext.registerService(ConfigurationService.class.getName(), this.cs, null);

    fixPermissions(this.cs);
  }
Esempio n. 2
0
 private void fixConfigSchema() {
   File configFile;
   File ctpDir = new File(directory, "CTP");
   if (ctpDir.exists()) configFile = new File(ctpDir, "config.xml");
   else configFile = new File(directory, "config.xml");
   if (configFile.exists()) {
     try {
       Document doc = getDocument(configFile);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       moveAttributes(server, sslAttrs, "SSL");
       moveAttributes(server, proxyAttrs, "ProxyServer");
       moveAttributes(server, ldapAttrs, "LDAP");
       if (programName.equals("ISN")) fixRSNAROOT(server);
       if (isMIRC(root)) fixFileServiceAnonymizerID(root);
       setFileText(configFile, toString(doc));
     } catch (Exception ex) {
       cp.appendln(Color.red, "\nUnable to convert the config file schema.");
       cp.appendln(Color.black, "");
     }
   } else {
     cp.appendln(Color.red, "\nUnable to find the config file to check the schema.");
     cp.appendln(Color.black, "");
   }
 }
Esempio n. 3
0
 // Take a tree of files starting in a directory in a zip file
 // and copy them to a disk directory, recreating the tree.
 private int unpackZipFile(
     File inZipFile, String directory, String parent, boolean suppressFirstPathElement) {
   int count = 0;
   if (!inZipFile.exists()) return count;
   parent = parent.trim();
   if (!parent.endsWith(File.separator)) parent += File.separator;
   if (!directory.endsWith(File.separator)) directory += File.separator;
   File outFile = null;
   try {
     ZipFile zipFile = new ZipFile(inZipFile);
     Enumeration zipEntries = zipFile.entries();
     while (zipEntries.hasMoreElements()) {
       ZipEntry entry = (ZipEntry) zipEntries.nextElement();
       String name = entry.getName().replace('/', File.separatorChar);
       if (name.startsWith(directory)) {
         if (suppressFirstPathElement) name = name.substring(directory.length());
         outFile = new File(parent + name);
         // Create the directory, just in case
         if (name.indexOf(File.separatorChar) >= 0) {
           String p = name.substring(0, name.lastIndexOf(File.separatorChar) + 1);
           File dirFile = new File(parent + p);
           dirFile.mkdirs();
         }
         if (!entry.isDirectory()) {
           System.out.println("Installing " + outFile);
           // Copy the file
           BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFile));
           BufferedInputStream in = new BufferedInputStream(zipFile.getInputStream(entry));
           int size = 1024;
           int n = 0;
           byte[] b = new byte[size];
           while ((n = in.read(b, 0, size)) != -1) out.write(b, 0, n);
           in.close();
           out.flush();
           out.close();
           // Count the file
           count++;
         }
       }
     }
     zipFile.close();
   } catch (Exception e) {
     System.err.println("...an error occured while installing " + outFile);
     e.printStackTrace();
     System.err.println("Error copying " + outFile.getName() + "\n" + e.getMessage());
     return -count;
   }
   System.out.println(count + " files were installed.");
   return count;
 }
Esempio n. 4
0
 public static boolean deleteAll(File file) {
   boolean b = true;
   if ((file != null) && file.exists()) {
     if (file.isDirectory()) {
       try {
         File[] files = file.listFiles();
         for (File f : files) b &= deleteAll(f);
       } catch (Exception e) {
         return false;
       }
     }
     b &= file.delete();
   }
   return b;
 }
Esempio n. 5
0
 // Get the installer program file by looking in the user.dir for [programName]-installer.jar.
 private File getInstallerProgramFile() {
   System.out.println("Looking for the installer program file");
   File programFile;
   try {
     programFile =
         new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
   } catch (Exception ex) {
     String name = getProgramName();
     programFile = new File(name + "-installer.jar");
   }
   programFile = new File(programFile.getAbsolutePath());
   if (programFile.exists()) System.out.println("...found " + programFile);
   else {
     System.err.println("...unable to find the program file " + programFile + "\n...exiting.");
     exit();
   }
   return programFile;
 }
Esempio n. 6
0
  public void backup(String wildCardPath) {
    try {
      if (wildCardPath.contains("*") || wildCardPath.contains("?")) {
        // Extract the path so we know where to start and get the name which contains the
        // wildcard so we know what to store:

        File wildCardFile = new File(wildCardPath);
        String parentDirectory = wildCardFile.getParent();
        String wildCardPattern = wildCardFile.getName();
        _pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + wildCardPattern);
        Files.walkFileTree(Paths.get(parentDirectory), this);
      } else storeFile(new File(wildCardPath));
    } catch (FileNotFoundException exception) {
      Console.printError("File/Directory not found: " + wildCardPath);
    } catch (IOException exception) {
      Console.printError(
          "File/Directory '%s' not stored because: '%s'", wildCardPath, exception.getMessage());
    }
  }
Esempio n. 7
0
 // If this is a new installation, ask the user for a
 // port for the server; otherwise, return the negative
 // of the configured port. If the user selects an illegal
 // port, return zero.
 private int getPort() {
   // Note: directory points to the parent of the CTP directory.
   File ctp = new File(directory, "CTP");
   if (suppressFirstPathElement) ctp = ctp.getParentFile();
   File config = new File(ctp, "config.xml");
   if (!config.exists()) {
     // No config file - must be a new installation.
     // Figure out whether this is Windows or something else.
     String os = System.getProperty("os.name").toLowerCase();
     int defPort = ((os.contains("windows") && !programName.equals("ISN")) ? 80 : 1080);
     int userPort = 0;
     while (userPort == 0) {
       String port =
           JOptionPane.showInputDialog(
               null,
               "This is a new "
                   + programName
                   + " installation.\n\n"
                   + "Select a port number for the web server.\n\n",
               Integer.toString(defPort));
       try {
         userPort = Integer.parseInt(port.trim());
       } catch (Exception ex) {
         userPort = -1;
       }
       if ((userPort < 80) || (userPort > 32767)) userPort = 0;
     }
     return userPort;
   } else {
     try {
       Document doc = getDocument(config);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       String port = server.getAttribute("port");
       return -Integer.parseInt(port);
     } catch (Exception ex) {
     }
   }
   return 0;
 }
Esempio n. 8
0
  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.");
    }
  }
Esempio n. 9
0
 private void installConfigFile(int port) {
   if (port > 0) {
     System.out.println("Looking for /config/config.xml");
     InputStream is = getClass().getResourceAsStream("/config/config.xml");
     if (is != null) {
       try {
         File ctp = new File(directory, "CTP");
         if (suppressFirstPathElement) ctp = ctp.getParentFile();
         File config = new File(ctp, "config.xml");
         Document doc = getDocument(is);
         Element root = doc.getDocumentElement();
         Element server = getFirstNamedChild(root, "Server");
         System.out.println("...setting the port to " + port);
         server.setAttribute("port", Integer.toString(port));
         adjustConfiguration(root, ctp);
         setFileText(config, toString(doc));
       } catch (Exception ex) {
         System.err.println("...Error: unable to install the config.xml file");
       }
     } else System.err.println("...could not find it.");
   }
 }
Esempio n. 10
0
  private void storeFile(File file) throws FileNotFoundException, IOException {
    Console.printStatus("Storing: " + file);
    try (FileInputStream inputStream = new FileInputStream(file)) {
      _zipStream.putNextEntry(new ZipEntry(file.getCanonicalPath()));

      // Copy the content to the zip stream:

      int length;
      while ((length = inputStream.read(buffer)) > 0) _zipStream.write(buffer, 0, length);

      _zipStream.closeEntry();
    }
  }
Esempio n. 11
0
  /**
   * Makes home folder and the configuration file readable and writable only to the owner.
   *
   * @param cs the <tt>ConfigurationService</tt> instance to check for home folder and configuration
   *     file.
   */
  private static void fixPermissions(ConfigurationService cs) {
    if (!OSUtils.IS_LINUX && !OSUtils.IS_MAC) return;

    try {
      // let's check config file and config folder
      File homeFolder = new File(cs.getScHomeDirLocation(), cs.getScHomeDirName());
      Set<PosixFilePermission> perms =
          new HashSet<PosixFilePermission>() {
            {
              add(PosixFilePermission.OWNER_READ);
              add(PosixFilePermission.OWNER_WRITE);
              add(PosixFilePermission.OWNER_EXECUTE);
            }
          };
      Files.setPosixFilePermissions(Paths.get(homeFolder.getAbsolutePath()), perms);

      String fileName = cs.getConfigurationFilename();
      if (fileName != null) {
        File cf = new File(homeFolder, fileName);
        if (cf.exists()) {
          perms =
              new HashSet<PosixFilePermission>() {
                {
                  add(PosixFilePermission.OWNER_READ);
                  add(PosixFilePermission.OWNER_WRITE);
                }
              };
          Files.setPosixFilePermissions(Paths.get(cf.getAbsolutePath()), perms);
        }
      }
    } catch (Throwable t) {
      logger.error("Error creating c lib instance for fixing file permissions", t);

      if (t instanceof InterruptedException) Thread.currentThread().interrupt();
      else if (t instanceof ThreadDeath) throw (ThreadDeath) t;
    }
  }
Esempio n. 12
0
 private void setOwnership(File dir, String group, String owner) {
   try {
     Path path = dir.toPath();
     UserPrincipalLookupService lookupService =
         FileSystems.getDefault().getUserPrincipalLookupService();
     GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(group);
     UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(owner);
     PosixFileAttributeView pfav =
         Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
     pfav.setGroup(groupPrincipal);
     pfav.setOwner(userPrincipal);
   } catch (Exception ex) {
     cp.appendln("Unable to set the file group and owner for\n   " + dir);
   }
 }
Esempio n. 13
0
 private void adjustConfiguration(Element root, File dir) {
   // If this is an ISN installation and the Edge Server
   // keystore and truststore files do not exist, then set the configuration
   // to use the keystore.jks and truststore.jks files instead of the ones
   // in the default installation. If the Edge Server files do exist, then
   // delete the keystore.jks and truststore.jks files, just to avoid
   // confusion.
   if (programName.equals("ISN")) {
     Element server = getFirstNamedChild(root, "Server");
     Element ssl = getFirstNamedChild(server, "SSL");
     String rsnaroot = System.getenv("RSNA_ROOT");
     rsnaroot = (rsnaroot == null) ? "/usr/local/edgeserver" : rsnaroot.trim();
     String keystore = rsnaroot + "/conf/keystore.jks";
     String truststore = rsnaroot + "/conf/truststore.jks";
     File keystoreFile = new File(keystore);
     File truststoreFile = new File(truststore);
     cp.appendln(Color.black, "Looking for " + keystore);
     if (keystoreFile.exists() || truststoreFile.exists()) {
       cp.appendln(Color.black, "...found it [This is an EdgeServer installation]");
       // Delete the default files, just to avoid confusion
       File ks = new File(dir, "keystore.jks");
       File ts = new File(dir, "truststore.jks");
       boolean ksok = ks.delete();
       boolean tsok = ts.delete();
       if (ksok && tsok) cp.appendln(Color.black, "...Unused default SSL files were removed");
       else {
         if (!ksok) cp.appendln(Color.black, "...Unable to delete " + ks);
         if (!tsok) cp.appendln(Color.black, "...Unable to delete " + ts);
       }
     } else {
       cp.appendln(Color.black, "...not found [OK, this is a non-EdgeServer installation]");
       ssl.setAttribute("keystore", "keystore.jks");
       ssl.setAttribute("keystorePassword", "edge1234");
       ssl.setAttribute("truststore", "truststore.jks");
       ssl.setAttribute("truststorePassword", "edge1234");
       cp.appendln(
           Color.black, "...SSL attributes were updated for a non-EdgeServer installation");
     }
   }
 }
Esempio n. 14
0
  private void cleanup(File directory) {
    // Clean up from old installations, removing or renaming files.
    // Note that directory is the parent of the CTP directory
    // unless the original installation was done by Bill Weadock's
    // all-in-one installer for Windows.

    // Get a file pointing to the CTP directory.
    // This might be the current directory, or
    // it might be the CTP child.
    File dir;
    if (directory.getName().equals("RSNA")) dir = directory;
    else dir = new File(directory, "CTP");

    // If CTP.jar exists in this directory, it is a really
    // old CTP main file - not used anymore
    File ctp = new File(dir, "CTP.jar");
    if (ctp.exists()) ctp.delete();

    // These are old names for the Launcher.jar file
    File launcher = new File(dir, "CTP-launcher.jar");
    if (launcher.exists()) launcher.delete();
    launcher = new File(dir, "TFS-launcher.jar");
    if (launcher.exists()) launcher.delete();

    // Delete the obsolete CTP-runner.jar file
    File runner = new File(dir, "CTP-runner.jar");
    if (runner.exists()) runner.delete();

    // Delete the obsolete MIRC-copier.jar file
    File copier = new File(dir, "MIRC-copier.jar");
    if (copier.exists()) copier.delete();

    // Rename the old versions of the properties files
    File oldprops = new File(dir, "CTP-startup.properties");
    File newprops = new File(dir, "CTP-launcher.properties");
    File correctprops = new File(dir, "Launcher.properties");
    if (oldprops.exists()) {
      if (newprops.exists() || correctprops.exists()) oldprops.delete();
      else oldprops.renameTo(correctprops);
    }
    if (newprops.exists()) {
      if (correctprops.exists()) newprops.delete();
      else newprops.renameTo(correctprops);
    }

    // Get rid of obsolete startup and shutdown programs
    File startup = new File(dir, "CTP-startup.jar");
    if (startup.exists()) startup.delete();
    File shutdown = new File(dir, "CTP-shutdown.jar");
    if (shutdown.exists()) shutdown.delete();

    // Get rid of the obsolete linux directory
    File linux = new File(dir, "linux");
    if (linux.exists()) {
      startup = new File(linux, "CTP-startup.jar");
      if (startup.exists()) startup.delete();
      shutdown = new File(linux, "CTP-shutdown.jar");
      if (shutdown.exists()) shutdown.delete();
      linux.delete();
    }

    // clean up the libraries directory
    File libraries = new File(dir, "libraries");
    if (libraries.exists()) {
      // remove obsolete versions of the slf4j libraries
      // and the dcm4che-imageio libraries
      File[] files = libraries.listFiles();
      for (File file : files) {
        if (file.isFile()) {
          String name = file.getName();
          if (name.startsWith("slf4j-") || name.startsWith("dcm4che-imageio-rle")) {
            file.delete();
          }
        }
      }
      // remove the email subdirectory
      File email = new File(libraries, "email");
      deleteAll(email);
      // remove the xml subdirectory
      File xml = new File(libraries, "xml");
      deleteAll(xml);
      // remove the sftp subdirectory
      File sftp = new File(libraries, "sftp");
      deleteAll(xml);
      // move edtftpj.jar to the ftp directory
      File edtftpj = new File(libraries, "edtftpj.jar");
      if (edtftpj.exists()) {
        File ftp = new File(libraries, "ftp");
        ftp.mkdirs();
        File ftpedtftpj = new File(ftp, "edtftpj.jar");
        edtftpj.renameTo(ftpedtftpj);
      }
    }

    // remove the obsolete xml library under dir
    File xml = new File(dir, "xml");
    deleteAll(xml);

    // remove the dicom profiles so any
    // obsolete files will disappear
    File profiles = new File(dir, "profiles");
    File dicom = new File(profiles, "dicom");
    deleteAll(dicom);
    dicom.mkdirs();

    // Remove the index.html file so it will be rebuilt from
    // example-index.html when the system next starts.
    File root = new File(dir, "ROOT");
    if (root.exists()) {
      File index = new File(root, "index.html");
      index.delete();
    }
  }
Esempio n. 15
0
  /**
   * Class constructor; creates a new Installer object, displays a JFrame introducing the program,
   * allows the user to select an install directory, and copies files from the jar into the
   * directory.
   */
  public Installer(String args[]) {
    // Inputs are --install-dir INSTALL_DIR
    for (int k = 0; k < args.length; k = k + 2) {

      switch (args[k]) {
        case "--install-dir":
          directory = new File(args[k + 1]);
          System.out.println(directory);
          break;
        case "--port":
          port = Integer.parseInt(args[k + 1]);
          break;
      }
    }

    cp = new Stream();

    // Find the installer program so we can get to the files.
    installer = getInstallerProgramFile();
    String name = installer.getName();
    programName = (name.substring(0, name.indexOf("-"))).toUpperCase();

    // Get the installation information
    thisJava = System.getProperty("java.version");
    thisJavaBits = System.getProperty("sun.arch.data.model") + " bits";

    // Find the ImageIO Tools and get the version
    String javaHome = System.getProperty("java.home");
    File extDir = new File(javaHome);
    extDir = new File(extDir, "lib");
    extDir = new File(extDir, "ext");
    File clib = getFile(extDir, "clibwrapper_jiio", ".jar");
    File jai = getFile(extDir, "jai_imageio", ".jar");
    imageIOTools = (clib != null) && clib.exists() && (jai != null) && jai.exists();
    if (imageIOTools) {
      Hashtable<String, String> jaiManifest = getManifestAttributes(jai);
      imageIOVersion = jaiManifest.get("Implementation-Version");
    }

    // Get the CTP.jar parameters
    Hashtable<String, String> manifest = getJarManifestAttributes("/CTP/libraries/CTP.jar");
    programDate = manifest.get("Date");
    buildJava = manifest.get("Java-Version");

    // Get the util.jar parameters
    Hashtable<String, String> utilManifest = getJarManifestAttributes("/CTP/libraries/util.jar");
    utilJava = utilManifest.get("Java-Version");

    // Get the MIRC.jar parameters (if the plugin is present)
    Hashtable<String, String> mircManifest = getJarManifestAttributes("/CTP/libraries/MIRC.jar");
    if (mircManifest != null) {
      mircJava = mircManifest.get("Java-Version");
      mircDate = mircManifest.get("Date");
      mircVersion = mircManifest.get("Version");
    }

    // Set up the installation information for display
    if (imageIOVersion.equals("")) {
      imageIOVersion = "<b><font color=\"red\">not installed</font></b>";
    } else if (imageIOVersion.startsWith("1.0")) {
      imageIOVersion = "<b><font color=\"red\">" + imageIOVersion + "</font></b>";
    }
    if (thisJavaBits.startsWith("64")) {
      thisJavaBits = "<b><font color=\"red\">" + thisJavaBits + "</font></b>";
    }
    boolean javaOK = (thisJava.compareTo(buildJava) >= 0);
    javaOK &= (thisJava.compareTo(utilJava) >= 0);
    javaOK &= (thisJava.compareTo(mircJava) >= 0);
    if (!javaOK) {
      thisJava = "<b><font color=\"red\">" + thisJava + "</font></b>";
    }

    if (directory == null) exit();

    // Point to the parent of the directory in which to install the program.
    // so the copy process works correctly for directory trees.
    //
    // If the user has selected a directory named "CTP",
    // then assume that this is the directory in which
    // to install the program.
    //
    // If the directory is not CTP, see if it is called "RSNA" and contains
    // the Launcher program, in which case we can assume that it is an
    // installation that was done with Bill Weadock's all-in-one installer for Windows.
    //
    // If neither of those cases is true, then this is already the parent of the
    // directory in which to install the program
    if (directory.getName().equals("CTP")) {
      directory = directory.getParentFile();
    } else if (directory.getName().equals("RSNA")
        && (new File(directory, "Launcher.jar")).exists()) {
      suppressFirstPathElement = true;
    }

    // Cleanup old releases
    cleanup(directory);

    // Get a port for the server.
    if (port < 0) {
      if (checkServer(-port, false)) {
        System.err.println(
            "CTP appears to be running.\nPlease stop CTP and run the installer again.");
        System.exit(0);
      }
    }

    // Now install the files and report the results.
    int count =
        unpackZipFile(installer, "CTP", directory.getAbsolutePath(), suppressFirstPathElement);
    if (count > 0) {
      // Create the service installer batch files.
      updateWindowsServiceInstaller();
      updateLinuxServiceInstaller();

      // If this was a new installation, set up the config file and set the port
      installConfigFile(port);

      // Make any necessary changes in the config file to reflect schema evolution
      fixConfigSchema();

      System.out.println("Installation complete.");
      System.out.println(programName + " has been installed successfully.");
      System.out.println(count + " files were installed.");
    } else {
      System.err.println("Installation failed.");
      System.err.println(programName + " could not be fully installed.");
    }
    if (!programName.equals("ISN") && startRunner(new File(directory, "CTP"))) System.exit(0);
  }
Esempio n. 16
0
  /** Process all events for keys queued to the watcher */
  void processEvents() {
    for (; ; ) {

      // wait for key to be signalled
      WatchKey key;
      try {
        key = watcher.take();
      } catch (InterruptedException x) {
        return;
      }

      Path dir = keys.get(key);
      if (dir == null) {
        System.err.println("WatchKey not recognized!!");
        continue;
      }

      for (WatchEvent<?> event : key.pollEvents()) {
        WatchEvent.Kind kind = event.kind();

        // TBD - provide example of how OVERFLOW event is handled
        if (kind == OVERFLOW) {
          continue;
        }

        // Context for directory entry event is the file name of entry
        WatchEvent<Path> ev = cast(event);
        Path name = ev.context();
        Path child = dir.resolve(name);

        // print out event
        System.out.format("%s: %s\n", event.kind().name(), child);
        // Printing manager
        if (event.kind().name().equals("ENTRY_MODIFY")
            && (child.endsWith("baseFerremundoPointer.csv")
                || child.endsWith("baseFerremundoPointer2.csv"))) {
          File file = new File(child.toString());
          file.renameTo(new File("/home/dios/FERREMUNDO/BD/baseFerremundoPointer_.csv"));
          InvoicePrintingManager manager = new InvoicePrintingManager();
          manager.manage();
        }
        // if directory is created, and watching recursively, then
        // register it and its sub-directories
        if (recursive && (kind == ENTRY_CREATE)) {
          try {
            if (Files.isDirectory(child, NOFOLLOW_LINKS)) {
              registerAll(child);
            }
          } catch (IOException x) {
            // ignore to keep sample readbale
          }
        }
      }

      // reset key and remove from set if directory no longer accessible
      boolean valid = key.reset();
      if (!valid) {
        keys.remove(key);

        // all directories are inaccessible
        if (keys.isEmpty()) {
          break;
        }
      }
    }
  }
Esempio n. 17
0
  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");
    }
  }
Esempio n. 18
0
 public boolean accept(File file) {
   String name = file.getName();
   return name.startsWith(nameStart) && name.endsWith(nameEnd);
 }
Esempio n. 19
0
 private File getFile(File dir, String nameStart, String nameEnd) {
   File[] files = dir.listFiles(new NameFilter(nameStart, nameEnd));
   if (files.length == 0) return null;
   return files[0];
 }