meta données pour cette page
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| info:geonetwork:geonetwork-maj [2017/05/18 17:46:03] – [Le script] cmartin | info:geonetwork:geonetwork-maj [2017/05/27 09:11:40] (Version actuelle) – cmartin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Update de geonetwork ====== | ====== Update de geonetwork ====== | ||
| - | 2017/05/18 17:45:03. | + | samedi 27 mai 2017, 09:08:59 (UTC+0200) |
| cmartin | cmartin | ||
| Contient un script à lancer pour faire les mises à jour de geonetwork. | Contient un script à lancer pour faire les mises à jour de geonetwork. | ||
| - | Tout ce qu'il faut c' | + | Tout ce qu'il faut c' |
| - | de geonetwork et un nouveau | + | - connaître |
| + | - connaître | ||
| + | - avoir un nouveau | ||
| <note importante> | <note importante> | ||
| - | valable | + | Valable |
| en déployant un WAR, pas en utilisant le JAR d' | en déployant un WAR, pas en utilisant le JAR d' | ||
| + | |||
| + | \\ | ||
| + | Testé pour passage de geonetwork 3.0.4 à 3.2.1 | ||
| + | |||
| + | <wrap em>SANS GARANTIE</ | ||
| </ | </ | ||
| Ligne 19: | Ligne 26: | ||
| * avoir une copie du dossier de geonetwork (tar ou autre) | * avoir une copie du dossier de geonetwork (tar ou autre) | ||
| En cas d' | En cas d' | ||
| + | * S' | ||
| ===== Avant de lancer le script ===== | ===== Avant de lancer le script ===== | ||
| Ligne 41: | Ligne 49: | ||
| Redémarrage de tomcat à votre charge. | Redémarrage de tomcat à votre charge. | ||
| + | |||
| + | ===== Un mot sur le script ===== | ||
| + | |||
| + | C' | ||
| + | l' | ||
| + | Évidemment, | ||
| + | qu'à se casser la figure à la première occasion. Ce qui n'a | ||
| + | pas manqué de se produire, lorsque que la locale était | ||
| + | différente sur la machine de test par rapport à la machine | ||
| + | de prod... | ||
| + | |||
| + | Tout réécrit en python. Le script n'est pas plus clair, AMHA, | ||
| + | mais plus robuste certainement. Réécrit dans la nuit d'un | ||
| + | vendredi à un samedi, d'où le copyright à Schplurtz. | ||
| + | |||
| + | **NB** pour moi même :\\ | ||
| + | Le script à utiliser est '' | ||
| + | par le Makefile qui inclut le .mo en français. Le script | ||
| + | a éditer est '' | ||
| ===== Le script ===== | ===== Le script ===== | ||
| - | **note perso**:\\ Ce script est dans le git IUEM des sysadmins. | + | **note perso** :\\ |
| + | Ce script est dans le git IUEM des sysadmins. | ||
| + | |||
| + | Cliquez sur le titre pour télécharger. | ||
| - | Cliquer sur le titre pour télécharger. | + | < |
| - | < | + | #! /usr/bin/env python |
| - | #! /bin/bash | + | |
| # encoding: utf-8 | # encoding: utf-8 | ||
| + | # vim: se ts=2 sw=2 et ai: | ||
| + | license=''' | ||
| + | |||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | Veuillez prendre connaissance de la licence d' | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | |||
| + | Software author : Christophe Martin, Schplurtz@laposte•net | ||
| - | <<' | + | |
| - | Author : Christophe Martin, Christophe•Martin@univ-brest•fr | + | |
| - | + | ||
| - | | + | |
| | | ||
| Ligne 114: | Ligne 156: | ||
| les termes. | les termes. | ||
| - | 42 | + | ''' |
| - | set -e # stop on error | + | import glob |
| + | import zipfile | ||
| + | import filecmp | ||
| + | import tempfile | ||
| + | import atexit | ||
| + | import os | ||
| + | import sys | ||
| + | import subprocess | ||
| + | import shutil | ||
| + | import re | ||
| + | import gettext | ||
| + | import base64 | ||
| - | # setp variable-name1 variable-name2 | ||
| - | setp() { | ||
| - | eval " | ||
| - | } | ||
| - | # setv var-name value | ||
| - | setv() { | ||
| - | eval " | ||
| - | } | ||
| - | warn() { | ||
| - | echo " | ||
| - | } | ||
| - | fatal() { | ||
| - | warn " | ||
| - | exit | ||
| - | kill $$ | ||
| - | } | ||
| - | # ouinon [-default oui|non] question | + | def error( *txt ): |
| - | # return code : | + | |
| - | # 0 oui | + | |
| - | # 1 non | + | |
| - | #exemple | + | |
| - | # ouinon -default non 'aimez vous le saucisson ?' && 'echo vous êtes gourmand' | + | |
| - | ouinon() { | + | |
| - | | + | |
| - | local rep | + | |
| - | if test ' | + | |
| - | case " | + | |
| - | | + | |
| - | def=0 | + | |
| - | ;; | + | |
| - | ([nN]|non|Non|nOn|noN|NOn|NoN|nON|NON|no|No|nO|NO) | + | |
| - | def=1 | + | |
| - | ;; | + | |
| - | esac | + | |
| - | shift | + | |
| - | shift 2>/ | + | |
| - | fi | + | |
| - | + | ||
| - | while : ; do | + | |
| - | read -p "$1 (o/n) : " | + | |
| - | case " | + | |
| - | ([yYoO]|oui|Oui|oUi|ouI|OUi|OuI|oUI|OUI|yes|YES|Yes|YEs|YeS|yES|yEs|yeS) | + | |
| - | return 0 | + | |
| - | ;; | + | |
| - | ([nN]|non|Non|nOn|noN|NOn|NoN|nON|NON|no|No|nO|NO) | + | |
| - | return 1 | + | |
| - | ;; | + | |
| - | esac | + | |
| - | done | + | |
| - | } | + | |
| + | # thanks to stackoverflow | ||
| + | def which(program): | ||
| + | import os | ||
| + | def is_exe(fpath): | ||
| + | return os.path.isfile(fpath) and os.access(fpath, | ||
| + | |||
| + | fpath, fname = os.path.split(program) | ||
| + | if fpath: | ||
| + | if is_exe(program): | ||
| + | return program | ||
| + | else: | ||
| + | for path in os.environ[' | ||
| + | path = path.strip('"' | ||
| + | exe_file = os.path.join(path, | ||
| + | if is_exe(exe_file): | ||
| + | return exe_file | ||
| + | |||
| + | return None | ||
| + | |||
| + | def cleanup(): | ||
| + | os.chdir('/' | ||
| + | # rmr(tmpdir) # Surtout pas ! Il peut y rester des fichiers importants | ||
| + | rmr(os.path.join(tmpdir,' | ||
| + | |||
| + | def question( var, txt ): | ||
| + | rep=raw_input( '{0} ({1}) ' | ||
| + | if rep == ' | ||
| + | exit(0) | ||
| + | if rep == '': | ||
| + | return var | ||
| + | return rep | ||
| + | |||
| + | def yn(txt): | ||
| + | while True: | ||
| + | rep='' | ||
| + | rep=question( rep, txt ).strip().lower() | ||
| + | if re.match( ' | ||
| + | return True | ||
| + | if re.match( ' | ||
| + | return False | ||
| + | |||
| + | def iswar( fn ): | ||
| + | ''' | ||
| + | a good war file is an existing zip file that | ||
| + | contains at least META-INF/ | ||
| + | ''' | ||
| + | ret=True | ||
| + | try: | ||
| + | zip=zipfile.ZipFile( fn ) | ||
| + | zip.getinfo(' | ||
| + | except: | ||
| + | ret=False | ||
| + | return ret | ||
| + | |||
| + | def rmr( *fname ): | ||
| + | for filename in fname: | ||
| + | if os.path.islink(filename) or os.path.isfile(filename): | ||
| + | os.remove(filename) | ||
| + | # print ' | ||
| + | else: | ||
| + | for root, dirs, files in os.walk(filename, | ||
| + | for fn in files: | ||
| + | os.remove(os.path.join(root, | ||
| + | # print ' | ||
| + | for dn in dirs: | ||
| + | os.rmdir(os.path.join(root, | ||
| + | # print 'rmdir {0}' | ||
| + | os.rmdir(filename) | ||
| + | # print 'rmdir {0}' | ||
| + | |||
| + | def bindata(fn): | ||
| + | lines='' | ||
| + | with open(fn) as data: | ||
| + | ok=False | ||
| + | for line in data: | ||
| + | if not ok and line == '# __DATA__\n': | ||
| + | ok=True | ||
| + | continue | ||
| + | if ok: | ||
| + | lines += line[1:] | ||
| + | return base64.b64decode(lines) | ||
| - | # question varname " | ||
| - | question() { | ||
| - | local __vname=$1 __rep __value | ||
| - | setp __value " | ||
| - | shift | ||
| - | printf '%s ' " | ||
| - | printf "(%s) " " | ||
| - | read __rep | ||
| - | test " | ||
| - | setv " | ||
| - | } | ||
| # | # | ||
| - | # MAIN Main main | + | # Main main Main |
| # | # | ||
| + | |||
| + | me=os.path.abspath(__file__.rstrip(' | ||
| + | tmpdir=tempfile.mkdtemp() | ||
| + | os.makedirs(os.path.join(tmpdir,' | ||
| + | with open(os.path.join(tmpdir,' | ||
| + | cat.write(bindata(me)) | ||
| + | # | ||
| + | gettext.install(' | ||
| - | missing= | + | atexit.register( cleanup ) |
| - | for cmd in diff tar sed unzip less tee find split xargs sed; do | + | missing=False |
| - | | + | for cmd in ['less']: |
| - | done | + | |
| - | test "$missing" && | + | error( _('missing |
| - | fatal "Les commandes suivantes manquent : $missing" | + | missing=True |
| - | # approuver la licence | + | if( missing ): |
| - | { | + | |
| - | echo | + | _("There are missing commands"), |
| - | echo | + | _(" |
| - | echo " | + | ) |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo | + | |
| - | echo | + | |
| - | sed -ne '/ | + | |
| - | sed -e '/ | + | |
| - | } | less | + | |
| - | if ! ouinon -default non "Accepetez vous les risques et la licence ?" | + | |
| - | then | + | |
| - | | + | |
| - | fi | + | |
| + | # | ||
| + | # Accept the license. Or not... | ||
| + | # | ||
| + | fnlic=os.path.join(tmpdir,' | ||
| + | with open(fnlic,' | ||
| + | f.write(license) | ||
| + | subprocess.call([' | ||
| + | ' | ||
| + | | ||
| + | fnlic | ||
| + | ] | ||
| + | ) | ||
| + | os.remove(fnlic) | ||
| + | if not yn( _("Do you accept the risks and the license ?") ): | ||
| + | print _('Ok. exiting' | ||
| + | exit(0) | ||
| - | # | ||
| - | geodir=/ | ||
| - | while : ; do | ||
| - | question geodir "Quel est le dossier de geonetwork ? " | ||
| - | case " | + | |
| - | (/*) | + | # |
| - | | + | # Now the real job |
| - | test " | + | # |
| - | test -d " | + | geonetdir='/var/ |
| - | warn "Hum \" | + | while True: |
| - | | + | |
| - | } | + | _('Directory containing current geonetwork' |
| + | if os.path.isdir( geonetdir ): | ||
| + | webinf=os.path.join( geonetdir, ' | ||
| + | if os.path.isdir( webinf ): | ||
| break | break | ||
| - | | + | error( _('{0} not a dir or not a geonetwork dir...' |
| - | warn " | + | |
| - | continue | + | |
| - | ;; | + | |
| - | | + | |
| - | | + | |
| - | esac | + | |
| - | done | + | |
| - | newwar= | + | |
| - | while : ; do | + | oldwar=geonetdir + ' |
| - | question | + | while True: |
| - | case " | + | |
| - | (exit) exit 0 ;; | + | |
| - | (*) | + | |
| - | test exit = " | + | |
| - | echo "bye bye" | + | |
| - | exit | + | |
| - | } | + | |
| - | test -r " | + | |
| - | warn " | + | |
| - | continue | + | |
| - | } | + | |
| - | test " | + | |
| - | warn "Pas bon. $newwar devrait être le war actuel, pas le nouveau." | + | |
| - | continue | + | |
| - | } | + | |
| - | case " | + | |
| - | (/*) : ;; | + | |
| - | (*) newwar=$PWD/ | + | |
| - | esac | + | |
| - | cmp " | + | |
| - | warn " | + | |
| - | continue | + | |
| - | } | + | |
| break | break | ||
| - | | + | |
| - | esac | + | |
| - | done | + | |
| - | echo " | ||
| - | echo " | ||
| - | echo " | ||
| - | if ouinon | + | newwar=' |
| - | then | + | while 1: |
| - | | + | |
| - | else | + | _('New war file') |
| - | echo "Bye bye" | + | ) |
| - | | + | |
| - | fi | + | |
| + | error( '{0} Not a valid/ | ||
| - | cd /tmp | ||
| - | # Arreter tomcat | + | geonetdir=os.path.abspath(geonetdir) |
| - | warn Arret de tomcat8 | + | oldwar=os.path.abspath(oldwar) |
| - | systemctl stop tomcat8 | + | newwar=os.path.abspath(newwar) |
| - | warn " | + | print '' |
| - | rm -rf geonetwork-old ; mkdir geonetwork-old ; cd geonetwork-old | + | print _('geonetwork |
| - | unzip -q " | + | print _(' |
| - | + | print _('new war file : '), newwar | |
| - | warn recherche des fichiers modifies et des fichiers ajoutes. | + | |
| - | # faire et conserver un diff | + | |
| - | diff -Bbwur . " | + | |
| - | # Conserver les fichiers avec différence | + | oldcontent=os.path.join(tmpdir,'oldcontent') |
| - | tar cCf " | + | os.mkdir(oldcontent) |
| - | awk '/^diff/ { print $3 }' | + | os.chdir(oldcontent) |
| - | ) | + | |
| - | # extraire liste des fichiers présents dans le dossier, non présents dans le WAR et les conserver | + | print _('Extracting current war in temp dir') |
| - | tar cCf " | + | zipfile.ZipFile(oldwar, 'r').extractall() |
| - | sed -ne '/ | + | |
| - | sed -e " | + | |
| - | ) | + | |
| - | # Lister ces fichiers en plus (on liste le tar, il pourrait y avoir des dossiers...) | + | |
| - | tar tf / | + | |
| - | grep -v '/$' | + | |
| - | sort -o /tmp/liste.enplus-old | + | |
| - | warn installation du nouveau war dans " | + | # Can't easily get what I want with filecmp.dircmp. It does not have |
| - | # installer le nouveau war | + | # recursive capabilities. too bad. Let's do it the barbarian way : |
| - | rm " | + | # get 2 full lists and compare. |
| - | cp " | + | # diff_cur_old=filecmp.dircmp(geonetdir, |
| + | # diff_cur_old.report_full_closure() | ||
| + | #for file in diff_cur_old.diff_files: | ||
| + | # print file | ||
| - | # dézipper le nouveau war | + | #print ' |
| - | warn deploiement du nouveau | + | print _(' |
| - | cd " | + | os.chdir(oldcontent) |
| - | unzip -q -o " | + | oldtree=set() |
| + | for root, dirs, files in os.walk('.'): | ||
| + | for name in files: | ||
| + | oldtree.add(os.path.join(root, | ||
| + | #print ' | ||
| + | #for x in oldtree: | ||
| + | # print x | ||
| - | # lister la totalité des fichiers et dossiers présents | + | print _(' |
| - | find . -type f | sed -e ' | + | os.chdir(geonetdir) |
| + | currenttree=set() | ||
| + | for root, dirs, files in os.walk('.'): | ||
| + | for name in files: | ||
| + | currenttree.add(os.path.join(root, | ||
| + | #for name in dirs: | ||
| + | # currenttree.add(os.path.join(root, | ||
| + | #for x in currenttree: | ||
| + | # print x | ||
| - | warn inspection du nouveau | + | print _(' |
| - | # lister le contenu du nouveau war | + | currenttreeenplus=currenttree.copy() |
| - | unzip -qql " | + | currenttreeenplus |
| - | | + | print _('{0} more files installed than files in current war').format(len(currenttreeenplus)) |
| - | sed -e 's,^\./,,' | + | '' |
| - | | + | for x in currenttreeenplus: |
| + | | ||
| + | ''' | ||
| - | warn determination des fichiers obsoletes | + | communstree=currenttree.copy() |
| - | # Les fichiers à enlever sont donc : | + | communstree |
| - | # total - nouveau - enplus | + | print _('computed {0} files in common (should be {1})').format( len(communstree), |
| - | # Prepare pour soustraction | + | |
| - | sed -e 's/^/^/' | + | |
| - | sed -e ' | + | |
| - | # La liste des trucs qu'il faut enlever est donc : | + | print _('searching among {0} files, those that have been modified' |
| - | #grep -v -f /tmp/liste.enplus.regexp / | + | modifiedtree=set() |
| - | # grep -v -f / | + | for file in sorted(communstree): |
| - | # tee /tmp/liste.a-detruire >/ | + | |
| - | # | + | |
| - | # Mais on risque de faire peter la mémoire car il y a trop de regexp dans les | + | |
| - | # fichiers. On va les splitter et progresser par étapes. On peut pas non plus | + | |
| - | # fabriquer un pipe immense, pour la même raison, donc, fichiers intermédiaires... | + | |
| - | # Naz... | + | |
| - | split -l 100 -a 4 / | + | |
| - | split -l 100 -a 4 / | + | |
| - | cp / | + | print _(' |
| - | set -- / | + | rmr(oldcontent) |
| - | for i in / | + | |
| - | do | + | |
| - | echo " | + | |
| - | grep -v -f " | + | |
| - | set -- $2 $1 | + | |
| - | done | + | |
| - | : echo fichier reduit est $(</ | + | |
| - | cd " | + | |
| - | warn suppression des fichiers obsoletes | + | |
| - | xargs -d \\n rm <$(</ | + | |
| - | # Remettre les fichiers modifiés | + | print _(' |
| - | if ouinon -default oui " | + | modifiedfiles=os.path.join( tmpdir, |
| - | $( | + | os.mkdir(modifiedfiles) |
| - | tar tf / | + | for filename in modifiedtree: |
| - | sed -e 's/^/ /' | + | dir=os.path.join( modifiedfiles, |
| - | ) | + | if not os.path.exists( dir ): |
| - | Et peut-etre d' | + | |
| - | " | + | |
| - | then | + | |
| - | | + | |
| - | fi | + | |
| - | warn suppression du cache | + | print _(' |
| - | # Supprimer le cache | + | newzip=zipfile.ZipFile(newwar, |
| - | rm -rf \ | + | newwartree=set() |
| - | | + | for filename in newzip.namelist(): |
| - | WEB-INF/ | + | |
| - | WEB-INF/ | + | |
| - | | + | |
| - | warn don des fichiers a tomcat8: | + | print _(' |
| - | chown -hR tomcat8: / | + | obsoletetree=oldtree.copy() |
| + | obsoletetree | ||
| + | print _(' | ||
| + | if yn( _('all checks are done. Start modifying ?') ): | ||
| + | print _(" | ||
| + | else: | ||
| + | print _('Bye bye.') | ||
| + | exit(0) | ||
| + | print _(' | ||
| + | os.chdir(geonetdir) | ||
| + | newzip.extractall() | ||
| - | echo "Fini. a vous de redemarrer le serveur tomcat8" | + | print _(' |
| + | for filename in obsoletetree: | ||
| + | os.remove(filename) | ||
| - | </code> | + | print _(' |
| + | rmr(*glob.glob(' | ||
| + | rmr(*glob.glob(' | ||
| + | rmr(*glob.glob(' | ||
| + | rmr(*glob.glob(' | ||
| - | ===== Auteur ===== | + | rep=' |
| + | while True: | ||
| + | rep=question( rep, _(''' | ||
| + | There are {0} modified files, what do you want to do ? | ||
| + | |||
| + | 0 : restore all | ||
| + | 1 : stop now and examine yourself the diffs | ||
| + | 2 : ask for each file | ||
| + | ''' | ||
| + | ).strip().lower() | ||
| + | if re.match( ' | ||
| + | break | ||
| + | error( _('did not understand, sorry...' | ||
| + | |||
| + | os.chdir( modifiedfiles ) | ||
| + | if ' | ||
| + | print _("OK. You have to examine the situation.\nmodified files are in {0}" | ||
| + | elif ' | ||
| + | for filename in sorted(modifiedtree): | ||
| + | print filename | ||
| + | shutil.copyfile(filename, | ||
| + | else: | ||
| + | for filename in sorted(modifiedtree): | ||
| + | if yn( _(" | ||
| + | | ||
| + | shutil.copyfile(filename, | ||
| + | os.remove(filename) | ||
| + | for root, dirs, files in os.walk(modifiedfiles, | ||
| + | for dn in dirs: | ||
| + | try: | ||
| + | os.rmdir(os.path.join(root, | ||
| + | except: | ||
| + | pass | ||
| + | print _('you will find remaining files (if any) in {0}' | ||
| + | |||
| + | print 'don des fichiers à tomcat8.' | ||
| + | subprocess.call([' | ||
| + | |||
| + | # __DATA__ | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | </ | ||
| - | --- // | ||