update change_domain

This commit is contained in:
Matthieu Lamalle 2021-07-07 15:10:54 +02:00
parent 27bdbf5e4f
commit 401a4f9ef4
1 changed files with 32 additions and 23 deletions

View File

@ -10,38 +10,34 @@ from collections import OrderedDict
def display_help():
print("Modification de la valeur d'une variable d'un serveur")
print("{} [--r realm --d domain --save]".format(sys.argv[0]))
print("{} [--d domain --integration --save]".format(sys.argv[0]))
def argparser():
# récupère l'ID du groupe
arglen = len(sys.argv)
save = False
save = None
integration = None
if "--save" in sys.argv:
save = True
if "--integration" in sys.argv:
integration = True
if arglen == 1:
return None, None, save
return None, save
if sys.argv[1] in ['-h', '--help']:
display_help()
sys.exit(0)
if sys.argv[1] in ['-r', '--realm']:
realm = sys.argv[2]
return realm, None, save
if sys.argv[1] in ['-d', '--domain']:
domain = sys.argv[2]
return domain, save, integration
if sys.argv[3] in ['-d', '--domain']:
domain = sys.argv[4]
return realm, domain, save
return None, None, save
return None, save, integration
def main():
# import des fonctions communes de Zéphir client
realm, domain, save = argparser()
if realm is None :
realm = raw_input("Realm AD : ")
domain, save, integration = argparser()
if domain is None :
domain = raw_input("Domaine AD : ")
@ -49,10 +45,8 @@ def main():
fh = open("/etc/eole/config.eol", 'r')
store = cjson.decode(fh.read(), all_unicode=True)
fh.close
if "ad_realm" in store:
store["ad_realm"]['val'] = realm
if "ad_domain" in store:
store["ad_domain"]['val'] = domain
if "nom_domaine_local" in store:
store["nom_domaine_local"]['val'] = domain
fh = open("/etc/eole/config.eol", 'w')
fh.write(cjson.encode(store))
@ -63,10 +57,25 @@ def main():
res = output.read().strip()
output.close()
cmd="""/usr/share/eole/postservice/25-manage-samba instance"""
output = os.popen(cmd)
res = output.read().strip()
output.close()
if not integration :
to_integrate = raw_input("Souhaitez vous intégrer le serveur au domaine ad ? (O/N) ")
if to_integrate == "O":
integration = True
if integration:
cmd="""rm -f /var/lib/samba/.instance_ok; rm -f *.tdb"""
output = os.popen(cmd)
res = output.read().strip()
output.close()
cmd="""/usr/share/eole/postservice/25-manage-samba instance"""
output = os.popen(cmd)
res = output.read().strip()
output.close()
if not save :
to_save = raw_input("Souhaitez vous sauvegarder la configuration sur Zephir ? (O/N) ")
if to_save == "O":
save = True
if save:
cmd="""/usr/share/zephir/scripts/zephir_client save_files"""
output = os.popen(cmd)