for creole's zephir2 branch
This commit is contained in:
27
upgrade/DistUpgradeViewEOLE.py
Normal file
27
upgrade/DistUpgradeViewEOLE.py
Normal file
@ -0,0 +1,27 @@
|
||||
from __future__ import absolute_import, print_function
|
||||
from .DistUpgradeViewNonInteractive import DistUpgradeViewNonInteractive
|
||||
z_proc = "UPGRADE"
|
||||
try:
|
||||
from pyeole.ansiprint import print_red
|
||||
except:
|
||||
print_red = print
|
||||
try:
|
||||
# import zephir logger if registered
|
||||
from zephir.zephir_conf.zephir_conf import id_serveur
|
||||
from zephir.lib_zephir import log as zlog
|
||||
import time
|
||||
except:
|
||||
zlog = None
|
||||
|
||||
class DistUpgradeViewEOLE(DistUpgradeViewNonInteractive):
|
||||
def error(self, summary, msg, extended_msg=None):
|
||||
" display an error "
|
||||
print_red("Une erreur est survenue : %s %s (%s)" % (summary, msg, extended_msg))
|
||||
if zlog is not None:
|
||||
zlog(z_proc, -2, "Une erreur est survenue : %s" % summary, str(time.ctime()))
|
||||
super(DistUpgradeViewEOLE, self).error(summary, msg, extended_msg)
|
||||
def abort(self):
|
||||
if zlog is not None:
|
||||
zlog(z_proc, 1, "Une erreur fatale est survenue Vous trouverez plus d'informations dans les journaux : /var/log/dist-upgrade/", str(time.ctime()))
|
||||
print_red("Une erreur fatale est survenue. Vous trouverez plus d'informations dans les journaux : /var/log/dist-upgrade/")
|
||||
super(DistUpgradeViewEOLE, self).abort()
|
37
upgrade/EOLEPostInstallScripts.py
Executable file
37
upgrade/EOLEPostInstallScripts.py
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from os import system
|
||||
from os.path import join
|
||||
from pyeole.ihm import print_title, print_red
|
||||
from creole.fonctionseole import zephir
|
||||
|
||||
POST_UPGRADE = 'post_upgrade'
|
||||
# nom de procédure pour les logs Zéphir
|
||||
z_proc = "UPGRADE"
|
||||
|
||||
# Variable déclarée en double (cf Upgrade-Auto)
|
||||
RUNPARTS_CMD = u'/bin/run-parts --exit-on-error -v {directory}'
|
||||
|
||||
if __name__ == "__main__":
|
||||
#FIXME
|
||||
tmp_dir = '/tmp/Upgrade-Auto'
|
||||
post_upgrade = join(tmp_dir, POST_UPGRADE)
|
||||
print_title("Instructions préalables spécifiques au module")
|
||||
system('/usr/share/creole/gen_certif.py')
|
||||
code = system(RUNPARTS_CMD.format(directory=post_upgrade))
|
||||
if code != 0:
|
||||
zephir("ERR", u'Erreur dans un script post_upgrade)', z_proc)
|
||||
print_red((u'Erreur {0}').format(post_upgrade))
|
||||
exit(1)
|
||||
#Ne pas faire d'import ... doit être celui de la version de destination
|
||||
#FIXME
|
||||
# echo "EOLE \l
|
||||
# Serveur migré de 2.3 vers $NEW_VERS
|
||||
# " > /etc/issue
|
||||
#FIXME apt-get clean ?
|
||||
print_title("Mise à jour des informations dans l'application Zéphir ...")
|
||||
#Ne pas faire d'import ... doit être celui de la version de destination
|
||||
system('/usr/share/zephir/scripts/upgrade_distrib.py')
|
||||
zephir("FIN", 'procédure Upgrade-Auto terminée avec succès', z_proc)
|
||||
|
596
upgrade/Upgrade-Auto
Executable file
596
upgrade/Upgrade-Auto
Executable file
@ -0,0 +1,596 @@
|
||||
#!/usr/bin/python -u
|
||||
# -*- 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
|
||||
##########################################################################
|
||||
|
||||
import sys
|
||||
|
||||
import warnings
|
||||
import apt
|
||||
|
||||
import atexit
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import locale
|
||||
from pyeole.i18n import i18n
|
||||
from pyeole import lock
|
||||
from pyeole.process import system_code
|
||||
from pyeole.ihm import print_title, print_red, print_green
|
||||
from pyeole.ihm import question_ouinon
|
||||
from creole.config import configeoldir
|
||||
|
||||
from os import system
|
||||
from os import access
|
||||
from os import R_OK
|
||||
from os import mkdir
|
||||
from os import unlink
|
||||
from os.path import join
|
||||
from os.path import isfile
|
||||
from os.path import isdir
|
||||
|
||||
import time
|
||||
import re
|
||||
from shutil import copytree
|
||||
from shutil import copy
|
||||
from pyeole.pkg import EolePkg, _configure_sources_mirror
|
||||
from creole.fonctionseole import controle_kernel, zephir
|
||||
from creole.config import eoledir
|
||||
from creole.config import templatedir
|
||||
from creole.config import vareole
|
||||
from creole.template import CreoleTemplateEngine
|
||||
from creole.client import CreoleClient
|
||||
|
||||
from glob import glob
|
||||
import hashlib
|
||||
from urllib2 import urlopen
|
||||
from urllib2 import ProxyHandler
|
||||
from urllib2 import build_opener
|
||||
from HTMLParser import HTMLParser
|
||||
|
||||
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
|
||||
|
||||
_ = i18n('update-manager')
|
||||
|
||||
if not isfile(join(configeoldir, '.upgrade_available')):
|
||||
print ""
|
||||
print_red(_(u'Upgrade to a newer major version is not available'))
|
||||
print _(u'Use Maj-Release script to upgrade to next minoir version')
|
||||
print ""
|
||||
sys.exit(1)
|
||||
|
||||
from UpdateManager.Core.MetaRelease import MetaReleaseCore
|
||||
from UpdateManager.Core.DistUpgradeFetcherCore import DistUpgradeFetcherCore
|
||||
from DistUpgrade.utils import init_proxy
|
||||
|
||||
quit_re = re.compile(r'q|(quit)|(exit)|(abort)', re.I)
|
||||
|
||||
tmp_dir = '/tmp/Upgrade-Auto'
|
||||
|
||||
def release_lock():
|
||||
if lock.is_locked('upgrade-auto', level='system'):
|
||||
lock.release('upgrade-auto', level='system')
|
||||
|
||||
|
||||
class EOLEDistUpgradeFetcherCore(DistUpgradeFetcherCore):
|
||||
def verifyDistUprader(self, *args, **kwargs):
|
||||
copy(join(tmp_dir, 'DistUpgradeViewEOLE.py'), self.tmpdir)
|
||||
return super(EOLEDistUpgradeFetcherCore, self).verifyDistUprader(*args, **kwargs)
|
||||
|
||||
|
||||
def cli_choice(alternatives, prompt, title=None, guess=False):
|
||||
"""
|
||||
Display choices in terminal and return chosen one
|
||||
:param alternatives: choices proposed to user
|
||||
:type alternatives: list
|
||||
:param guess: wether to guess choice
|
||||
:type guess: boolean
|
||||
"""
|
||||
def default_input(alt_mapping, prompt, title=None, guess=False):
|
||||
choices = "\n".join(["[{0}] {1}".format(alt[0], alt[1])
|
||||
for alt in alt_mapping.items()])
|
||||
choices = _(u"Available choices:\n{}\n").format(choices)
|
||||
if title is not None:
|
||||
print_green(title)
|
||||
print choices
|
||||
if guess is True and len(alt_mapping) < 2:
|
||||
print_green(_(u"Automatically selected first choice: {}\n").format(alt_mapping[1]))
|
||||
choice = "1"
|
||||
else:
|
||||
try:
|
||||
prompt = prompt + _(u"\n[1]: ")
|
||||
choice = raw_input(prompt)
|
||||
except KeyboardInterrupt, EOFError:
|
||||
print _("\nUpgrade aborted by user")
|
||||
sys.exit(0)
|
||||
if choice == '':
|
||||
choice = "1"
|
||||
return choice
|
||||
|
||||
alt_mapping = {num + 1: choice for num, choice in enumerate(alternatives)}
|
||||
choice = default_input(alt_mapping, prompt, title=title, guess=guess)
|
||||
if choice not in alt_mapping.values():
|
||||
try:
|
||||
choice = alt_mapping[int(choice)]
|
||||
except KeyError:
|
||||
print _("Choice {} not available\n").format(choice)
|
||||
choice = cli_choice(alternatives, prompt, guess=guess)
|
||||
except ValueError:
|
||||
if quit_re.match(choice):
|
||||
print _("Upgrade cancelled by user")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print _("Invalid input: {}\n").format(choice)
|
||||
choice = cli_choice(alternatives, prompt, guess=guess)
|
||||
return choice
|
||||
|
||||
|
||||
def upgrade_container_source(container):
|
||||
"""Edit source list in container
|
||||
:param container: container name
|
||||
:type container: str
|
||||
"""
|
||||
print 'changement des sources.list pour le conteneur ', container
|
||||
source_list = '/opt/lxc/{}/rootfs/etc/apt/sources.list'.format(container)
|
||||
with open(source_list) as old_source:
|
||||
sources = old_source.read()
|
||||
with open(source_list, 'w') as new_source:
|
||||
new_source.write(sources.replace('precise', 'trusty'))
|
||||
cmd = ['apt-get', 'update']
|
||||
code = system_code(cmd, container=container)
|
||||
return code
|
||||
|
||||
|
||||
ALTERNATIVES = ("2.5.1", )
|
||||
RUNPARTS_CMD = u'/bin/run-parts --exit-on-error -v {directory}'
|
||||
PRE_DOWNLOAD = 'pre_download'
|
||||
UPGRADE_DIR = join(eoledir, 'upgrade')
|
||||
ISO_DIR = join(vareole, 'iso')
|
||||
ISO_URL_BASE = 'http://eole.ac-dijon.fr/pub/iso'
|
||||
z_proc = "UPGRADE"
|
||||
|
||||
class ExtractEOLEVersions(HTMLParser):
|
||||
"""Extrat stable EOLE versions from HTML page
|
||||
|
||||
Gathered versions are stored in ``self.versions``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, version):
|
||||
HTMLParser.__init__(self)
|
||||
self.version = version
|
||||
self.versions = []
|
||||
self.process_a = False
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
if tag != 'a':
|
||||
self.process_a = False
|
||||
return
|
||||
self.process_a = True
|
||||
|
||||
|
||||
def handle_data(self, data):
|
||||
if not self.process_a:
|
||||
return
|
||||
|
||||
# Strip not matching and pre stable versions
|
||||
if data.lower().startswith(self.version) and '-' not in data:
|
||||
self.versions.append(data.rstrip('/'))
|
||||
|
||||
|
||||
def get_most_recent_version(match, url, proxy=None):
|
||||
"""Get the most recent matching version
|
||||
|
||||
"""
|
||||
if proxy is not None:
|
||||
proxy_handler = ProxyHandler({'http': proxy,
|
||||
'https': proxy})
|
||||
else:
|
||||
proxy_handler = ProxyHandler({})
|
||||
|
||||
opener = build_opener(proxy_handler)
|
||||
http_request = opener.open(url)
|
||||
html_parser = ExtractEOLEVersions(match)
|
||||
html_parser.feed(http_request.read())
|
||||
html_parser.versions.sort()
|
||||
return html_parser.versions[-1]
|
||||
|
||||
|
||||
def build_iso_name(version):
|
||||
"""Build ISO name for version
|
||||
|
||||
"""
|
||||
arch = apt.apt_pkg.config.get('APT::Architecture')
|
||||
iso_name = 'eole-{version}-alternate-{arch}.iso'.format(version=version,
|
||||
arch=arch)
|
||||
return iso_name
|
||||
|
||||
|
||||
def build_release_url(version, proxy=None):
|
||||
"""Build the URL of latest release of a version
|
||||
|
||||
"""
|
||||
version_url = ISO_URL_BASE + '/EOLE-' + '.'.join(version.split('.')[0:2])
|
||||
latest_version = get_most_recent_version(version, version_url, proxy)
|
||||
release_url = '{base}/{release}'.format(base=version_url,
|
||||
release=latest_version)
|
||||
return release_url
|
||||
|
||||
|
||||
def check_iso(iso_name, path, release_url, proxy=None):
|
||||
"""Verify checksum and signature
|
||||
|
||||
"""
|
||||
sha256_file = join(ISO_DIR, 'SHA256SUMS')
|
||||
sha256_url = release_url + '/SHA256SUMS'
|
||||
|
||||
sha256_gpg_file = join(ISO_DIR, 'SHA256SUMS.gpg')
|
||||
sha256_gpg_url = sha256_url + '.gpg'
|
||||
|
||||
sha256 = hashlib.sha256()
|
||||
|
||||
iso_ok = False
|
||||
|
||||
print _(u"Verifying ISO image {iso}").format(iso=path)
|
||||
|
||||
if not isfile(sha256_file):
|
||||
print _(u"Download SHA256SUMS file")
|
||||
download_with_wget(sha256_file, sha256_url, proxy)
|
||||
|
||||
if not isfile(sha256_gpg_file):
|
||||
print _(u"Download SHA256SUMS.gpg file")
|
||||
download_with_wget(sha256_gpg_file, sha256_gpg_url, proxy)
|
||||
|
||||
print _(u"Check SHA256SUMS file signature")
|
||||
|
||||
gpg_cmd = ['gpgv', '-q', '--keyring',
|
||||
'/etc/apt/trusted.gpg.d/eole-archive-keyring.gpg',
|
||||
sha256_gpg_file, sha256_file]
|
||||
|
||||
ret = system_code(gpg_cmd)
|
||||
if ret == 0:
|
||||
print _(u"Check ISO SHA256..."),
|
||||
sha_fh = open(sha256_file, 'r')
|
||||
for line in sha_fh:
|
||||
sha, filename = line.split()
|
||||
if filename != '*{iso_name}'.format(iso_name=iso_name):
|
||||
continue
|
||||
|
||||
with open(path, 'rb') as iso_fh:
|
||||
while True:
|
||||
block = iso_fh.read(2**10)
|
||||
if not block:
|
||||
break
|
||||
|
||||
sha256.update(block)
|
||||
|
||||
iso_ok = sha == sha256.hexdigest()
|
||||
if iso_ok:
|
||||
print _(u'OK')
|
||||
return True
|
||||
|
||||
print _(u'Error')
|
||||
|
||||
|
||||
# Default
|
||||
return False
|
||||
|
||||
|
||||
def download_with_wget(out_file, url, proxy=None, limit_rate="0"):
|
||||
"""Use wget to download a file with a progress bar and rate limit
|
||||
|
||||
"""
|
||||
wcmd = ['wget', '-c', '--progress', 'dot:giga']
|
||||
if limit_rate != '0':
|
||||
wcmd.extend(['--limit-rate', limit_rate])
|
||||
|
||||
wcmd.extend(['-O', out_file, url])
|
||||
|
||||
if proxy is not None:
|
||||
env = {'http_proxy': proxy,
|
||||
'https_proxy': proxy}
|
||||
else:
|
||||
env = {}
|
||||
|
||||
if not system_code(wcmd, env=env) == 0:
|
||||
err_msg = _("Error downloading {file} with wget from {url}")
|
||||
err_msg = err_msg.format(file=out_file, url=url)
|
||||
zephir("ERR", err_msg, z_proc)
|
||||
raise SystemError(err_msg)
|
||||
|
||||
def download_iso_with_zsync(iso_file, iso_url):
|
||||
"""Use zsync to download the ISO
|
||||
|
||||
"""
|
||||
zcmd = ['zsync', '-o', iso_file, iso_url + '.zsync']
|
||||
if not system_code(zcmd) == 0:
|
||||
err_msg = _("Error downloading the image with zsync")
|
||||
zephir("ERR", err_msg, z_proc)
|
||||
raise SystemError(err_msg)
|
||||
|
||||
def clean_iso_dir(iso_file=None):
|
||||
"""Clean ISO directory
|
||||
|
||||
If :data:`iso_file` is not `None`, it's keept
|
||||
|
||||
"""
|
||||
# Remove any file other than targeted release ISO
|
||||
# This permit to resume download
|
||||
for filename in glob('{iso_dir}/*'.format(iso_dir=ISO_DIR)):
|
||||
if filename == iso_file:
|
||||
continue
|
||||
|
||||
unlink(filename)
|
||||
|
||||
def get_cdrom_device():
|
||||
device = None
|
||||
client = CreoleClient()
|
||||
mount_point = '/media/cdrom'
|
||||
mounted = False
|
||||
if not isdir(mount_point):
|
||||
mkdir(mount_point)
|
||||
|
||||
for cdrom in client.get_creole('cdrom_devices'):
|
||||
cmd = ['/bin/mount', cdrom, mount_point, '-o', 'ro']
|
||||
if system_code(cmd) != 0:
|
||||
continue
|
||||
|
||||
mounted = True
|
||||
|
||||
if isdir('{0}/dists'.format(mount_point)):
|
||||
device = cdrom
|
||||
|
||||
cmd = ['/bin/umount', mount_point]
|
||||
if system_code(cmd) != 0:
|
||||
err_msg = _("Unable to umount {cdrom}").format(cdrom=cdrom)
|
||||
zephir("ERR", err_msg, z_proc)
|
||||
raise SystemError(err_msg)
|
||||
|
||||
if device is not None:
|
||||
break
|
||||
|
||||
return device
|
||||
|
||||
|
||||
def download_iso(args):
|
||||
"""Download ISO image
|
||||
|
||||
Download an ISO image from internet or copy one from :data:`path`.
|
||||
|
||||
:parameter path: path of an existing ISO image
|
||||
:type path: `str`
|
||||
|
||||
"""
|
||||
proxy = None
|
||||
client = CreoleClient()
|
||||
|
||||
if client.get_creole('activer_proxy_client') == u'oui':
|
||||
address = client.get_creole('proxy_client_adresse')
|
||||
port = client.get_creole('proxy_client_port')
|
||||
proxy = 'http://{address}:{port}'.format(address=address, port=port)
|
||||
|
||||
release_url = build_release_url(args.release, proxy)
|
||||
iso_name = build_iso_name(args.release)
|
||||
iso_file = join(ISO_DIR, iso_name)
|
||||
iso_url = '{url}/{iso}'.format(url=release_url, iso=iso_name)
|
||||
|
||||
print_title(_(u"Downloading ISO image for {release}").format(release=args.release))
|
||||
|
||||
if not isdir(ISO_DIR):
|
||||
mkdir(ISO_DIR)
|
||||
|
||||
if isfile(iso_file) and check_iso(iso_name, iso_file, release_url, proxy):
|
||||
# ISO is downloaded and verified
|
||||
return True
|
||||
|
||||
# Remove SHA265SUMS* files
|
||||
# Keep ISO to resume download if possible
|
||||
clean_iso_dir(iso_file)
|
||||
err_msg = None
|
||||
|
||||
if args.cdrom or args.iso is not None:
|
||||
|
||||
if args.cdrom:
|
||||
path = get_cdrom_device()
|
||||
if path is None:
|
||||
err_msg = _("No CDROM found")
|
||||
else:
|
||||
path = args.iso
|
||||
if not isfile(path):
|
||||
err_msg = _("No such file: {iso}").format(iso=path)
|
||||
elif not access(path, R_OK):
|
||||
err_msg = _("Unreadable file: {iso}").format(iso=path)
|
||||
if err_msg is None:
|
||||
# Should we also check source image before copying?
|
||||
# elif not check_iso(iso_name, path, release_url):
|
||||
# raise SystemError("ISO image is not valid for {iso}".format(iso=path))
|
||||
|
||||
print _("Copying {source} to {iso}").format(source=path, iso=iso_file)
|
||||
|
||||
copy(path, iso_file)
|
||||
|
||||
if not check_iso(iso_name, iso_file, release_url, proxy):
|
||||
# Copy was OK but check fails
|
||||
# Remove copied ISO as it may be corrupted and prevent
|
||||
# futur download
|
||||
clean_iso_dir()
|
||||
msg = _("Error checking ISO after copy, remove {iso}")
|
||||
err_msg = msg.format(iso=iso_file)
|
||||
|
||||
else:
|
||||
# Try resuming download
|
||||
download_with_wget(iso_file, iso_url, proxy, args.limit_rate)
|
||||
# download_iso_with_zsync(iso_file, iso_url)
|
||||
|
||||
if not check_iso(iso_name, iso_file, release_url, proxy):
|
||||
# Download was OK but check fails
|
||||
# Remove downloaded ISO as it may be fully downloaded but
|
||||
# corrupted and prevent futur download
|
||||
clean_iso_dir()
|
||||
msg = _(u"Error checking ISO image after download, remove {iso}")
|
||||
err_msg = msg.format(iso=iso_file)
|
||||
|
||||
if err_msg:
|
||||
zephir('ERR', err_msg, z_proc)
|
||||
raise SystemError(err_msg)
|
||||
|
||||
def main():
|
||||
args_parser = ArgumentParser(description=_("EOLE distribution upgrade tool."))
|
||||
|
||||
args_parser.add_argument('--release',
|
||||
help=_(u"Target release number"))
|
||||
|
||||
args_parser.add_argument('--download', action='store_true',
|
||||
help=_(u"Only download the ISO image"))
|
||||
|
||||
args_parser.add_argument('--iso', metavar=u'PATH',
|
||||
help=_(u"Path to an ISO image"))
|
||||
|
||||
args_parser.add_argument('--cdrom', action='store_true',
|
||||
help=_(u"Use CDROM device instead of downloading ISO image"))
|
||||
|
||||
args_parser.add_argument('--limit-rate', metavar=u'BANDWIDTH', default='120k',
|
||||
help=_(u"Pass limit rate to wget. “0” to disable."))
|
||||
|
||||
args_parser.add_argument('-f', '--force', action='store_true',
|
||||
help=_(u"Do not ask confirmation"))
|
||||
|
||||
args = args_parser.parse_args()
|
||||
|
||||
|
||||
try:
|
||||
locale.setlocale(locale.LC_ALL, "")
|
||||
except:
|
||||
pass
|
||||
|
||||
print_red(_(u"This script will upgrade this server to a new release"))
|
||||
print_red(_(u"Modifications will be irreversible."))
|
||||
init_proxy()
|
||||
zephir("INIT", _(u"Starting Upgrade-Auto ({})").format(" ".join(sys.argv[1:])), z_proc)
|
||||
|
||||
# Ask for release if none provided on command line
|
||||
if args.release is not None:
|
||||
if args.release not in ALTERNATIVES:
|
||||
msg = _(u"Invalid release {version} use: {values}")
|
||||
err_msg = msg.format(version=args.release,
|
||||
values=', '.join(ALTERNATIVES))
|
||||
zephir("ERR", err_msg, z_proc)
|
||||
print err_msg
|
||||
sys.exit(1)
|
||||
else:
|
||||
title = _(u"Choose which version you want to upgrade to\n")
|
||||
prompt = _(u"Which version do you want to upgrade to (or 'q' to quit)?")
|
||||
args.release = cli_choice(ALTERNATIVES, prompt, title=title, guess=False)
|
||||
|
||||
|
||||
if not args.force:
|
||||
confirmation_msg = _(u"Do you really want to upgrade to version {}?")
|
||||
if question_ouinon(confirmation_msg.format(args.release)) != 'oui':
|
||||
end_msg = _(u'Upgrade cancelled by user')
|
||||
zephir("FIN", end_msg, z_proc)
|
||||
print end_msg
|
||||
sys.exit(0)
|
||||
|
||||
lock.acquire('upgrade-auto', valid=False, level='system')
|
||||
atexit.register(release_lock)
|
||||
|
||||
if not args.download:
|
||||
print_title(_("Check update status"))
|
||||
PKGMGR = EolePkg('apt', ignore=False)
|
||||
PKGMGR.set_option('APT::Get::Simulate', 'true')
|
||||
_configure_sources_mirror(PKGMGR.pkgmgr)
|
||||
PKGMGR.update(silent=True)
|
||||
upgrades = PKGMGR.get_upgradable_list()
|
||||
|
||||
for container, packages in upgrades.items():
|
||||
if packages:
|
||||
err_msg = _(u"Some packages are not up-to-date!")
|
||||
zephir("ERR", err_msg, z_proc)
|
||||
print_red(err_msg)
|
||||
print_red(_(u"Update this server (Maj-Auto) before another attempt to upgrade"))
|
||||
sys.exit(1)
|
||||
|
||||
print_green(_(u'Server is up-to-date'))
|
||||
|
||||
if controle_kernel():
|
||||
err_msg = _(u"In order to upgrade, most recent kernel endorsed for this release must be used")
|
||||
zephir("ERR", err_msg, z_proc)
|
||||
print_red(err_msg)
|
||||
sys.exit(1)
|
||||
|
||||
print_green(_(u'This server uses most recent kernel'))
|
||||
|
||||
download_iso(args)
|
||||
|
||||
if args.download:
|
||||
end_msg = _(u"Download only detected, stop")
|
||||
print_green(end_msg)
|
||||
zephir("FIN", end_msg, z_proc)
|
||||
sys.exit(0)
|
||||
|
||||
print_title(_("Copying upgrade scripts"))
|
||||
if isdir(tmp_dir):
|
||||
err_msg = _(u"Directory {0} already exists").format(tmp_dir)
|
||||
zephir("ERR", err_msg, z_proc)
|
||||
print_red(err_msg)
|
||||
sys.exit(1)
|
||||
|
||||
copytree(UPGRADE_DIR, tmp_dir)
|
||||
pre_download = join(tmp_dir, PRE_DOWNLOAD)
|
||||
|
||||
print_title(_("Configuring upgrade"))
|
||||
engine = CreoleTemplateEngine()
|
||||
rootctx = {u'name': u'root', u'path': u''}
|
||||
|
||||
file_info = {'name': '/etc/update-manager/release-upgrades.d/eole.cfg',
|
||||
'source': join(templatedir, 'eole.cfg'),
|
||||
'full_name': '/etc/update-manager/release-upgrades.d/eole.cfg',
|
||||
'activate' : True,
|
||||
'del_comment': u'',
|
||||
'mkdir' : False,
|
||||
'rm' : False}
|
||||
engine.prepare_template(file_info)
|
||||
engine.process(file_info, rootctx)
|
||||
|
||||
_configure_sources_mirror(PKGMGR.pkgmgr, eole_release=args.release)
|
||||
|
||||
print_title(_("Module specific commands"))
|
||||
code = system(RUNPARTS_CMD.format(directory=pre_download))
|
||||
if code != 0:
|
||||
err_msg = _(u'Error {0}').format(pre_download)
|
||||
print_red(err_msg)
|
||||
zephir("ERR", err_msg, z_proc)
|
||||
sys.exit(1)
|
||||
|
||||
for container in (cont for cont in upgrades if cont != 'root'):
|
||||
upgrade_container_source(container)
|
||||
PKGMGR.dist_upgrade(container=container, silent=False)
|
||||
|
||||
m = MetaReleaseCore(useDevelopmentRelease=False,
|
||||
useProposed=False)
|
||||
# this will timeout eventually
|
||||
while m.downloading:
|
||||
time.sleep(0.5)
|
||||
progress = apt.progress.text.AcquireProgress()
|
||||
fetcher = EOLEDistUpgradeFetcherCore(new_dist=m.new_dist,
|
||||
progress=progress)
|
||||
fetcher.run_options += ["--mode=server",
|
||||
"--frontend=DistUpgradeViewEOLE",
|
||||
]
|
||||
print_title(_("Upgrading server"))
|
||||
fetcher.run()
|
||||
# all lines below will not be executed
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print_red(_("\nUpgrade aborted by user"))
|
||||
exit(0)
|
||||
|
9
upgrade/post_upgrade/00-common
Executable file
9
upgrade/post_upgrade/00-common
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
#suppression des fichiers du type : /usr/share/eole/mysql_pwd.pyc
|
||||
find /usr/share/eole -name "*.pyc" -delete
|
||||
|
||||
#suppression du lien symbolique ajouté pour Upgrade-Auto 2.4
|
||||
[ -L /usr/bin/Upgrade-Auto ] && rm -f /usr/bin/Upgrade-Auto
|
||||
|
||||
exit 0
|
29
upgrade/post_upgrade/01-amon
Executable file
29
upgrade/post_upgrade/01-amon
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
initfile="$(CreoleGet container_path_proxy '')/etc/init.d/winbind"
|
||||
# Utilisation du script d'init fourni par le paquet (#14608)
|
||||
if [ -f ${initfile}.dpkg-dist ];then
|
||||
mv -f ${initfile}.dpkg-dist ${initfile}
|
||||
fi
|
||||
|
||||
# Restauration des bases de filtres obligatoires (#8621)
|
||||
DB="$(CreoleGet container_path_proxy '')/var/lib/blacklists/db"
|
||||
if [ -d /tmp/db ];then
|
||||
for filter in 'adult' 'redirector';do
|
||||
mkdir -p $DB/$filter
|
||||
if [ -f /tmp/db/$filter/urls ];then
|
||||
cp -f /tmp/db/$filter/urls $DB/$filter/urls
|
||||
fi
|
||||
if [ -f /tmp/db/$filter/domains ];then
|
||||
cp -f /tmp/db/$filter/domains $DB/$filter/domains
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Suppression des restrictions pour squid (#15760)
|
||||
[ -f /etc/apparmor.d/usr.sbin.squid ] && ln -nsf /etc/apparmor.d/usr.sbin.squid /etc/apparmor.d/disable/
|
||||
|
||||
# Suppression des configurations fournies par le paquet freeradius (#16147)
|
||||
rm -f /etc/freeradius/modules/*.dpkg-dist
|
||||
|
||||
exit 0
|
6
upgrade/post_upgrade/01-bacula
Executable file
6
upgrade/post_upgrade/01-bacula
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Purge des paquets bacula (#14933)
|
||||
if [ -n "$(dpkg -l eole-bacula | grep ^rc)" ];then
|
||||
apt-get remove --purge -y --force-yes bacula-common bacula-common-sqlite3 bacula-console bacula-director-common bacula-director-sqlite3 bacula-fd bacula-sd eole-bacula
|
||||
fi
|
9
upgrade/post_upgrade/01-horus
Executable file
9
upgrade/post_upgrade/01-horus
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Restauration des fichiers Interbase (#11070)
|
||||
if [ -d /tmp/interbase ];then
|
||||
cp -f /tmp/interbase/isc4.gdb /opt/interbase/isc4.gdb
|
||||
cp -f /tmp/interbase/ib_license.dat /opt/interbase/ib_license.dat 2>/dev/null
|
||||
fi
|
||||
|
||||
exit 0
|
19
upgrade/post_upgrade/03-zephir-client
Executable file
19
upgrade/post_upgrade/03-zephir-client
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
BACKUP_DIR=/var/lib/zephir_backup
|
||||
OLD_DIR=/usr/lib/python2.6/dist-packages/zephir
|
||||
|
||||
if [ -f $BACKUP_DIR/zephir_conf.py ]
|
||||
then
|
||||
# mise en place de la configuration uucp
|
||||
cp -rpf $BACKUP_DIR/.ssh /var/spool/uucp/
|
||||
cp -pf $BACKUP_DIR/uucp/* /etc/uucp/
|
||||
# mise en place de la configuration d'enregistrement (python 2.7)
|
||||
mv -f $BACKUP_DIR/zephir_conf.py /usr/lib/python2.7/dist-packages/zephir/zephir_conf/
|
||||
rm -rf $BACKUP_DIR
|
||||
# suppression anciens fichier python2.6
|
||||
if [ -d $OLD_DIR ]
|
||||
then
|
||||
rm -rf $OLD_DIR
|
||||
fi
|
||||
fi
|
13
upgrade/post_upgrade/10-apache
Executable file
13
upgrade/post_upgrade/10-apache
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
PACKAGES="apache2-mpm-prefork apache2-utils apache2.2-bin"
|
||||
MODULES="alias auth_basic authn_file authz_host authz_user autoindex deflate dir env negotiation status"
|
||||
|
||||
if CreoleGet container_ip_reseau > /dev/null 2>&1
|
||||
then
|
||||
# Remove unwanted packages
|
||||
CreoleRun "apt-eole remove ${PACKAGES}" reseau
|
||||
|
||||
# Enable required modules
|
||||
CreoleRun "a2enmod ${MODULES}" reseau
|
||||
fi
|
4
upgrade/post_upgrade/90-delete-iso
Executable file
4
upgrade/post_upgrade/90-delete-iso
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Remove ISO directory /var/lib/eole/iso"
|
||||
rm -rf /var/lib/eole/iso
|
16
upgrade/post_upgrade/99-grub
Executable file
16
upgrade/post_upgrade/99-grub
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
bootdevice=$(mount | awk '/ \/boot / {gsub(/[0-9]/,"",$1);print $1}')
|
||||
rootdevice=$(mount | awk '/ \/ / {gsub(/[0-9]/,"",$1);print $1}')
|
||||
if [[ -n "${bootdevice}" ]]
|
||||
then
|
||||
grub-install ${bootdevice}
|
||||
exit $?
|
||||
elif [[ -n "${rootdevice}" ]]
|
||||
then
|
||||
grub-install ${rootdevice}
|
||||
exit $?
|
||||
else
|
||||
echo "Le disque d'installation de grub ne peut pas être déterminé."
|
||||
exit 127
|
||||
fi
|
8
upgrade/post_upgrade/99-unlock
Executable file
8
upgrade/post_upgrade/99-unlock
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
python -c 'from pyeole.lock import release; release("upgrade-auto", force=True, level="system")'
|
||||
|
||||
# Unlock instance
|
||||
echo '2.4.2' >| /etc/eole/.upgrade-auto
|
||||
|
||||
exit 0
|
5
upgrade/post_upgrade/99-upgrade_eole
Executable file
5
upgrade/post_upgrade/99-upgrade_eole
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
[[ -f /etc/apt/apt.conf.d/99upgradeEOLE ]] && rm -f /etc/apt/apt.conf.d/99upgradeEOLE
|
||||
|
||||
exit 0
|
28
upgrade/pre_download/00-common
Executable file
28
upgrade/pre_download/00-common
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
BACKUP_DIR="/var/backup/creolelocal"
|
||||
echo -e "\n# personnalisations locales (dictionnaires/patch/templates)"
|
||||
echo -e " Sauvegarde dans ${BACKUP_DIR}"
|
||||
mkdir -p ${BACKUP_DIR}/distrib
|
||||
mkdir -p ${BACKUP_DIR}/dicos
|
||||
mkdir -p ${BACKUP_DIR}/patch
|
||||
# dictionnaires locaux
|
||||
/bin/cp -rf /usr/share/eole/creole/dicos/local/*.xml ${BACKUP_DIR}/dicos/ >/dev/null 2>&1
|
||||
# si enregistré sur Zéphir : suppression des dictionnaires locaux/de variante
|
||||
# limite les problèmes avec creoled (cf https://dev-eole.ac-dijon.fr/issues/9787)
|
||||
/usr/bin/enregistrement_zephir --check >/dev/null
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
/bin/rm -f /usr/share/eole/creole/dicos/local/*.xml
|
||||
/bin/rm -f /usr/share/eole/creole/dicos/variante/*.xml
|
||||
fi
|
||||
# patchs
|
||||
/bin/cp -rf /usr/share/eole/creole/patch/*.patch ${BACKUP_DIR}/patch/ >/dev/null 2>&1
|
||||
# templates non installés par un paquet (variante et locaux)
|
||||
for TMPL in `ls /usr/share/eole/creole/distrib/*`
|
||||
do
|
||||
dpkg -S $TMPL >/dev/null 2>&1
|
||||
if [ $? -ne 0 ];then
|
||||
/bin/cp -rf $TMPL ${BACKUP_DIR}/distrib/
|
||||
fi
|
||||
done
|
3
upgrade/pre_download/00-dpkg_options
Executable file
3
upgrade/pre_download/00-dpkg_options
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo 'Dpkg::Options {"--force-confdef"; "--force-confmiss";};' > /etc/apt/apt.conf.d/99upgradeEOLE
|
10
upgrade/pre_download/01-amon
Executable file
10
upgrade/pre_download/01-amon
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
# Sauvegarde des bases de filtres obligatoires (#8621)
|
||||
DB="$(CreoleGet container_path_proxy '')/var/lib/blacklists/db"
|
||||
for filter in 'adult' 'redirector';do
|
||||
if [ -d $DB/$filter ];then
|
||||
mkdir -p /tmp/db/$filter
|
||||
cp -f $DB/$filter/urls /tmp/db/$filter/urls
|
||||
cp -f $DB/$filter/domains /tmp/db/$filter/domains
|
||||
fi
|
||||
done
|
6
upgrade/pre_download/01-bacula
Executable file
6
upgrade/pre_download/01-bacula
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Suppression des anciens fichiers bacula (#14933)
|
||||
if [ -d /etc/bacula/baculafichiers.d ];then
|
||||
rm -rf /etc/bacula/baculafichiers.d
|
||||
fi
|
27
upgrade/pre_download/01-horus
Executable file
27
upgrade/pre_download/01-horus
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
if dpkg-query -s eole-horus-backend > /dev/null 2>&1;then
|
||||
python -c """import sys
|
||||
from horus import backend
|
||||
from ldap import INVALID_CREDENTIALS
|
||||
try:
|
||||
for user in backend.ldapsearch('(&%s(sambaLogonScript=*))' % backend.user_filters):
|
||||
print 'correction du compte %s' % user[1]['uid'][0]
|
||||
backend.ldapmodify(user[0], 'sambaLogonScript', '')
|
||||
except INVALID_CREDENTIALS:
|
||||
print
|
||||
print 'Erreur le mot de passe ldap est désynchronisé'
|
||||
print 'Relancer un reconfigure pour corriger'
|
||||
print
|
||||
sys.exit(1)
|
||||
"""
|
||||
fi
|
||||
|
||||
# Sauvegarde des fichiers Interbase (#11070)
|
||||
if [ -f /opt/interbase/isc4.gdb ];then
|
||||
mkdir -p /tmp/interbase
|
||||
cp -f /opt/interbase/isc4.gdb /tmp/interbase
|
||||
cp -f /opt/interbase/ib_license.dat /tmp/interbase 2>/dev/null
|
||||
fi
|
||||
|
||||
exit 0
|
16
upgrade/pre_download/03-zephir-client
Executable file
16
upgrade/pre_download/03-zephir-client
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
/usr/bin/enregistrement_zephir --check >/dev/null 2>&1
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
BACKUP_DIR=/var/lib/zephir_backup/
|
||||
mkdir -p $BACKUP_DIR
|
||||
# copie temporaire de la configuration d'enregistrement
|
||||
cp -f /usr/lib/python2.7/dist-packages/zephir/zephir_conf/zephir_conf.py $BACKUP_DIR
|
||||
# configuration ssh de l'utilisateur uucp
|
||||
cp -rpf /var/spool/uucp/.ssh $BACKUP_DIR
|
||||
cp -rpf /etc/uucp $BACKUP_DIR
|
||||
fi
|
||||
|
||||
exit 0
|
18
upgrade/pre_download/10-rsyslog
Executable file
18
upgrade/pre_download/10-rsyslog
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Remove autogenerated configuration files
|
||||
DO_NOT_TOUCH_REGEXP='eole_templates\|default'
|
||||
|
||||
for conf in $(find /etc/rsyslog.d/ -type f -name '*.conf')
|
||||
do
|
||||
if echo "${conf}" | grep -qs "${DO_NOT_TOUCH_REGEXP}"
|
||||
then
|
||||
# Do nothing
|
||||
continue
|
||||
fi
|
||||
if ! dpkg -S "${conf}" > /dev/null 2>&1
|
||||
then
|
||||
echo "Remove generated rsyslog configuration file: “${conf}”"
|
||||
rm -f "${conf}"
|
||||
fi
|
||||
done
|
6
upgrade/pre_download/10-sympa
Executable file
6
upgrade/pre_download/10-sympa
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
if CreoleGet container_ip_reseau > /dev/null 2>&1
|
||||
then
|
||||
CreoleRun 'rm -f /etc/apache2/conf.d/sympa' reseau
|
||||
fi
|
107
upgrade/pre_download/90-fill-apt-cache
Executable file
107
upgrade/pre_download/90-fill-apt-cache
Executable file
@ -0,0 +1,107 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
ISO_DIR='/var/lib/eole/iso'
|
||||
|
||||
ISO_IMAGE=$(ls -1 ${ISO_DIR}/*.iso 2>/dev/null || true)
|
||||
|
||||
APT_CACHER_DIR='/var/cache/apt-cacher-ng'
|
||||
APT_DIR='/var/cache/apt/archives'
|
||||
|
||||
MOUNT_POINT=
|
||||
|
||||
## Called at the end of the file
|
||||
main() {
|
||||
if [ $(echo "${ISO_IMAGE}" | wc -l) -gt 1 ]
|
||||
then
|
||||
die "more than one ISO image detected: ${ISO_IMAGE}"
|
||||
fi
|
||||
|
||||
if [ -d "${APT_CACHER_DIR}" ]
|
||||
then
|
||||
populate_apt_cacher_cache
|
||||
else
|
||||
populate_apt_cache
|
||||
fi
|
||||
}
|
||||
|
||||
populate_apt_cache() {
|
||||
MOUNT_POINT='/media/cdrom'
|
||||
mount_iso "${ISO_IMAGE}" "${MOUNT_POINT}"
|
||||
|
||||
if find "${MOUNT_POINT}" -type f -name '*.deb' | xargs -I{} cp {} "${APT_DIR}"
|
||||
then
|
||||
echo "APT cache directory populated"
|
||||
else
|
||||
die "unablo to populate APT cache"
|
||||
fi
|
||||
}
|
||||
|
||||
populate_apt_cacher_cache() {
|
||||
|
||||
MOUNT_POINT="${APT_CACHER_DIR}/_import"
|
||||
mount_iso "${ISO_IMAGE}" "${MOUNT_POINT}"
|
||||
APT_CACHER_IMPORT_LOG=/tmp/apt-cacher-import.log
|
||||
APT_CACHER_PORT=$(CreoleGet apt_cacher_port)
|
||||
|
||||
CURRENT_DISTRIB=$(lsb_release --codename --short)
|
||||
NEXT_DISTRIB=$(awk '/^Suite:/ {print $2}' "${MOUNT_POINT}/dists/stable/Release")
|
||||
TMP_SL=/tmp/next-apt-sources.list
|
||||
|
||||
# Build a temporary sources.list
|
||||
# EOLE references are OK
|
||||
cp /etc/apt/sources.list ${TMP_SL}
|
||||
sed -i -e "s,${CURRENT_DISTRIB},${NEXT_DISTRIB}," ${TMP_SL}
|
||||
|
||||
# Clean apt cache
|
||||
rm -f /var/cache/apt/*cache.bin
|
||||
rm -f /var/lib/apt/lists/*Packages
|
||||
rm -f /var/lib/apt/lists/*Sources
|
||||
|
||||
apt-get -o Dir::Etc::SourceList=${TMP_SL} update
|
||||
|
||||
IMPORT_URL="http://localhost:${APT_CACHER_PORT}/acng-report.html?abortOnErrors=aOe&doImport=Start+Import&calcSize=cs&asNeeded=an"
|
||||
|
||||
ERROR_PATTERN='(No appropriate files found in the _import directory|color=red)'
|
||||
wget -O "${APT_CACHER_IMPORT_LOG}" -q "${IMPORT_URL}"
|
||||
ERRORS=$(sed -n -E "/${ERROR_PATTERN}/ s,<[^>]*>,,gp" "${APT_CACHER_IMPORT_LOG}")
|
||||
if [ -n "${ERRORS}" ]
|
||||
then
|
||||
die "import log contains errors: ${ERRORS}"
|
||||
else
|
||||
echo "APT-CACHER cache populated"
|
||||
fi
|
||||
}
|
||||
|
||||
mount_iso() {
|
||||
ISO="${1}"
|
||||
MOUNT_POINT="$2"
|
||||
|
||||
[ -d "${MOUNT_POINT}" ] || mkdir "${MOUNT_POINT}"
|
||||
|
||||
if ! mount -o loop,ro "${ISO}" "${MOUNT_POINT}"
|
||||
then
|
||||
die "unable to mount “${ISO}”"
|
||||
fi
|
||||
}
|
||||
|
||||
die(){ echo 'Error:' $@ >&2; exit 1; }
|
||||
|
||||
_clean() {
|
||||
EXIT_CODE=$?
|
||||
|
||||
# Do not abort on failure as we are in SIGHANDLER
|
||||
set +e
|
||||
|
||||
# Make script idempotent
|
||||
umount "${MOUNT_POINT}" 2> /dev/null
|
||||
rmdir "${MOUNT_POINT}" 2> /dev/null
|
||||
|
||||
# Use main script exit code
|
||||
return ${EXIT_CODE}
|
||||
}
|
||||
|
||||
trap _clean EXIT
|
||||
|
||||
main $@
|
Reference in New Issue
Block a user