#!/usr/bin/env python import os import sys import subprocess import time log_file = '/tmp/.domaincheck.log' class DOMAINCHECK: def __init__(self): print "[DOMAINCHECK] Init" self.ready=False self.count=0 #def __init__ def is_lsass_configured(self): f=open("/etc/pam.d/common-auth") lines=f.readlines() f.close() tmp="".join(lines) if "pam_lsass.so" in tmp: return True else: return False #def is_lsass_configured def resolve(self): if not self.is_lsass_configured(): self.ready=True return 0 try: f=open(log_file,"a") f.write("[DOMAINCHECK] [Try %d] Resolving domain ..\n"%(self.count+1)) output=subprocess.Popen(["domainjoin-cli query | grep Domain"],shell=True,stdout=subprocess.PIPE).communicate()[0] self.domain=output.split(" = ")[1].strip("\n") ret=os.system("host %s"%self.domain) if ret==0: f.write("[DOMAINCHECK] Domain Ready\n") self.ready=True print("[DOMAINCHECK] Domain ready. Exiting...") else: f.write("[DOMAINCHECK] Domain not ready. Retrying...\n") print("[DOMAINCHECK] Domain not ready. Waiting...") f.close() except: f.write("[DOMAINCHECK] Domain not ready\n") f.close() #def resolve #class DOMAINCHECK if __name__=="__main__": if not os.path.exists(log_file): dcheck = DOMAINCHECK() while(not dcheck.ready): if dcheck.count < 15: dcheck.resolve() dcheck.count+=1 if not dcheck.ready: os.system('plymouth message --text="Waiting for AD Domain..." || :') time.sleep(6) else: dcheck.ready=True