diff -Nur smeserver-yum-2.6.0.bz8705.old/root/usr/lib/yum-plugins/smeserver.py smeserver-yum-2.6.0.bz8705.new/root/usr/lib/yum-plugins/smeserver.py --- smeserver-yum-2.6.0.bz8705.old/root/usr/lib/yum-plugins/smeserver.py 2013-01-31 17:35:08.000000000 +0100 +++ smeserver-yum-2.6.0.bz8705.new/root/usr/lib/yum-plugins/smeserver.py 2017-02-19 22:03:21.922929438 +0100 @@ -14,72 +14,278 @@ signal_event = '/sbin/e-smith/signal-event' config_set = '/sbin/e-smith/config' status_file = '/var/run/yum.status' +expand_template = '/sbin/e-smith/expand-template' +service = '/sbin/e-smith/service' + +eventlist = dict() +actionlist = dict() +templateslist = dict() +serviceslist = dict() + + +# list of packages that need a reboot +# if a package name starts with one these names, a reboot is needed +rebootpkgs = ['kernel', 'glibc', 'linux-firmware', 'systemd', 'udev', 'openssl-libs', 'gnutls', 'dbus', 'daemontools', 'lvm2', 'mdadm'] + +# list of packages that need a service restart +# if a package name starts with one of these values, a service restart is needed +# since, for example, httpd means httpd-admin and httpd-e-smith, we won't use these names directly but via serviceslist (see below) +restartpkgs = ['httpd', 'openssh', 'openldap', 'squid', 'dovecot', 'nut', 'freeradius', 'iptables', 'mysql', 'php', 'pptpd', 'proftp', 'qmail', 'qpsmtpd', 'samba', 'spamassassin'] +servicenames = dict() +servicenames['httpd']='httpd-admin','httpd-e-smith' +servicenames['openssh']='sshd', +servicenames['openldap']='slapd', +servicenames['freeradius']='radiusd', +servicenames['iptables']='masq', +servicenames['mysql']='mysqld', +servicenames['php']='httpd-e-smith', +servicenames['proftp']='proftpd', +servicenames['samba']='smbd', +servicenames['spamassassin']='spamd', +servicenames['squid']='squid', +servicenames['dovecot']='dovecot','pop3','pop3s' + smechange = False ourfile = False +erasing = False def report_yum_status(status): - fileHandle = open(status_file, 'w') - fileHandle.write(status) - fileHandle.close() + fileHandle = open(status_file, 'w') + fileHandle.write(status) + fileHandle.close() def predownload_hook(conduit): - report_yum_status('predownload') + report_yum_status('predownload') def postdownload_hook(conduit): - report_yum_status('postdownload') + report_yum_status('postdownload') def prereposetup_hook(conduit): - global ourfile - ourfile = True - report_yum_status('prereposetup') + global ourfile + + ourfile = True + report_yum_status('prereposetup') def postreposetup_hook(conduit): - report_yum_status('postreposetup') + report_yum_status('postreposetup') def exclude_hook(conduit): - report_yum_status('exclude') + report_yum_status('exclude') def preresolve_hook(conduit): - report_yum_status('preresolve') + report_yum_status('preresolve') def postresolve_hook(conduit): - report_yum_status('postresolve') + report_yum_status('postresolve') def pretrans_hook(conduit): - report_yum_status('pretrans') - ts = conduit.getTsInfo() + report_yum_status('pretrans') + # Prefetch filelist for packages to be removed, + # otherwise for updated packages headers will not be available + ts = conduit.getTsInfo() + removes = ts.getMembersWithState(output_states=TS_REMOVE_STATES) + global smechange + global eventlist + global actionlist + global templateslist + global serviceslist + global erasing + + for tsmem in removes: + erasing = True + (n, a, e, v, r) = tsmem.po.pkgtup + #only for debug + #print 'Package: ' + tsmem.name + ' remove' + smeevent = tsmem.name + '-update' + #only for debug + #print smeevent + if os.path.isdir(events_path + os.sep + smeevent): + tmppath = events_path + os.sep + smeevent + os.sep + eventlist[tsmem.name] = smeevent + + if os.path.isdir(tmppath + "templates2expand" + os.sep): + tmppathtmpl = tmppath + "templates2expand" + os.sep + for subdir, dirs, files in os.walk(tmppathtmpl): + for file in files: + mytmptemplate = os.path.join(subdir, file).replace(tmppathtmpl,os.sep) + if not templateslist.has_key(mytmptemplate): + templateslist[mytmptemplate]=mytmptemplate + #tmptmplpath = subdir + os.sep + file + #print (file) + + if os.path.isdir(tmppath + "services2adjust" + os.sep): + tmppathsrv = tmppath + "services2adjust" + os.sep + files = [f for f in os.listdir(tmppathsrv)] + for f in files: + if os.path.islink(tmppathsrv + f): + #print "link " + f + ": " + (os.readlink(tmppathsrv + f)) + mytmpserv = os.readlink(tmppathsrv + f) + if not serviceslist.has_key(f): + serviceslist[f]=mytmpserv + else: + #only for debug + #print "old value: " + serviceslist[f] + #print "new value: " + mytmpserv + + if mytmpserv == "restart": + print "overriding all signals, forcing restart" + serviceslist[f]="restart" + + else: + if n.startswith('smeserver') or n.startswith('e-smith'): + smechange = True + + #only for debug + #print 'smechange: '+str(smechange) + #print 'eventlist: '+ str(eventlist) + #print 'templateslist: '+str(templateslist) + #print 'serviceslist: '+str(serviceslist) def posttrans_hook(conduit): - global smechange - report_yum_status('posttrans') - ts = conduit.getTsInfo() - for tsmem in ts.getMembers(): - smeevent = 'yum-reconfigure-' + tsmem.name - if os.path.isdir(events_path + '/' + smeevent): - print "smeservers signal-event: " + smeevent - os.spawnl(os.P_WAIT, - signal_event, signal_event, smeevent) - - (n, a, e, v, r) = tsmem.po.pkgtup - if n.startswith('sme') or n.startswith('e-smith') or n.startswith('kernel') or r.endswith('sme'): - smechange = True - - if smechange: - os.spawnl(os.P_WAIT, config_set, config_set, 'set', 'UnsavedChanges', 'yes') - os.spawnl(os.P_WAIT, initialize_database, initialize_database) - os.spawnl(os.P_WAIT, navigation_conf, navigation_conf) + report_yum_status('posttrans') + ts = conduit.getTsInfo() + + global smechange + global eventlist + global actionlist + global templateslist + global serviceslist + global erasing + + + for tsmem in ts.getMembers(): + (n, a, e, v, r) = tsmem.po.pkgtup + + #print 'smechange: '+str(smechange) + + # we're upgrading/installing/removing a rebootpkgs package.. a reboot is required + for pkg in rebootpkgs: + if n.startswith(pkg): + #print 'Package: ' + tsmem.name + ' triggers reboot' + smechange = True + + + # check if we're upgrading a restartpkgs rpm + for pkg in restartpkgs: + #print pkg + if n.startswith(pkg): + if servicenames[pkg]: + #print 'lista' + for name in servicenames[pkg]: + #print name + if not serviceslist.has_key(name): + serviceslist[name] = 'restart' + else: + #only for debug + #print pkg + if not serviceslist.has_key(pkg): + serviceslist[pkg] = 'restart' + + + #if smechange is true we can ignore the following part + if not smechange and not erasing: + + #smeevent = 'yum-reconfigure-' + tsmem.name + smeevent = tsmem.name + '-update' + if os.path.isdir(events_path + os.sep + smeevent): + tmppath = events_path + os.sep + smeevent + os.sep + eventlist[tsmem.name] = smeevent + + files = [f for f in os.listdir(tmppath)] + for f in files: + if os.path.islink(tmppath + f): + + mytmpaction = os.path.realpath(os.readlink(tmppath + f)).replace("/root/rpmbuild/RPMS",events_path) + #print "link " + f + ": " + mytmpaction + + if not actionlist.has_key(mytmpaction): + actionlist[mytmpaction] = mytmpaction + + if os.path.isdir(tmppath + "templates2expand" + os.sep): + tmppathtmpl = tmppath + "templates2expand" + os.sep + for subdir, dirs, files in os.walk(tmppathtmpl): + for file in files: + mytmptemplate = os.path.join(subdir, file).replace(tmppathtmpl,os.sep) + if not templateslist.has_key(mytmptemplate): + templateslist[mytmptemplate]=mytmptemplate + #tmptmplpath = subdir + os.sep + file + #print (file) + + if os.path.isdir(tmppath + "services2adjust" + os.sep): + tmppathsrv = tmppath + "services2adjust" + os.sep + files = [f for f in os.listdir(tmppathsrv)] + for f in files: + if os.path.islink(tmppathsrv + f): + #print "link " + f + ": " + (os.readlink(tmppathsrv + f)) + mytmpserv = os.readlink(tmppathsrv + f) + if not serviceslist.has_key(f): + serviceslist[f]=mytmpserv + else: + #only for debug + #print "old value: " + serviceslist[f] + #print "new value: " + mytmpserv + + if mytmpserv == "restart": + #only for debug + print "overriding all signals, forcing restart" + serviceslist[f]="restart" + + else: + if n.startswith('smeserver') or n.startswith('e-smith'): + smechange = True + + + #only for debug + #print 'smechange: '+str(smechange) + #print 'post-trans' + #print 'eventlist: '+ str(eventlist) + #print 'templateslist: '+str(templateslist) + #print 'serviceslist: '+str(serviceslist) + + # check if smechange is true or if eventlist has items.. in both cases we must initialize databases + if smechange == True or len(eventlist)>0: + print 'Initializing databases' + os.spawnl(os.P_WAIT, initialize_database, initialize_database) + + # now, if smechange is false (no reboot needed), we can execute actions, expan templates and adjust services + #if not smechange: + + if len(actionlist)>0: + print "Executing actions" + for kactions in actionlist: + #print kactions + if os.path.isfile(kactions): + os.spawnl(os.P_WAIT, kactions, kactions) + + if len(templateslist)>0: + print "Expanding templates" + for ktemplates in templateslist: + #print ktemplates + if os.path.isfile(ktemplates): + os.spawnl(os.P_WAIT, expand_template, expand_template, ktemplates) + + if len(serviceslist)>0: + print "Adjusting services" + for kservices in serviceslist: + print kservices + ": " + serviceslist[kservices] + os.spawnl(os.P_WAIT, service, service, kservices, serviceslist[kservices]) + + + if smechange: + os.spawnl(os.P_WAIT, config_set, config_set, 'set', 'UnsavedChanges', 'yes') + os.spawnl(os.P_WAIT, navigation_conf, navigation_conf) def close_hook(conduit): - if ourfile and os.path.isfile('/var/run/yum.status'): - os.unlink('/var/run/yum.status') + if ourfile and os.path.isfile('/var/run/yum.status'): + os.unlink('/var/run/yum.status') - if smechange: - print "\n==============================================================" - print "WARNING: You now need to run BOTH of the following commands" - print "to ensure consistent system state:\n" - print "signal-event post-upgrade; signal-event reboot\n" - print "You should run these commands unless you are certain that" - print "yum made no changes to your system." - print "==============================================================" + if smechange: + print "\n==============================================================" + print "WARNING: You now need to run BOTH of the following commands" + print "to ensure consistent system state:\n" + print "signal-event post-upgrade; signal-event reboot\n" + print "You should run these commands unless you are certain that" + print "yum made no changes to your system." + print "=============================================================="