for creole's zephir2 branch
This commit is contained in:
153
bin/CreoleCat
Executable file
153
bin/CreoleCat
Executable file
@ -0,0 +1,153 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Run templatisation on a template name or file
|
||||
|
||||
`CreoleCat` support two modes:
|
||||
|
||||
- run on a template name with option -t: the name is looked up in
|
||||
``/usr/share/eole/creole/distrib/``. The output files are
|
||||
calculated unless you explicitely specify ``-o``.
|
||||
|
||||
- run on a file with options -s: this mode requires the use of
|
||||
``-o`` option.
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
|
||||
from os.path import basename, join, split
|
||||
|
||||
from pyeole import scriptargs
|
||||
from pyeole.log import init_logging
|
||||
|
||||
from creole.template import CreoleTemplateEngine
|
||||
import creole.config as cfg
|
||||
from creole.client import CreoleClient, CreoleClientError
|
||||
from pyeole.ihm import only_root
|
||||
|
||||
only_root()
|
||||
|
||||
client = CreoleClient()
|
||||
|
||||
def parse_cmdline():
|
||||
"""Parse commande line.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description="Instancie un template creole",
|
||||
parents=[scriptargs.container(),
|
||||
scriptargs.logging()])
|
||||
parser.add_argument("-t", "--template", metavar="NAME",
|
||||
help=u"nom du fichier template creole présent "
|
||||
"dans /usr/share/eole/creole/distrib")
|
||||
parser.add_argument("-s", "--source", metavar="PATH",
|
||||
help=u"chemin d’un fichier template")
|
||||
parser.add_argument("-o", "--output", metavar="OUTPUTFILE",
|
||||
help=u"chemin du fichier généré")
|
||||
|
||||
opts = parser.parse_args()
|
||||
|
||||
if (opts.template is None and opts.source is None) \
|
||||
or (opts.template and opts.source):
|
||||
parser.error("Vous devez spécifier une des options"
|
||||
"'--template' ou '--source'.")
|
||||
|
||||
if opts.source is not None and not os.access(opts.source, os.F_OK):
|
||||
parser.error("Fichier source inexistant"
|
||||
" ou illisible: {0}".format(opts.source))
|
||||
|
||||
if opts.output is None:
|
||||
if opts.source is not None:
|
||||
opts.output = ""
|
||||
else:
|
||||
if opts.template is not None \
|
||||
and opts.output == join(cfg.distrib_dir, opts.template):
|
||||
parser.error("Le fichier de sortie ne peut écraser"
|
||||
" le fichier template: {0}".format(opts.output) )
|
||||
if opts.source is not None and opts.output == opts.source:
|
||||
parser.error("Le fichier de sortie ne peut écraser"
|
||||
" le fichier source: {0}".format(opts.output) )
|
||||
|
||||
if opts.verbose:
|
||||
opts.log_level = 'info'
|
||||
if opts.debug:
|
||||
opts.log_level = 'debug'
|
||||
|
||||
return opts
|
||||
|
||||
|
||||
def _find_file(name, ctx):
|
||||
candidates = client.to_grouped_lists(ctx['files'], keyname='source')
|
||||
for source, filevar in candidates.items():
|
||||
if name != basename(source):
|
||||
continue
|
||||
elif filevar[0].get('activate', False):
|
||||
return filevar[0]
|
||||
|
||||
|
||||
def main():
|
||||
"""Setup environnment and run templatisation.
|
||||
"""
|
||||
|
||||
options = parse_cmdline()
|
||||
try:
|
||||
log = init_logging(level=options.log_level)
|
||||
|
||||
engine = CreoleTemplateEngine()
|
||||
|
||||
filevar = { 'source': options.source,
|
||||
'name': options.output,
|
||||
'full_name': options.output,
|
||||
'activate' : True,
|
||||
'del_comment': u'',
|
||||
'mkdir' : False,
|
||||
'rm' : False,
|
||||
}
|
||||
|
||||
if options.container is not None:
|
||||
# force container context
|
||||
groups = [client.get_container_infos(options.container)]
|
||||
elif options.output is not None:
|
||||
# Source without container, for root context
|
||||
groups = [client.get_container_infos('root')]
|
||||
else:
|
||||
groups = []
|
||||
for group in client.get_groups():
|
||||
groups.append(client.get_group_infos(group))
|
||||
|
||||
instanciated_files = []
|
||||
for group in groups:
|
||||
if filevar['source'] is not None:
|
||||
instanciated_files.append(filevar)
|
||||
engine.process(filevar, group)
|
||||
elif options.template is not None:
|
||||
found_file = _find_file(options.template, group)
|
||||
if found_file:
|
||||
instanciated_files.append(found_file)
|
||||
if options.output is None:
|
||||
engine._instance_file(found_file, group)
|
||||
else:
|
||||
# Override output
|
||||
found_file['name'] = options.output
|
||||
found_file['full_name'] = options.output
|
||||
# Do not get through verify and
|
||||
# change_properties
|
||||
engine._copy_to_template_dir(found_file)
|
||||
engine.process(found_file, group)
|
||||
|
||||
if not instanciated_files:
|
||||
# No file get instanciated
|
||||
raise CreoleClientError("Fichier template inexistant:"
|
||||
" {0}".format(options.template))
|
||||
|
||||
except Exception, err:
|
||||
if options.debug:
|
||||
log.debug(err, exc_info=True)
|
||||
else:
|
||||
log.error(err)
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
130
bin/CreoleGet
Executable file
130
bin/CreoleGet
Executable file
@ -0,0 +1,130 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Get a creole variable value.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from creole.client import CreoleClient
|
||||
|
||||
from pyeole import scriptargs
|
||||
from pyeole.log import init_logging
|
||||
from pyeole.encode import normalize
|
||||
|
||||
_RETURN_VALUES = u"""Multiple values are separated with NEWLINE character '\\n',
|
||||
or SPACE character if several variables are displayed."""
|
||||
|
||||
parser = argparse.ArgumentParser(description=u"Get creole variable",
|
||||
epilog=_RETURN_VALUES,
|
||||
parents=[scriptargs.logging()])
|
||||
|
||||
parser.add_argument('variable', nargs='?',
|
||||
help=u"Nom de variable creole")
|
||||
parser.add_argument('default', nargs='?',
|
||||
help=u"Valeur par défaut si la variable n’existe pas")
|
||||
|
||||
incompatible_options = parser.add_mutually_exclusive_group()
|
||||
|
||||
incompatible_options.add_argument('--groups', action="store_true", default=False,
|
||||
help=u"Liste les groupes de conteneurs")
|
||||
|
||||
incompatible_options.add_argument('--list', action="store_true", default=False,
|
||||
help=u"Liste l'ensemble des variables creole")
|
||||
|
||||
incompatible_options.add_argument('--reload', action="store_true", default=False,
|
||||
help=u"Recharge toute la configuration creole")
|
||||
|
||||
incompatible_options.add_argument('--reload-eol', action="store_true", default=False,
|
||||
help=u"Recharge les valeurs de configuration creole")
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
if options.verbose:
|
||||
# 'info' is outputed to stdout
|
||||
options.log_level = u'warning'
|
||||
if options.debug:
|
||||
options.log_level = u'debug'
|
||||
|
||||
def output(value, strip_master=False):
|
||||
"""
|
||||
formatage de l'affichage
|
||||
"""
|
||||
if isinstance(value, list):
|
||||
#FIXME: ['val1', None, 'val2']
|
||||
for val in value:
|
||||
if isinstance(val, dict):
|
||||
sys.stderr.write(u'{}\n'.format(val['err']))
|
||||
else:
|
||||
sys.stdout.write(u'{}\n'.format(val))
|
||||
elif isinstance(value, dict):
|
||||
# in case several keys/values are returned
|
||||
list_keys = value.keys()
|
||||
list_keys.sort()
|
||||
for var in list_keys:
|
||||
values = value[var]
|
||||
if isinstance(values, list):
|
||||
values_ = u''
|
||||
for val in values:
|
||||
if val and not isinstance(val, dict):
|
||||
values_ += u" {}".format(val)
|
||||
values = values_
|
||||
elif values is None:
|
||||
values = u''
|
||||
else:
|
||||
values = u'{}'.format(values)
|
||||
if strip_master:
|
||||
varname = var.split('.')[-1]
|
||||
else:
|
||||
varname = var
|
||||
sys.stdout.write(u'{}="{}"\n'.format(varname, values.strip()))
|
||||
elif value is None or value == u'':
|
||||
sys.stdout.write(u'\n')
|
||||
else:
|
||||
sys.stdout.write(u'{0}\n'.format(value))
|
||||
#return ret.rstrip('\n')
|
||||
|
||||
def main():
|
||||
"""Setup environnment and run templatisation.
|
||||
"""
|
||||
|
||||
try:
|
||||
log = init_logging(level=options.log_level)
|
||||
client = CreoleClient()
|
||||
var = options.variable
|
||||
if options.groups:
|
||||
output(client.get_groups())
|
||||
elif options.list:
|
||||
output(client.get_creole(), True)
|
||||
elif options.reload:
|
||||
client.reload_config()
|
||||
elif options.reload_eol:
|
||||
client.reload_eol()
|
||||
elif not var:
|
||||
raise Exception(u"Veuillez spécifier un nom de variable Creole")
|
||||
else:
|
||||
if options.default is not None:
|
||||
kwargs = {'default':options.default}
|
||||
else:
|
||||
kwargs = {}
|
||||
if '.' in var:
|
||||
output(client.get(var))
|
||||
else:
|
||||
output(client.get_creole(var, **kwargs))
|
||||
|
||||
except Exception, err:
|
||||
if options.debug:
|
||||
log.debug(normalize(err), exc_info=True)
|
||||
else:
|
||||
log.error(normalize(err))
|
||||
sys.exit(1)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
#Fix #18701
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('UTF8')
|
||||
main()
|
||||
|
68
bin/CreoleLint
Executable file
68
bin/CreoleLint
Executable file
@ -0,0 +1,68 @@
|
||||
#! /usr/bin/python
|
||||
|
||||
import sys
|
||||
from optparse import OptionParser
|
||||
|
||||
from creole.lint.creolelint import validate
|
||||
from creole.lint.ansiwriter import AnsiWriter
|
||||
|
||||
def parse_cmdline():
|
||||
parser = OptionParser()
|
||||
|
||||
parser.add_option("-t", "--template", dest="tmpl",
|
||||
default=None, help="nom du template Creole")
|
||||
parser.add_option("-l", "--level", dest="writelevel", default='warning',
|
||||
help="level d'affichage des messages")
|
||||
parser.add_option("-n", "--name", dest="name",
|
||||
default=None, help="nom du lint a tester")
|
||||
parser.add_option("-d", "--dico-only", action="store_true",
|
||||
dest="only_on_dico",
|
||||
default=False, help="lint uniquement sur les dicos")
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
options, args = parse_cmdline()
|
||||
tmpl = options.tmpl
|
||||
writelevel = options.writelevel
|
||||
|
||||
#if options.writelevel not in errorlevel.values():
|
||||
# raise Exception('Niveau %s inconnu'% options.writelevel)
|
||||
only_on_template = False
|
||||
only_on_dico = options.only_on_dico
|
||||
if tmpl is not None:
|
||||
only_on_template = True
|
||||
if options.name:
|
||||
keywords = [options.name]
|
||||
writelevel = 'info'
|
||||
else:
|
||||
keywords = []
|
||||
if not only_on_template:
|
||||
# keywords.extend(['orphans_def',
|
||||
# 'orphans_set', 'orphans_for', 'orphans_tmpl_files',
|
||||
# 'define', 'syntax_for', 'syntax_var', 'syntax_var2',
|
||||
# 'syntax_function', 'valid_client_option'])
|
||||
keywords.extend(['valid_dtd', 'wrong_dicos_name',
|
||||
'tabs_in_dicos', 'hidden_if_in_dicos',
|
||||
'condition_without_target',
|
||||
'obligatoire_in_dicos',
|
||||
'valid_slave_value',
|
||||
'valid_var_label', 'valid_separator_label',
|
||||
'valid_help_label',
|
||||
'activation_var_without_help',
|
||||
'family_without_help',
|
||||
'family_without_icon',
|
||||
'old_fw_file'])
|
||||
if not only_on_dico:
|
||||
keywords.extend(['valid_parse_tmpl'])
|
||||
keywords.append('builtins')
|
||||
ansi = AnsiWriter(writelevel)
|
||||
try:
|
||||
for keyword in keywords:
|
||||
validate(keyword, ansi, tmpl)
|
||||
except Exception, err:
|
||||
from traceback import print_exc
|
||||
print_exc()
|
||||
#print u"Erreur : {0}".format(err)
|
||||
sys.exit(1)
|
||||
|
||||
main()
|
16
bin/CreoleLock
Executable file
16
bin/CreoleLock
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from sys import argv
|
||||
from os import getppid
|
||||
from importlib import import_module
|
||||
from pyeole.command_line import ArgumentParser
|
||||
from pyeole.ihm import only_root
|
||||
|
||||
only_root()
|
||||
|
||||
allowed_functions = ('acquire', 'release', 'is_locked')
|
||||
module = import_module('pyeole.lock')
|
||||
module.PID = getppid()
|
||||
arguments = ArgumentParser(module, allowed_functions, argv[0])
|
||||
arguments.parse_args(argv[1:])
|
||||
arguments.trigger_callback()
|
54
bin/CreoleRun
Executable file
54
bin/CreoleRun
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# exécute une commande dans un conteneur
|
||||
|
||||
SSHCMD="ssh -q -o LogLevel=ERROR -o StrictHostKeyChecking=no"
|
||||
|
||||
commande=$1
|
||||
container=$2
|
||||
# ne lancer la commande que si dans un conteneur (ssh)
|
||||
onlyifcontainer=$3
|
||||
silent=$4
|
||||
CMD='eval'
|
||||
|
||||
ExecContainer()
|
||||
{
|
||||
ip="$1"
|
||||
cmd="$2"
|
||||
tcpcheck 2 $ip:22 &>/dev/null || return 1
|
||||
$SSHCMD root@$ip "$cmd"
|
||||
}
|
||||
|
||||
if [[ ${container} == "all" ]]
|
||||
then
|
||||
if [[ $(CreoleGet mode_conteneur_actif) == "oui" ]]
|
||||
then
|
||||
for grp in $(CreoleGet --groups)
|
||||
do
|
||||
if [[ ${grp} != 'root' ]] && [[ ${grp} != 'all' ]]
|
||||
then
|
||||
container_ip=$(CreoleGet "container_ip_${grp}")
|
||||
if [ ! "$silent" = "yes" ]; then
|
||||
echo "Exécution de la commande [${commande}] dans le conteneur ${grp}"
|
||||
echo
|
||||
fi
|
||||
ExecContainer "$container_ip" "$commande"
|
||||
if [ ! "$silent" = "yes" ]; then
|
||||
echo
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
else
|
||||
if [ -n "$container" ]
|
||||
then
|
||||
container_ip=$(CreoleGet "container_ip_$container")
|
||||
fi
|
||||
if [ -n "$container_ip" ] && [ ! "$container_ip" = "127.0.0.1" ]
|
||||
then
|
||||
ExecContainer "$container_ip" "$commande"
|
||||
elif [ "$onlyifcontainer" != "yes" ]
|
||||
then
|
||||
eval "$commande"
|
||||
fi
|
||||
fi
|
71
bin/CreoleService
Executable file
71
bin/CreoleService
Executable file
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from pyeole import scriptargs
|
||||
from pyeole.log import init_logging
|
||||
from pyeole.service import manage_services
|
||||
from creole.reconfigure import services
|
||||
from pyeole.ihm import only_root
|
||||
|
||||
only_root()
|
||||
|
||||
def parse_cmdline():
|
||||
|
||||
service_actions=['apply', 'configure', 'enable', 'disable', 'status',
|
||||
'start', 'stop', 'restart', 'reload']
|
||||
|
||||
parser = argparse.ArgumentParser(description="Action sur les services",
|
||||
parents=[scriptargs.container(),
|
||||
scriptargs.logging('info')])
|
||||
parser.add_argument('service', help="Nom du service")
|
||||
parser.add_argument('action', choices=service_actions,
|
||||
help="Action à effectuer")
|
||||
parser.add_argument("-f", "--force", action="store_true", default=False,
|
||||
help="Ne pas valider l'état de service")
|
||||
parser.add_argument("-s", "--silent", action="store_true", default=False,
|
||||
help="Ne pas affichier sur la console")
|
||||
|
||||
opts = parser.parse_args()
|
||||
|
||||
if opts.verbose:
|
||||
opts.log_level = 'info'
|
||||
if opts.debug:
|
||||
opts.log_level = 'debug'
|
||||
if opts.silent:
|
||||
opts.log_level = 'error'
|
||||
|
||||
|
||||
return opts
|
||||
|
||||
def main():
|
||||
options = parse_cmdline()
|
||||
log = init_logging(level=options.log_level)
|
||||
try:
|
||||
display = 'console'
|
||||
if options.silent:
|
||||
display = 'log'
|
||||
if options.service == 'all':
|
||||
if options.action == 'restart':
|
||||
services('stop', display_title=False, try_restart_lxc=False)
|
||||
services('start', display_title=False, try_restart_lxc=False)
|
||||
else:
|
||||
services(options.action, display_title=False, try_restart_lxc=False)
|
||||
ret = True
|
||||
else:
|
||||
ret = manage_services(options.action, options.service,
|
||||
container=options.container, force=options.force,
|
||||
display=display)
|
||||
except Exception, err:
|
||||
if options.debug:
|
||||
log.debug(err, exc_info=True)
|
||||
else:
|
||||
log.error(err)
|
||||
sys.exit(1)
|
||||
sys.exit(ret)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
92
bin/CreoleSet
Executable file
92
bin/CreoleSet
Executable file
@ -0,0 +1,92 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
from sys import exit
|
||||
|
||||
from pyeole import scriptargs
|
||||
from pyeole.ansiprint import print_red
|
||||
from pyeole.log import init_logging
|
||||
from creole.var_loader import convert_value
|
||||
from creole.loader import creole_loader, config_save_values
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
from pyeole.ihm import only_root
|
||||
|
||||
only_root()
|
||||
|
||||
parser = argparse.ArgumentParser(description=u"Set Creole variable",
|
||||
parents=[scriptargs.logging()])
|
||||
parser.add_argument("--default", action="store_true", default=False,
|
||||
help=u"remettre à la valeur par défaut")
|
||||
parser.add_argument('variable', nargs=1,
|
||||
help=u"Nom de variable Creole")
|
||||
parser.add_argument('value', nargs='?',
|
||||
help=u"Valeur de la variable Creole")
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
if options.verbose:
|
||||
# 'info' is outputed to stdout
|
||||
options.log_level = u'warning'
|
||||
if options.debug:
|
||||
options.log_level = u'debug'
|
||||
|
||||
if options.default and options.value:
|
||||
print_red("En cas de remise à la valeur par défaut, il ne faut pas spécifier de valeur")
|
||||
exit(1)
|
||||
|
||||
if not options.default and options.value is None:
|
||||
print_red("Veuiller spécifier la valeur")
|
||||
exit(1)
|
||||
|
||||
def main():
|
||||
log = init_logging(level=options.log_level)
|
||||
try:
|
||||
config = creole_loader(rw=True, owner='creoleset', load_extra=True)
|
||||
var = options.variable[0]
|
||||
if '.' in var:
|
||||
if var.startswith('.'):
|
||||
var = var[1:]
|
||||
namespace = var.split('.')[0]
|
||||
else:
|
||||
namespace = 'creole'
|
||||
var = config.find_first(byname=var, type_='path',
|
||||
force_permissive=True)
|
||||
if options.default:
|
||||
homeconfig, name = config.cfgimpl_get_home_by_path(var)
|
||||
homeconfig.__delattr__(name)
|
||||
else:
|
||||
option = config.unwrap_from_path(var)
|
||||
value = options.value
|
||||
if option.impl_is_multi():
|
||||
values = []
|
||||
for val in value.split('\n'):
|
||||
values.append(convert_value(option, val))
|
||||
value = values
|
||||
else:
|
||||
value = convert_value(option, value)
|
||||
setattr(config, var, value)
|
||||
config_save_values(config, namespace)
|
||||
except PropertiesOptionError, err:
|
||||
if options.debug:
|
||||
log.debug(err, exc_info=True)
|
||||
print_red(u"Erreur de propriété : {0}".format(err))
|
||||
exit(1)
|
||||
except ValueError, err:
|
||||
if options.debug:
|
||||
log.debug(err, exc_info=True)
|
||||
print_red("Valeur invalide : {0}".format(err))
|
||||
exit(1)
|
||||
except AttributeError:
|
||||
if options.debug:
|
||||
log.debug("AttributeError", exc_info=True)
|
||||
print_red("Nom de variable inconnue : {0}".format(options.variable[0]))
|
||||
exit(1)
|
||||
except Exception, err:
|
||||
if options.debug:
|
||||
log.debug(err, exc_info=True)
|
||||
print_red("Erreur inconnue : {0}".format(err))
|
||||
exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
454
bin/Maj-Auto
Executable file
454
bin/Maj-Auto
Executable file
@ -0,0 +1,454 @@
|
||||
#! /usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
##########################################################################
|
||||
# Maj-Auto - Manage automatique update of EOLE server
|
||||
# Copyright © 2013 Pôle de compétences EOLE <eole@ac-dijon.fr>
|
||||
#
|
||||
# License CeCILL:
|
||||
# * in french: http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html
|
||||
# * in english http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
|
||||
##########################################################################
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import atexit
|
||||
import time
|
||||
import locale
|
||||
|
||||
from os import unlink, environ, system
|
||||
from subprocess import Popen, PIPE
|
||||
from os.path import basename, isfile
|
||||
|
||||
from creole import reconfigure, fonctionseole
|
||||
from creole.client import CreoleClient, TimeoutCreoleClientError, NotFoundError, CreoleClientError
|
||||
from creole.error import UserExit, UserExitError
|
||||
|
||||
from creole.eoleversion import EOLE_RELEASE, LAST_RELEASE, EOLE_VERSION
|
||||
|
||||
from pyeole.lock import acquire, release, is_locked
|
||||
from pyeole.log import init_logging, set_formatter
|
||||
from pyeole.ihm import question_ouinon, only_root, catch_signal
|
||||
from pyeole.encode import normalize
|
||||
|
||||
from pyeole.pkg import EolePkg, _configure_sources_mirror, report
|
||||
|
||||
from pyeole.diagnose import test_tcp
|
||||
from pyeole import scriptargs
|
||||
|
||||
from pyeole.i18n import i18n
|
||||
|
||||
_ = i18n('creole')
|
||||
|
||||
#import logging
|
||||
|
||||
log = None
|
||||
|
||||
only_root()
|
||||
|
||||
try:
|
||||
# FIXME : refactorer le système de lock de zephir-client (ref #6660)
|
||||
from zephir.lib_zephir import lock, unlock
|
||||
zephir_libs = True
|
||||
except Exception:
|
||||
zephir_libs = False
|
||||
|
||||
def release_lock():
|
||||
if zephir_libs:
|
||||
unlock('maj')
|
||||
if is_locked('majauto', level='system'):
|
||||
release('majauto', level='system')
|
||||
|
||||
def user_exit(*args, **kwargs):
|
||||
"""
|
||||
sortie utilisateur "propre"
|
||||
"""
|
||||
log.warn(_(u'! Abandoning configuration !'))
|
||||
log.warn(_(u'System may be in an incoherent state.\n\n'))
|
||||
raise UserExitError()
|
||||
|
||||
|
||||
def parse_cmdline():
|
||||
"""Parse commande line.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(prog='Maj-Auto|Query-Auto',
|
||||
description=_(u"Manage EOLE server automatic update"),
|
||||
parents=[scriptargs.logging('info')],
|
||||
add_help=False)
|
||||
|
||||
parser.add_argument('-h', '--help',
|
||||
action='help',
|
||||
help=_(u"show this help message and exit"))
|
||||
parser.add_argument('-n', '--dry-run',
|
||||
action='store_true',
|
||||
help=_(u"run in dry-run mode (force to True when using Query-Auto)."))
|
||||
parser.add_argument('-f', '--force',
|
||||
action='store_true',
|
||||
help=_(u"bypass Zephir authorizations."))
|
||||
parser.add_argument('-F', '--force-update',
|
||||
action='store_true',
|
||||
help=_(u"update your server without any confirmation."))
|
||||
|
||||
parser.add_argument('-s', '--simulate',
|
||||
action='store_true',
|
||||
help=_(u"ask apt-get to simulate packages installation"))
|
||||
|
||||
# Level of upgrade
|
||||
maj_level = parser.add_mutually_exclusive_group()
|
||||
maj_level.add_argument('-C', '--candidat', default=False,
|
||||
action='store', nargs='*',
|
||||
choices=['eole', 'envole'],
|
||||
help=_(u"use testing packages."))
|
||||
maj_level.add_argument('-D', '--devel', default=False,
|
||||
action='store', nargs='*',
|
||||
choices=['eole', 'envole'],
|
||||
help=_(u"use development packages."))
|
||||
|
||||
parser.add_argument('--release',
|
||||
help=argparse.SUPPRESS)
|
||||
|
||||
# Action when upgrade is OK
|
||||
parser.add_argument('-r', '--reconfigure',
|
||||
action='store_true',
|
||||
help=_(u"run reconfigure on successful upgrade."))
|
||||
|
||||
parser.add_argument('-R', '--reboot',
|
||||
action='store_true',
|
||||
help=_(u"run reconfigure on successful upgrade and reboot if necessary (implies -r)."))
|
||||
parser.add_argument('--download', action='store_true',
|
||||
help=_(u'only download packages in cache.'))
|
||||
# Mirror selection
|
||||
parser.add_argument('-S', '--eole-mirror',
|
||||
help=_(u"EOLE repository server."))
|
||||
parser.add_argument('-U', '--ubuntu-mirror',
|
||||
help=_(u"Ubuntu repository server."))
|
||||
parser.add_argument('-V', '--envole-mirror',
|
||||
help=_(u"Envole repository server."))
|
||||
parser.add_argument('-c', '--cdrom', action="store_true",
|
||||
help=_(u"use CDROM as source."))
|
||||
|
||||
# sortie EAD
|
||||
parser.add_argument('-W', action='store_true',
|
||||
help=_(u"specific output for EAD."))
|
||||
# mode sans creoled
|
||||
parser.add_argument('-i', '--ignore', action='store_true',
|
||||
help=_(u"ignore local configuration if creoled not responding."))
|
||||
|
||||
|
||||
opts = parser.parse_args()
|
||||
|
||||
if getattr(opts, 'level', None) is None:
|
||||
opts.level = u'updates'
|
||||
if opts.verbose:
|
||||
opts.log_level = 'info'
|
||||
if opts.debug:
|
||||
opts.log_level = 'debug'
|
||||
|
||||
if opts.reboot:
|
||||
opts.reconfigure = True
|
||||
|
||||
return opts
|
||||
|
||||
|
||||
def main():
|
||||
global log
|
||||
opts = parse_cmdline()
|
||||
if opts.W:
|
||||
# variable set for pyeole.ansiprint
|
||||
environ['ModeTxt'] = 'yes'
|
||||
reporting = not (opts.dry_run or opts.simulate or opts.download)
|
||||
if not reporting:
|
||||
z_proc = 'QUERY-MAJ'
|
||||
log = init_logging(name=basename(sys.argv[0]), level=opts.log_level)
|
||||
pkg_log = init_logging(name='pyeole.pkg', level=opts.log_level)
|
||||
diag_log = init_logging(name='pyeole.diagnose', level=opts.log_level)
|
||||
else:
|
||||
z_proc = 'MAJ'
|
||||
report_file = '/var/lib/eole/reports/rapport-maj.log'
|
||||
if isfile(report_file):
|
||||
unlink(report_file)
|
||||
log = init_logging(name=basename(sys.argv[0]), level=opts.log_level,
|
||||
filename=report_file)
|
||||
pkg_log = init_logging(name='pyeole.pkg', level=opts.log_level,
|
||||
filename=report_file)
|
||||
diag_log = init_logging(name='pyeole.diagnose', level=opts.log_level,
|
||||
filename=report_file)
|
||||
set_formatter(log, u'file', u'brief')
|
||||
set_formatter(log, u'file', u'with-levelname-date')
|
||||
set_formatter(pkg_log, u'file', u'with-levelname-date')
|
||||
set_formatter(diag_log, u'file', u'with-levelname-date')
|
||||
report(2)
|
||||
locale.setlocale(locale.LC_TIME, "fr_FR.utf8")
|
||||
log.info(_(u'Update at {0}').format(time.strftime("%A %d %B %Y %H:%M:%S")))
|
||||
raised_err = None
|
||||
error_msg = None
|
||||
try:
|
||||
# gestion du ctrl+c
|
||||
catch_signal(user_exit)
|
||||
acquire('majauto', level='system')
|
||||
atexit.register(release_lock)
|
||||
client = CreoleClient()
|
||||
eole_level = 'stable'
|
||||
envole_level = 'stable'
|
||||
try:
|
||||
version = client.get_creole('eole_release')
|
||||
except (TimeoutCreoleClientError, NotFoundError, CreoleClientError) as err:
|
||||
if opts.ignore:
|
||||
version = EOLE_RELEASE
|
||||
else:
|
||||
raise err
|
||||
if opts.candidat is not False:
|
||||
z_level = " en candidate"
|
||||
# Gestion du niveau par dépôt (16110)
|
||||
if len(opts.candidat) == 0:
|
||||
# Si on ne précise aucun dépôt tout le monde va en candidat
|
||||
eole_level = 'proposed'
|
||||
envole_level = 'proposed'
|
||||
else:
|
||||
# Sinon on vérifie dépôt par dépôt, les dépôts non précisés restent en stable
|
||||
if 'eole' in opts.candidat:
|
||||
eole_level = 'proposed'
|
||||
if 'envole' in opts.candidat:
|
||||
envole_level = 'proposed'
|
||||
elif opts.devel is not False:
|
||||
z_level = " en devel"
|
||||
# Gestion du niveau par dépôt (16110)
|
||||
if len(opts.devel) == 0:
|
||||
# Si on ne précise aucun dépôt tout le monde vas en candidat
|
||||
eole_level = 'unstable'
|
||||
envole_level = 'unstable'
|
||||
else:
|
||||
# Sinon on vérifie dépôt par dépôt, les dépôts non précisés restent en stable
|
||||
if 'eole' in opts.devel:
|
||||
eole_level = 'unstable'
|
||||
if 'envole' in opts.devel:
|
||||
envole_level = 'unstable'
|
||||
else:
|
||||
z_level = ""
|
||||
if opts.release:
|
||||
current_release = int(EOLE_RELEASE.split('.')[-1])
|
||||
new_release = opts.release.split('.')
|
||||
if len(new_release) != 3 or \
|
||||
u'.'.join(new_release[0:2]) != EOLE_VERSION or \
|
||||
int(new_release[2]) not in range(current_release+1, int(LAST_RELEASE) + 1):
|
||||
raise Exception(_('Unknown release number'))
|
||||
z_level += " en {0}".format(opts.release)
|
||||
version = opts.release
|
||||
if opts.cdrom:
|
||||
z_level += " via le CDROM"
|
||||
#distro = 'stable'
|
||||
fonctionseole.zephir("INIT", "Début{0}".format(z_level), z_proc)
|
||||
if zephir_libs and not fonctionseole.init_proc('MAJ'):
|
||||
if opts.force:
|
||||
fonctionseole.zephir("MSG",
|
||||
"Mise à jour forcée par l'utilisateur",
|
||||
z_proc)
|
||||
else:
|
||||
log.warn(_(u"Update is locked, please contact Zéphir administrator"))
|
||||
log.warn(_(u"Use -f option if you want to force execution"))
|
||||
raise UserExitError()
|
||||
lock('maj')
|
||||
PKGMGR = EolePkg('apt', ignore=opts.ignore)
|
||||
if opts.dry_run:
|
||||
PKGMGR.set_option('APT::Get::Simulate', 'true')
|
||||
|
||||
try:
|
||||
module = client.get_creole('eole_module')
|
||||
except (TimeoutCreoleClientError, NotFoundError, CreoleClientError) as err:
|
||||
if opts.ignore:
|
||||
module = 'module'
|
||||
else:
|
||||
raise err
|
||||
try:
|
||||
uai = client.get_creole('numero_etab')
|
||||
except (TimeoutCreoleClientError, NotFoundError, CreoleClientError) as err:
|
||||
if opts.ignore:
|
||||
uai = None
|
||||
else:
|
||||
raise err
|
||||
|
||||
head = "*** {0} {1}"
|
||||
if uai:
|
||||
head += " ({2})"
|
||||
head += " ***\n"
|
||||
|
||||
log.info(head.format(module, version, uai))
|
||||
|
||||
if not opts.force_update:
|
||||
raising_level = u''
|
||||
if opts.release:
|
||||
raising_level = _(u"(CHANGE RELEASE LEVEL)")
|
||||
elif u'unstable' in [eole_level, envole_level]:
|
||||
raising_level = _(u"(UNSTABLE VERSION)")
|
||||
elif u'proposed' in [eole_level, envole_level]:
|
||||
raising_level = _(u"(TESTING VERSION)")
|
||||
|
||||
if raising_level != u'':
|
||||
log.warn(_(u"{0} - Raising update level may prevent "
|
||||
u"lowering back to stable version.").format(raising_level))
|
||||
try:
|
||||
assert question_ouinon(_(u"Do you wish to proceed?")) == 'oui'
|
||||
fonctionseole.zephir("MSG",
|
||||
"Mise à jour{0} forcée par l'utilisateur".format(z_level),
|
||||
z_proc)
|
||||
except (AssertionError, EOFError) as err:
|
||||
log.warn(_(u"Cancelling!"))
|
||||
raise UserExit()
|
||||
|
||||
PKGMGR.check()
|
||||
|
||||
#serveurs à utiliser pour les dépôts Ubuntu et EOLE
|
||||
_configure_sources_mirror(PKGMGR.pkgmgr, ubuntu=opts.ubuntu_mirror,
|
||||
eole=opts.eole_mirror, envole=opts.envole_mirror,
|
||||
ignore=opts.ignore, cdrom=opts.cdrom,
|
||||
release=version, eole_level=eole_level,
|
||||
envole_level=envole_level)
|
||||
|
||||
|
||||
PKGMGR.update(silent=True)
|
||||
upgrades = PKGMGR.get_upgradable_list()
|
||||
|
||||
install = 0
|
||||
upgrade = 0
|
||||
delete = 0
|
||||
for container, packages in upgrades.items():
|
||||
if not packages:
|
||||
continue
|
||||
for name, isInstalled, candidateVersion in packages:
|
||||
if isInstalled:
|
||||
if candidateVersion is None:
|
||||
delete += 1
|
||||
else:
|
||||
upgrade += 1
|
||||
else:
|
||||
install += 1
|
||||
|
||||
total_pkg = install+upgrade
|
||||
|
||||
headers = []
|
||||
if total_pkg == 0:
|
||||
log.info(_(u"Update successful."))
|
||||
log.info(_(u"Nothing to install."))
|
||||
fonctionseole.zephir("FIN",
|
||||
"Aucun paquet à installer{0}".format(z_level),
|
||||
z_proc)
|
||||
if reporting:
|
||||
report(3)
|
||||
sys.exit(0)
|
||||
|
||||
headers.append(_(u"{0} new,", u"{0} news,", install).format(install))
|
||||
headers.append(_(u"{0} upgrade,", u"{0} upgrades,", upgrade).format(upgrade))
|
||||
headers.append(_(u"{0} delete", u"{0} deletes", delete).format(delete))
|
||||
log.info(' '.join(headers))
|
||||
|
||||
for line in PKGMGR.list_upgrade(upgrades=upgrades):
|
||||
log.info(line)
|
||||
|
||||
if opts.dry_run:
|
||||
fonctionseole.zephir("FIN",
|
||||
"{0} paquets à mettre à jour{1}".format(total_pkg, z_level),
|
||||
z_proc)
|
||||
sys.exit(0)
|
||||
|
||||
if opts.download:
|
||||
for container, packages in upgrades.items():
|
||||
if not packages:
|
||||
continue
|
||||
pkgs = []
|
||||
for name, isInstalled, candidateVersion in packages:
|
||||
pkgs.append(name)
|
||||
PKGMGR.fetch_archives(container=container, packages=pkgs)
|
||||
fonctionseole.zephir("FIN",
|
||||
"{0} paquets téléchargés{1}".format(total_pkg, z_level),
|
||||
z_proc)
|
||||
|
||||
elif opts.simulate:
|
||||
PKGMGR.dist_upgrade(simulate=opts.simulate)
|
||||
fonctionseole.zephir("FIN",
|
||||
"{0} paquets mis à jour (simulation){1}".format(total_pkg, z_level),
|
||||
z_proc)
|
||||
|
||||
else:
|
||||
PKGMGR.download_upgrade()
|
||||
PKGMGR.dist_upgrade(simulate=opts.simulate)
|
||||
log.info(_(u"Update successful."))
|
||||
fonctionseole.zephir("FIN",
|
||||
"{0} paquets mis à jour{1}".format(total_pkg, z_level),
|
||||
z_proc)
|
||||
if opts.release:
|
||||
ret_code = system('/usr/share/zephir/scripts/upgrade_distrib.py --auto')
|
||||
if ret_code != 0:
|
||||
error_msg = str('erreur à la mise à jour vers la release {0}'.format(opts.release))
|
||||
else:
|
||||
log.info(_('Upgrade post Maj-Release, please wait'))
|
||||
release('majauto', level='system')
|
||||
cmd = ['/usr/bin/Maj-Auto', '-F']
|
||||
process = Popen(cmd, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=False)
|
||||
ret_code = process.wait()
|
||||
if ret_code != 0:
|
||||
error_msg = str(_('error in post maj release'))
|
||||
if opts.reconfigure:
|
||||
# rechargement des modules python (#7832)
|
||||
# cf. http://code.activestate.com/recipes/81731-reloading-all-modules/
|
||||
if globals().has_key('init_modules'):
|
||||
for m in [x for x in sys.modules.keys() if x not in init_modules]:
|
||||
del(sys.modules[m])
|
||||
else:
|
||||
init_modules = sys.modules.keys()
|
||||
fonctionseole.zephir("MSG",
|
||||
"Reconfiguration automatique",
|
||||
z_proc)
|
||||
elif not opts.release:
|
||||
log.warn(_(u"At least one packages has been updated,"
|
||||
u" use command [reconfigure] to apply modifications."))
|
||||
fonctionseole.zephir("MSG",
|
||||
"Reconfiguration du serveur à planifier",
|
||||
z_proc)
|
||||
|
||||
except (UserExit, UserExitError) as err:
|
||||
if reporting:
|
||||
report(1, 'Stopped by user')
|
||||
fonctionseole.zephir("FIN", "Abandon par l'utilisateur", z_proc)
|
||||
sys.exit(1)
|
||||
|
||||
except (TimeoutCreoleClientError, NotFoundError, CreoleClientError) as err:
|
||||
clue = _(". If restarting creoled service does not help, try {} command with '-i' option.")
|
||||
error_msg = str(err) + clue.format('Query-Auto' if opts.dry_run else 'Maj-Auto')
|
||||
raised_err = err
|
||||
|
||||
except Exception as err:
|
||||
error_msg = str(err)
|
||||
raised_err = err
|
||||
else:
|
||||
if reporting:
|
||||
report(0, reconf=opts.reconfigure)
|
||||
|
||||
if error_msg is not None:
|
||||
fonctionseole.zephir("ERR", error_msg, z_proc, console=False)
|
||||
if reporting:
|
||||
if raised_err is not None:
|
||||
report(1, normalize(err))
|
||||
else:
|
||||
report(1, error_msg)
|
||||
if log is None:
|
||||
# No logger defined, error in argument parsing
|
||||
raise
|
||||
if opts.log_level == 'debug' and raised_err is not None:
|
||||
log.error(err, exc_info=True)
|
||||
else:
|
||||
log.error(error_msg)
|
||||
sys.exit(1)
|
||||
|
||||
if opts.reconfigure:
|
||||
try:
|
||||
reconfigure.main(force_options={'auto': opts.reboot, 'log_level': opts.log_level},
|
||||
force_args=[], need_lock=False)
|
||||
except Exception as err:
|
||||
fonctionseole.zephir("ERR", str(err), z_proc, console=False)
|
||||
if reporting:
|
||||
report(1, normalize(err))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
3
bin/Maj-Cd
Executable file
3
bin/Maj-Cd
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
Maj-Auto --cdrom $@
|
116
bin/Maj-Release
Executable file
116
bin/Maj-Release
Executable file
@ -0,0 +1,116 @@
|
||||
#! /usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
##########################################################################
|
||||
# Maj-Auto - Manage automatique update of EOLE server
|
||||
# Copyright © 2015 Pôle de compétences EOLE <eole@ac-dijon.fr>
|
||||
#
|
||||
# License CeCILL:
|
||||
# * in french: http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html
|
||||
# * in english http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
|
||||
##########################################################################
|
||||
|
||||
from os import system
|
||||
from sys import exit
|
||||
import re
|
||||
from creole.eoleversion import EOLE_RELEASE, LAST_RELEASE, EOLE_VERSION
|
||||
from pyeole.i18n import i18n
|
||||
from pyeole.ihm import print_red
|
||||
|
||||
import argparse
|
||||
from pyeole import scriptargs
|
||||
|
||||
_ = i18n('creole')
|
||||
|
||||
def parse_cmdline():
|
||||
"""Parse commande line.
|
||||
"""
|
||||
description = _(u"This script will upgrade to a new release of this distribution")
|
||||
parser = argparse.ArgumentParser(prog='Maj-Release',
|
||||
description=description,
|
||||
add_help=False)
|
||||
|
||||
parser.add_argument('-h', '--help',
|
||||
action='help',
|
||||
help=_(u"show this help message and exit"))
|
||||
|
||||
parser.add_argument('--release', help=_(u"Target release number"))
|
||||
|
||||
parser.add_argument('-f', '--force', action='store_true',
|
||||
help=_(u"Do not ask confirmation"))
|
||||
|
||||
opts = parser.parse_args()
|
||||
|
||||
return opts
|
||||
|
||||
|
||||
def main():
|
||||
opts = parse_cmdline()
|
||||
|
||||
print(_(u"This script will upgrade to a new release of this distribution"))
|
||||
all_releases = []
|
||||
current_release = int(EOLE_RELEASE.split('.')[-1])
|
||||
choices = range(current_release+1, int(LAST_RELEASE)+1)
|
||||
# Last is firt displayed
|
||||
if choices == []:
|
||||
print_red(_(u"No stable new release available"))
|
||||
exit(1)
|
||||
choices.reverse()
|
||||
for release_suffix in choices:
|
||||
all_releases.append(EOLE_VERSION + '.' + str(release_suffix))
|
||||
|
||||
while True:
|
||||
if opts.release is not None:
|
||||
choice = opts.release
|
||||
else:
|
||||
for idx, release in enumerate(all_releases):
|
||||
print("{0}: {1}".format(idx+1, release))
|
||||
print(_(u"q|quit: abort"))
|
||||
|
||||
try:
|
||||
choice = raw_input("[1] : ")
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print_red(_("\nUpgrade aborted by user"))
|
||||
exit(0)
|
||||
|
||||
if choice == '':
|
||||
# User hit enter
|
||||
choice = 1
|
||||
elif choice in all_releases:
|
||||
# User entrer release number
|
||||
choice = all_releases.index(choice) + 1
|
||||
else:
|
||||
try:
|
||||
choice = int(choice)
|
||||
except ValueError:
|
||||
if re.match(r'^q(uit)?', choice):
|
||||
print_red(_(u"Voluntary stay of proceedings"))
|
||||
exit(0)
|
||||
else:
|
||||
print_red(_(u"Invalid response: {0}").format(choice))
|
||||
if opts.release is not None:
|
||||
exit(1)
|
||||
else:
|
||||
continue
|
||||
|
||||
if not 1 <= choice <= len(choices):
|
||||
print_red(_(u"Invalid response: {0}").format(choice))
|
||||
if opts.release is not None:
|
||||
exit(1)
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
|
||||
release = all_releases[choice - 1]
|
||||
if opts.force:
|
||||
force = '--force-update'
|
||||
else:
|
||||
force = ''
|
||||
|
||||
majrel = system('/usr/bin/Maj-Auto --release {0} {1}'.format(release, force))
|
||||
|
||||
exit(majrel)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
3
bin/Query-Auto
Executable file
3
bin/Query-Auto
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
Maj-Auto --dry-run $@
|
3
bin/Query-Cd
Executable file
3
bin/Query-Cd
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
Maj-Cd --dry-run $@
|
7
bin/StartAll
Executable file
7
bin/StartAll
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Stop all services
|
||||
CreoleService all stop
|
||||
|
||||
# Start only enabled ones
|
||||
CreoleService all start
|
5
bin/Upgrade-Auto
Executable file
5
bin/Upgrade-Auto
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "La commande Upgrade-Auto ne permet plus de changer de sous-version du serveur EOLE."
|
||||
echo "Merci d'utiliser la commande Maj-Release à la place."
|
||||
exit 1
|
65
bin/diagnose
Executable file
65
bin/diagnose
Executable file
@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
###########################################################################
|
||||
# Eole NG - 2007
|
||||
# Copyright Pole de Competence Eole (Ministere Education - Academie Dijon)
|
||||
# Licence CeCill cf /root/LicenceEole.txt
|
||||
# eole@ac-dijon.fr
|
||||
#
|
||||
# diagnose
|
||||
#
|
||||
# Verifie l'instanciation d'un serveur
|
||||
#
|
||||
###########################################################################
|
||||
. /usr/lib/eole/ihm.sh
|
||||
. /usr/lib/eole/utils.sh
|
||||
|
||||
only_root
|
||||
|
||||
CREOLE_FILE="/etc/eole/config.eol"
|
||||
RELEASE_FILE="/etc/eole/release"
|
||||
DIAG_DIR="/usr/share/eole/diagnose"
|
||||
err_prefix="Diagnose impossible"
|
||||
|
||||
TestFile $CREOLE_FILE
|
||||
if [ ${?} -eq 1 ]
|
||||
then
|
||||
EchoRouge "${err_prefix} : le serveur n'est pas instancié"
|
||||
exit 1
|
||||
fi
|
||||
TestFile $RELEASE_FILE
|
||||
if [ ${?} -eq 1 ]
|
||||
then
|
||||
EchoRouge "${err_prefix} : le serveur n'est pas instancié"
|
||||
exit
|
||||
fi
|
||||
TestDir $DIAG_DIR
|
||||
if [ ${?} -eq 1 ]
|
||||
then
|
||||
EchoRouge "${err_prefix} : pas script diagnose disponible"
|
||||
exit 1
|
||||
fi
|
||||
TestCreoled
|
||||
if [ ${?} -eq 1 ]
|
||||
then
|
||||
EchoRouge "${err_prefix} : creoled est arrêté"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Opt=""
|
||||
while getopts "LWT" Option
|
||||
do
|
||||
case $Option in
|
||||
L ) export Verbose="yes";;
|
||||
W ) export ModeEad="yes";;
|
||||
T ) export ModeTxt="yes";;
|
||||
* ) exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
. $RELEASE_FILE
|
||||
DETAILS="$(CreoleGet nom_machine) $(CreoleGet numero_etab)"
|
||||
[ -z "$EOLE_RELEASE" ] && EOLE_RELEASE=$EOLE_VERSION
|
||||
EchoGras "*** Test du module $EOLE_MODULE version $EOLE_RELEASE ($DETAILS) ***"
|
||||
echo
|
||||
run-parts $DIAG_DIR
|
||||
EchoGras "*** FIN DU DIAGNOSTIC ***"
|
27
bin/gen_patch
Executable file
27
bin/gen_patch
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from os import listdir, system, chdir
|
||||
from os.path import isfile, join, basename
|
||||
from creole import config
|
||||
|
||||
modif_dir = basename(config.modif_dir)
|
||||
distrib_dir = basename(config.distrib_dir)
|
||||
patch_dir = basename(config.patch_dir)
|
||||
|
||||
system('clear')
|
||||
|
||||
# on travaille dans le répertoire eole
|
||||
chdir(config.eoleroot)
|
||||
|
||||
print "** Génération des patches à partir de %s **\n" % modif_dir
|
||||
for modfile in listdir(modif_dir):
|
||||
if modfile.endswith('~'):
|
||||
continue
|
||||
if not isfile(join(distrib_dir, modfile)):
|
||||
print "ATTENTION : le fichier original %s n'existe pas !" % join(distrib_dir, modfile)
|
||||
continue
|
||||
print "Génération du patch %s.patch" % modfile
|
||||
system("diff -uNr %s %s > %s.patch" % (join(distrib_dir,modfile), join(modif_dir,modfile), join(patch_dir,modfile)))
|
||||
|
||||
print "\n** Fin de la génération des patch **\n"
|
137
bin/gen_rpt
Executable file
137
bin/gen_rpt
Executable file
@ -0,0 +1,137 @@
|
||||
#!/bin/bash
|
||||
###########################################################################
|
||||
# EOLE - 2010
|
||||
# Copyright Pole de Competence Eole (Ministere Education - Academie Dijon)
|
||||
# Licence CeCill cf /root/LicenceEole.txt
|
||||
# eole@ac-dijon.fr
|
||||
#
|
||||
# gen_rpt
|
||||
#
|
||||
# Génère un rapport d'anomalie
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
TestConf()
|
||||
{
|
||||
[ -e "$1" ] && return 0
|
||||
tput setaf 3
|
||||
echo "* Erreur $0 : le fichier de configuration $1 absent"
|
||||
echo "* Instanciez votre serveur"
|
||||
tput sgr0
|
||||
exit 1
|
||||
}
|
||||
|
||||
clear
|
||||
|
||||
. /usr/lib/eole/ihm.sh
|
||||
. /usr/lib/eole/utils.sh
|
||||
|
||||
only_root
|
||||
|
||||
numero_etab=$(CreoleGet numero_etab)
|
||||
CONFIGEOL='/etc/eole/config.eol'
|
||||
EOLEDIRS="/usr/share/eole/creole/dicos"
|
||||
PATCHDIR="/usr/share/eole/creole/patch"
|
||||
TestConf $CONFIGEOL
|
||||
EOLERELEASE="/etc/eole/release"
|
||||
if [ ! -e $EOLERELEASE ]; then
|
||||
EchoRouge "Fichier $EOLERELEASE est introuvable"
|
||||
exit 1
|
||||
fi
|
||||
. $EOLERELEASE
|
||||
Module="${EOLE_MODULE}-${EOLE_VERSION}"
|
||||
echo "Récupération des informations ..."
|
||||
RepRpt="/tmp/GenRpt"
|
||||
rm -fr $RepRpt 2> /dev/null
|
||||
mkdir $RepRpt
|
||||
mkdir $RepRpt/log
|
||||
mkdir $RepRpt/eole
|
||||
mkdir $RepRpt/system
|
||||
Rpt=$RepRpt"/Rpt-"$Module"-"$numero_etab
|
||||
Mel="eole@ac-dijon.fr"
|
||||
|
||||
# les fichiers texte
|
||||
echo "Config.eol"
|
||||
/bin/cp -f $CONFIGEOL $RepRpt/eole
|
||||
echo "Diagnose"
|
||||
/usr/bin/diagnose -LT >> $RepRpt/diagnose.txt 2>&1
|
||||
echo Pstree
|
||||
pstree >> $RepRpt/system/pstree.txt 2>&1
|
||||
echo Lshw
|
||||
lshw >> $RepRpt/system/lshw.txt 2>&1
|
||||
echo Lsusb
|
||||
lsusb >> $RepRpt/system/lsusb.txt 2>&1
|
||||
echo Lspci
|
||||
lspci >> $RepRpt/system/lspci.txt 2>&1
|
||||
echo Iptables
|
||||
iptables -nvL > $RepRpt/system/iptables.txt 2>&1
|
||||
iptables -nvL -t nat >> $RepRpt/system/iptables.txt 2>&1
|
||||
echo History
|
||||
grep -v "^#" /root/.bash_history > $RepRpt/system/history.txt
|
||||
echo Paquets
|
||||
dpkg-query -W > $RepRpt/system/packages.txt 2>&1
|
||||
# les gz
|
||||
echo Syslog
|
||||
for log in rsyslog su sudo kernel cron auth chpasswd exim ; do
|
||||
[ -d /var/log/rsyslog/local/$log ] && gzip -rc /var/log/rsyslog/local/$log > $RepRpt/log/$log.gz
|
||||
done
|
||||
echo Dmesg
|
||||
dmesg > $RepRpt/log/dmesg.log 2>&1
|
||||
gzip $RepRpt/log/dmesg.log
|
||||
echo Creole.log
|
||||
gzip -c /var/log/reconfigure.log > $RepRpt/log/reconfigure.log.gz
|
||||
echo Dicos
|
||||
gzip -rc $EOLEDIRS > $RepRpt/eole/dicos.gz
|
||||
echo Patch
|
||||
gzip -rc $PATCHDIR > $RepRpt/eole/patch.gz
|
||||
echo Stats
|
||||
gzip -rc /usr/share/zephir/monitor/stats > $RepRpt/stats.gz
|
||||
|
||||
# spécifique Scribe
|
||||
if [ -f /var/www/ead/extraction/tmp/rapport.txt ];then
|
||||
echo "Rapport d'extraction"
|
||||
gzip -rc /var/www/ead/extraction/tmp/rapport.txt > $RepRpt/log/extraction.log.gz
|
||||
fi
|
||||
if [ -f /var/log/controle-vnc/main.log ];then
|
||||
echo 'Log client scribe'
|
||||
gzip -rc /var/log/controle-vnc/main.log > $RepRpt/log/controle-vnc.log.gz
|
||||
fi
|
||||
|
||||
# spécifique Scribe/Horus/Eclair
|
||||
if [ -d /var/lib/eole/reports ];then
|
||||
echo "Rapport (sauvegarde/maj/...)"
|
||||
gzip -rc /var/lib/eole/reports > $RepRpt/log/rapport.log.gz
|
||||
fi
|
||||
|
||||
# spécifique Amon
|
||||
if [ -f '/usr/share/eole/test-rvp' ];then
|
||||
echo 'Rvp'
|
||||
/usr/sbin/ipsec status &> $RepRpt/ipsec.status 2>&1
|
||||
fi
|
||||
|
||||
# Rapport debsums
|
||||
if [ -x '/usr/share/eole/debsums/show-reports.py' ]; then
|
||||
echo "Rapport debsums"
|
||||
/usr/share/eole/debsums/show-reports.py > ${RepRpt}/log/rapport-debsums.log 2>&1
|
||||
fi
|
||||
|
||||
echo
|
||||
Archive=$Module-$numero_etab".tar.gz"
|
||||
echo "Création de l'archive locale $Archive"
|
||||
tar -C /tmp -czf $Archive GenRpt
|
||||
echo
|
||||
|
||||
Question_ouinon "Envoyer l'archive par email ?"
|
||||
if [ $? -eq 1 ];then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Destinataire du message : "
|
||||
echo -n "[$Mel] : "
|
||||
read mail
|
||||
if [ "$mail" == "" ];then
|
||||
mail=$Mel
|
||||
fi
|
||||
echo -n "Commentaire : "
|
||||
read comment
|
||||
echo "$comment"|mutt -a $Archive -s "Rapport $Module de $numero_etab" -c $mail -e "set copy=no"
|
24
bin/instance
Executable file
24
bin/instance
Executable file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Application de la configuration EOLE
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
from creole.reconfigure import main
|
||||
from creole.error import UserExitError, LockError, UnlockError, UserExit
|
||||
from pyeole.ihm import only_root
|
||||
|
||||
only_root()
|
||||
|
||||
try:
|
||||
# Force interactive mode
|
||||
main(force_options={'interactive': True})
|
||||
except (UserExitError, LockError, UnlockError):
|
||||
sys.exit(1)
|
||||
except UserExit:
|
||||
sys.exit(0)
|
||||
except:
|
||||
#FIXME: log & affichage géré au raise ?
|
||||
sys.exit(1)
|
173
bin/manage-eole
Executable file
173
bin/manage-eole
Executable file
@ -0,0 +1,173 @@
|
||||
#!/bin/bash
|
||||
##########################################################
|
||||
#
|
||||
# Eole NG - 2010
|
||||
# Copyright Pole de Competence Eole (Ministere Education - Academie Dijon)
|
||||
# Licence CeCill http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html
|
||||
# eole@ac-dijon.fr
|
||||
#
|
||||
# Gestion des modules en mode dialogue
|
||||
# avec les comptes système eole, eole2
|
||||
#
|
||||
##########################################################
|
||||
|
||||
# un seul manage ?
|
||||
pmanage=`pgrep manage-eole`
|
||||
nbmanage=`echo $pmanage | wc -w`
|
||||
|
||||
# fichiers temporaires
|
||||
temp="/tmp/InBox-Eol-"
|
||||
tempfile="$temp$$"
|
||||
|
||||
TitreGen="Eole - Gestion du Serveur"
|
||||
|
||||
##########################################################
|
||||
# Fonctions reprises de FonctionsEole
|
||||
##########################################################
|
||||
|
||||
MenuBox()
|
||||
{
|
||||
#${1="Votre Saisie"}
|
||||
#${2="Saisie"}
|
||||
NBlignes=${NBlignes=5}
|
||||
Menu="$3"
|
||||
dialog $NOMOUSE1 --backtitle "$TitreGen" \
|
||||
--aspect 45 --clear \
|
||||
--menu "$1" 16 50 $NBlignes \
|
||||
$Menu 2> $tempfile
|
||||
retval=$?
|
||||
case $retval in
|
||||
0)
|
||||
eval $2="`cat $tempfile`";;
|
||||
1) # Cancel
|
||||
eval $2="CANCEL";;
|
||||
255) # ESC
|
||||
if test -s $tempfile ;
|
||||
then
|
||||
eval $2=`cat $tempfile`
|
||||
else
|
||||
eval $2="ESC"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
OkBox()
|
||||
{
|
||||
dialog $NOMOUSE1 --backtitle "$TitreGen" \
|
||||
--aspect 45 --cancel-label Abandon\
|
||||
--msgbox "$1" 0 0
|
||||
}
|
||||
|
||||
QuestionBox()
|
||||
{
|
||||
#${1=Votre Saisie"}
|
||||
#${2="Saisie"}
|
||||
dialog $NOMOUSE1 --backtitle "$TitreGen" \
|
||||
--aspect 45 --clear \
|
||||
--yesno "$1" 16 50
|
||||
retval=$?
|
||||
case $retval in
|
||||
0)
|
||||
eval $2="OUI";;
|
||||
1) # Cancel
|
||||
eval $2="NON";;
|
||||
255) # ESC
|
||||
eval $2="ESC" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
Entree(){
|
||||
echo
|
||||
echo "Tapez <Entrée>"
|
||||
read Bidon
|
||||
}
|
||||
|
||||
CleanExit(){
|
||||
echo "Au revoir !"
|
||||
rm -f $tempfile
|
||||
exit $1
|
||||
}
|
||||
|
||||
##########################################################
|
||||
# Programme principal
|
||||
##########################################################
|
||||
|
||||
if [ $nbmanage -gt 1 ]
|
||||
then
|
||||
MenuBox "D'autres instances de manage-eole ont été détectées" Rep "1 Quitter_sans_tuer 2 Quitter_et_tuer"
|
||||
rm -f "$temp*"
|
||||
if [ "$Rep" == "2" ]
|
||||
then
|
||||
for pid in $pmanage
|
||||
do
|
||||
kill -9 $pid
|
||||
done
|
||||
fi
|
||||
CleanExit 0
|
||||
fi
|
||||
|
||||
OkBox "Administration EOLE\n\nPour Vous Deplacer sur l'Ecran\nUtiliser votre Souris\nOu la touche tabulation.\n\n"
|
||||
|
||||
Rep=""
|
||||
while [ 1 ]
|
||||
do
|
||||
# FIXME/TODO : ajouter des entrées de menu !
|
||||
MenuBox "Votre Choix" Rep "1 Diagnostic 2 Reconfiguration 3 Paquets_en_Maj 4 Mise_A_Jour 8 Redemarrer_Serveur 9 Arret_Serveur ! Shell_Linux Q Quitter"
|
||||
|
||||
if [ "$Rep" == "CANCEL" ]
|
||||
then
|
||||
CleanExit 1
|
||||
fi
|
||||
|
||||
case $Rep in
|
||||
1)
|
||||
echo "En cours ..."
|
||||
sudo /usr/bin/diagnose
|
||||
Entree
|
||||
;;
|
||||
2)
|
||||
sudo /usr/bin/reconfigure
|
||||
Entree
|
||||
;;
|
||||
3)
|
||||
sudo /usr/bin/Query-Auto
|
||||
Entree
|
||||
;;
|
||||
4)
|
||||
sudo /usr/bin/Maj-Auto
|
||||
Entree
|
||||
;;
|
||||
# TODO : pouvoir inclure des entrées venant d'ailleurs ;)
|
||||
#5)
|
||||
#sudo /usr/share/eole/Maj-blacklist.sh
|
||||
#Entree
|
||||
#;;
|
||||
8)
|
||||
QuestionBox "Vous avez demandé le redémarrage du serveur\nEtes vous sur ?" Rep
|
||||
if [ "$Rep" == "OUI" ]
|
||||
then
|
||||
sudo /sbin/reboot
|
||||
sleep 1
|
||||
CleanExit 0
|
||||
fi
|
||||
;;
|
||||
9)
|
||||
QuestionBox "Vous avez demandé un arret total du serveur\nEtes vous sur ?" Rep
|
||||
if [ "$Rep" == "OUI" ]
|
||||
then
|
||||
sudo /sbin/halt -p
|
||||
sleep 1
|
||||
CleanExit 0
|
||||
fi
|
||||
;;
|
||||
!)
|
||||
echo "\"exit\" ou \"Ctrl + d\" pour revenir au Menu"
|
||||
/bin/bash
|
||||
;;
|
||||
Q)
|
||||
CleanExit 0
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
22
bin/reconfigure
Executable file
22
bin/reconfigure
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Application de la configuration EOLE
|
||||
"""
|
||||
|
||||
import sys
|
||||
from creole.reconfigure import main
|
||||
from creole.error import UserExitError, LockError, UnlockError, UserExit
|
||||
from pyeole.ihm import only_root
|
||||
|
||||
only_root()
|
||||
|
||||
try:
|
||||
main()
|
||||
except (UserExitError, LockError, UnlockError):
|
||||
sys.exit(1)
|
||||
except UserExit:
|
||||
sys.exit(0)
|
||||
except:
|
||||
#FIXME: log & affichage géré au raise ?
|
||||
sys.exit(1)
|
Reference in New Issue
Block a user