package com.northpine;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static spark.Spark.*;

public class Server {

  private static Logger log = LoggerFactory.getLogger( Server.class );

  public static void main(String[] args) {
    ServerHandler handler = new ServerHandler();
    Path output = Paths.get("output/");
    if( Files.notExists( output ) ) {
      try {
        Files.createDirectory( output );
        log.info("successfully created '" + output + "'");
      } catch ( IOException e ) {
        log.error( "Couldn't create " + output, e );
        System.exit( 1 );
      }
    }
    port(getHerokuAssignedPort());
    staticFiles.location( "public" );
    before( handler::checkUrlParam );
    get("/scrape",  handler::handleScrapeStartRequest);
    get("/status", handler::handleGetProgress);
    get("/output", handler::handleGetOutput);
    get("/nourl", (req, res) -> "need a url");
  }

  private static int getHerokuAssignedPort() {
    ProcessBuilder processBuilder = new ProcessBuilder();
    if (processBuilder.environment().get("PORT") != null) {
      return Integer.parseInt(processBuilder.environment().get("PORT"));
    }
    return 8000; //return default port if heroku-port isn't set (i.e. on localhost)
  }
}

@@ -351,24 +351,47 @@
 g%5B%5D args) %7B%0A
+    checkOgrInstall();%0A
     ServerHa
@@ -1388,11 +1388,292 @@
 ost)%0A  %7D
+%0A%0A  private static void checkOgrInstall() %7B%0A    try %7B%0A      Runtime rt = Runtime.getRuntime();%0A      String%5B%5D commands = %7B%22ogr2ogr%22%7D;%0A      rt.exec( commands );%0A    %7D catch (IOException io) %7B%0A      log.info(%22Something is wrong with ogr2ogr%22, io);%0A      System.exit(1);%0A    %7D%0A  %7D%0A%0A%0A
 %0A%7D%0A

add ogr2ogr check on server start