#!/usr/bin/env python3
from setup_utils import *
import os
import socket

# icat.server

def uninstall():
    app = actions.getAppName("icat.lucene")
    if app: actions.undeploy(app)
    
actions, arg, props = getActions("setup.properties", [])

prop_name = "run.properties"
prop_list = ["directory", "commitSeconds", "ip"]

if arg in ["CONFIGURE", "INSTALL"]: actions.configure(prop_name, prop_list) 
luceneProperties = getProperties(prop_name, prop_list)

if arg in ["CONFIGURE", "INSTALL"]:
    actions.checkNoErrors()

if arg == "INSTALL":           
           
    try:           
        uninstall()
        ovfiles = [[prop_name, "WEB-INF/classes"]]
        if os.path.exists("logback.xml"): ovfiles.append(["logback.xml", "WEB-INF/classes"])
        if os.path.exists("synonym.txt"): ovfiles.append(["synonym.txt", "WEB-INF/classes"])
        actions.deploy(deploymentorder=80, files=ovfiles)
    except Exception as e:
        abort(str(e))
                
if arg == "UNINSTALL":        

    try:
        uninstall()
    except Exception as e:
        abort(str(e))       
    
            
    
