#!/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") print("{} [--d domain --integration --save]".format(sys.argv[0])) def argparser(): # récupère l'ID du groupe arglen = len(sys.argv) save = None integration = None if "--save" in sys.argv: save = True if "--integration" in sys.argv: integration = True if arglen == 1: return None, save if sys.argv[1] in ['-h', '--help']: display_help() sys.exit(0) if sys.argv[1] in ['-d', '--domain']: domain = sys.argv[2] return domain, save, integration return None, save, integration def main(): # import des fonctions communes de Zéphir client domain, save, integration = argparser() 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 if "nom_domaine_local" in store: store["nom_domaine_local"]['val'] = domain fh = open("/etc/eole/config.eol", 'w') fh.write(cjson.encode(store)) fh.close() cmd="""CreoleCat -t samba4-vars.conf""" 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) output.close() if __name__ == '__main__': main()