mtes-scripts/scripts/module/change_domain.py

86 lines
2.3 KiB
Python
Raw Normal View History

2021-05-10 17:47:13 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, getpass, socket, cjson, os
from pyeole.ihm import print_line
from pyeole.ansiprint import print_orange, print_red
from creole.client import CreoleClient
from collections import OrderedDict
def display_help():
print("Modification de la valeur d'une variable d'un serveur")
2021-07-07 15:10:54 +02:00
print("{} [--d domain --integration --save]".format(sys.argv[0]))
2021-05-10 17:47:13 +02:00
def argparser():
# récupère l'ID du groupe
arglen = len(sys.argv)
2021-07-07 15:10:54 +02:00
save = None
integration = None
2021-06-30 16:43:06 +02:00
if "--save" in sys.argv:
save = True
2021-07-07 15:10:54 +02:00
if "--integration" in sys.argv:
integration = True
2021-05-10 17:47:13 +02:00
if arglen == 1:
2021-07-07 15:10:54 +02:00
return None, save
2021-05-10 17:47:13 +02:00
if sys.argv[1] in ['-h', '--help']:
display_help()
sys.exit(0)
2021-07-07 15:10:54 +02:00
if sys.argv[1] in ['-d', '--domain']:
domain = sys.argv[2]
return domain, save, integration
2021-05-10 17:47:13 +02:00
2021-07-07 15:10:54 +02:00
return None, save, integration
2021-05-10 17:47:13 +02:00
def main():
# import des fonctions communes de Zéphir client
2021-07-07 15:10:54 +02:00
domain, save, integration = argparser()
2021-05-10 17:47:13 +02:00
if domain is None :
domain = raw_input("Domaine AD : ")
fh = open("/etc/eole/config.eol", 'r')
store = cjson.decode(fh.read(), all_unicode=True)
fh.close
2021-07-07 15:10:54 +02:00
if "nom_domaine_local" in store:
store["nom_domaine_local"]['val'] = domain
2021-05-10 17:47:13 +02:00
fh = open("/etc/eole/config.eol", 'w')
fh.write(cjson.encode(store))
fh.close()
2021-06-30 15:13:29 +02:00
cmd="""CreoleCat -t samba4-vars.conf"""
2021-05-10 17:47:13 +02:00
output = os.popen(cmd)
res = output.read().strip()
output.close()
2021-07-07 15:10:54 +02:00
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()
2021-07-16 15:05:43 +02:00
to_save = ""
2021-07-07 15:10:54 +02:00
if not save :
to_save = raw_input("Souhaitez vous sauvegarder la configuration sur Zephir ? (O/N) ")
if to_save == "O":
save = True
2021-06-30 16:43:06 +02:00
if save:
cmd="""/usr/share/zephir/scripts/zephir_client save_files"""
output = os.popen(cmd)
output.close()
2021-05-10 17:47:13 +02:00
if __name__ == '__main__':
main()