import subprocess
import os


def check_directory():
    if os.path.exists("/Library/Application Support/COMODO/CCS"):
        return "CCSM"
    elif os.path.exists("/Library/Application Support/Xcitium Client - Security"):
        return "XCSM"
    else:
        return "EM"

product_type = check_directory()
print(product_type)

# Bash script to disable debug logging
bash_script = f"""#!/bin/bash

if [ {product_type} = "CCSM" ]; then
	sudo defaults write com.comodo.FileAccessDaemon logLevel 4   
elif [ {product_type} = "XCSM" ]; then
	sudo /usr/libexec/PlistBuddy -c "Set :logLevel info" "/Library/Application Support/Xcitium Client - Security/settings.plist"    
fi
"""

# Function to execute commands
def execute(arguments):
    p = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    output, error = p.communicate()
    if output:
        print(output)

# Write scripts to disk
script_path = f"/Library/Caches/Collect{product_type}enableLogs.sh"

with open(script_path, 'w') as f:
    f.write(bash_script)
# Execute bash script to disable logging
execute(f"sh {script_path}")
os.remove(script_path)
print(f"{product_type} debug logging is disabled successfully")