76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
import os
|
|
import toml
|
|
|
|
baseDir = "/airwatchConnector"
|
|
logDir = f"{baseDir}/logs"
|
|
confDir = f"{baseDir}/conf"
|
|
confFiles = os.listdir(confDir)
|
|
|
|
# On récupère que les fichiers .conf
|
|
confFiles = [conf for conf in confFiles if os.path.isfile(f"{confDir}/{conf}") and not conf.endswith(".conf")]
|
|
|
|
for conf in confFiles:
|
|
# On forme un nom à partir du nom du fichier de conf sans l'extension
|
|
# et on enlève les espaces
|
|
confName = conf[:5].replace(' ', '')
|
|
|
|
with open(f"{confDir}/{conf}", "r") as f:
|
|
settings = toml.load(f)
|
|
|
|
# Create log folder
|
|
if(settings["LOGS"]["Enabled"]):
|
|
logPath = settings["LOGS"].get(Path)
|
|
if not os.path.exists(f"{logDir}/{logPath}"):
|
|
os.makedirs(f"{logDir}/{logPath}")
|
|
|
|
|
|
with open(f"/etc/systemd/system/{confName}-sync.service", "w") as f:
|
|
f.write(f"""[Unit]
|
|
Description=Script Airwatch pour la synchronisation des données Airwatch et GLPI.
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
WorkingDirectory=/airwatchConnector
|
|
ExecStart=/airwatchConnector/syncGLPI.py -c {confDir}/{conf} -s -f
|
|
User=root
|
|
""")
|
|
|
|
with open(f"/etc/systemd/system/{confName}-sync.timer", "w") as f:
|
|
f.write(f"""[Unit]
|
|
Description=Script Airwatch pour la synchronisation des données Airwatch et GLPI.
|
|
|
|
[Timer]
|
|
OnUnitInactiveSec=1h
|
|
AccuracySec=1us
|
|
Unit={confName}-sync.service
|
|
|
|
[Install]
|
|
WantedBy=timers.target
|
|
""")
|
|
|
|
with open(f"/etc/systemd/system/{confName}-staging.service", "w") as f:
|
|
f.write(f"""[Unit]
|
|
Description=Script qui assigne les appareils en staging aux utilisateurs en se basant sur GLPI.
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
WorkingDirectory=/airwatchConnector
|
|
ExecStart=/airwatchConnector/StagingUserAssignation.py -c {confDir}/{conf} -s -f
|
|
User=root
|
|
""")
|
|
|
|
with open(f"/etc/systemd/system/{confName}-staging.timer", "w") as f:
|
|
f.write(f"""[Unit]
|
|
Description=Script qui assigne les appareils en staging aux utilisateurs en se basant sur GLPI.
|
|
|
|
[Timer]
|
|
OnUnitInactiveSec=1m
|
|
AccuracySec=1us
|
|
Unit={confName}-staging.service
|
|
|
|
[Install]
|
|
WantedBy=timers.target
|
|
""")
|
|
|
|
|