from setuphelpers import *
config_file = "mesh-conf.json"
def install():
package_version = control.get_software_version()
app_name = control.name
mesh_config_dict = json_load_file(get_persistent_package_file(config_file))
if mesh_config_dict["mesh_companyName"] != mesh_config_dict["mesh_serviceName"]:
app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"], mesh_config_dict["mesh_serviceName"])
else:
app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"])
app_path = makepath(app_dir, mesh_config_dict["mesh_fileName"] + ".exe")
app_uninstallkey = mesh_config_dict["mesh_serviceName"]
if iswin64():
bin_name = glob.glob("*64-*.exe")[0]
else:
bin_name = glob.glob("*32-*.exe")[0]
if not running_as_system():
print(
f'WARNING: {app_name} will NOT be installed as SYSTEM account, that will cause issues since it is installed as user: {get_current_user()} ("Waiting for key: {mesh_config_dict["mesh_serviceName"]}" will not complete), please uninstall it manually before deployment'
)
def get_app_version(key):
return get_version_from_binary(app_path, "FileVersion")
install_exe_if_needed(
bin_name,
silentflags="-fullinstall",
key=app_uninstallkey,
min_version=package_version,
get_version=get_app_version,
accept_returncodes=[0, 1, 3010, 3221226356],
)
quiet_uninstall_string = f'"{app_path}" {"-fulluninstall"}'
wait_uninstallkey_present(app_uninstallkey)
register_uninstall(app_uninstallkey, quiet_uninstall_string=quiet_uninstall_string)
def uninstall():
mesh_config_dict = json_load_file(get_persistent_package_file(config_file))
app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"])
app_uninstallkey = mesh_config_dict["mesh_serviceName"]
if isdir(app_dir):
killalltasks(control.get_impacted_process_list())
wait_uninstallkey_absent(app_uninstallkey)
print("Removing: %s" % (app_dir))
remove_tree(app_dir)
def audit():
mesh_config_dict = json_load_file(get_persistent_package_file(config_file))
if mesh_config_dict["mesh_companyName"] != mesh_config_dict["mesh_serviceName"]:
app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"], mesh_config_dict["mesh_serviceName"])
else:
app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"])
app_path = makepath(app_dir, mesh_config_dict["mesh_fileName"] + ".exe")
app_name = mesh_config_dict["mesh_displayName"]
mesh_regkey = r"SOFTWARE\Open Source\%s" % mesh_config_dict["mesh_serviceName"]
meshserverurl = registry_readstring(HKEY_LOCAL_MACHINE, mesh_regkey, "MeshServerUrl")
nodeid = registry_readstring(HKEY_LOCAL_MACHINE, mesh_regkey, "NodeId")
remotedesktopurl = "https://%s:%s/?viewmode=11&gotonode=%s&hide=25" % (mesh_config_dict["mesh_server"], mesh_config_dict["mesh_port"], nodeid)
print(remotedesktopurl)
"""
// SERVICE_STOPPED 1 The service is not running.
// SERVICE_START_PENDING 2 The service is starting.
// SERVICE_STOP_PENDING 3 The service is stopping.
// SERVICE_RUNNING 4 The service is running.
// SERVICE_CONTINUE_PENDING 5 The service continue is pending.
// SERVICE_PAUSE_PENDING 6 The service pause is pending.
// SERVICE_PAUSED 7 The service is paused.
// SERVICE_NOT_INSTALLED 100 The service is not installed.
"""
state = run(f'"{app_path}" {"state"}')
state_str = state.strip()
print("%s service state is:" % app_name)
print(state_str)
if state_str.lower() == "RUNNING".lower():
result = "OK"
elif state_str.lower() == "NOT INSTALLED".lower():
result = "WARNING"
print(
'INFO: "Not installed" Service state may be incorrect status, you may need to update your Mesh Server and Mesh Agent (more info here: https://github.com/Ylianst/MeshAgent/issues/87)'
)
else:
result = "WARNING"
try:
WAPT.write_audit_data_if_changed("mesh", "meshserverurl", meshserverurl, keep_days=365)
WAPT.write_audit_data_if_changed("mesh", "nodeid", nodeid, keep_days=365)
WAPT.write_audit_data_if_changed("mesh", "agenthash", registry_readstring(HKEY_LOCAL_MACHINE, mesh_regkey, "AgentHash"), keep_days=365)
WAPT.write_audit_data_if_changed("mesh", "remotedesktopurl", remotedesktopurl, keep_days=365)
except:
print("ERROR: write_audit_data failed")
result = "ERROR"
return result
def get_persistent_package_file(fname):
if isdir(makepath(os.getcwd(), "WAPT", "persistent")):
return makepath(os.getcwd(), "WAPT", "persistent", fname)
else:
return makepath(WAPT.persistent_root_dir, control.package_uuid, fname)
def get_persistent_package_dir():
if isdir(makepath(os.getcwd(), "WAPT", "persistent")):
return makepath(os.getcwd(), "WAPT", "persistent")
else:
return makepath(WAPT.persistent_root_dir, control.package_uuid)