On Thu, Jun 11, 2009 at 01:59:56PM +0200, Dejan Muhamedagic wrote: > > so, to summarize, I hacked up a compare_version. > > and I think I even avoided bashisms! that is once in a life time :) > > Exemplary ;-)
It may depend on some GNU stuff in sed and sort, though. > > comments? > > overkill? > > useful? > > Yes. Unfortunately, the thing got quite complicated. Some > comments: > > sort_keys=$(seq $l | sed -e 's/.*/ -k&,&/;2~2 s/$/n/') > > Won't even try to unravel this magic. l was set to the number or version parts (non-numeric, numeric). so I get $l "columns", need that many sort keys. and they need to do "ascii" and "numeric" sort. seq 3 1 2 3 seq 3 | sed -e 's/.*/ -k&,&/' -k1,1 -k2,2 -k3,3 ... | -e '2~2 s/$/n/' "every second of two lines, append an n" (for numeric sort). -k1,1 -k2,2n -k3,3 > eval $(cibadmin -Ql | > sed -n -e '1 s/^<cib > validate-with=\("[^"]*"\).*$/_CIB_VALIDATE_WITH=\1/p' \ > > Beware: Attributes may come in any order. AFAIK, no guarantee at > all about it. > > -e 's/^[[:space:]]*<nvpair id="cib.bootstrap.options.dc.version".* > > Also, the id may be just about anything, can't rely on that, > better use the name attribute. is it, really arbitrary for the cib bootstrap things? > value="\([0-9.:]*\).*$/_DC_VERSION=\1/p') > > Hmm, don't really like eval here. If you really can't do without > it, at least protect the value with quotes. The same above with > _CIB_VALIDATE_WITH. of course I can do without it. I want to avoid to have to do it in two passes. but no need. the _DC_VERSION value only contains [0-9.:], which does not need to be quoted. for the _CIB_VALIDATE_WITH, the \("[^"]*"\) intentionally captures the enclosing quotes. ok, it could theoretically at one point in the future contain a backslash. but would <cib validate-with="something\" ...> be valid xml? and yes, it could in theory contain "`rm -rf /`" ;) Ok. I'll add some comments, and rewrite that part to sed -ne '/^<cib/ { s/^.*\bvalidate-with="\([^"]*\)".*$/\1/;s/[^-%+.\/0-9:=...@a-z_a-z]/\\&/g;s/^/_CIB_VALIDATE_WITH=/;p;}' -e '1,/<cluster_property_set\b/d;/<\/cluster_property_set>/q;' -e '/^[[:space:]]*<nvpair .*\bname="dc-version"/ s/^.*\bvalue="\([0-9.:]*\).*$/_DC_VERSION=\1/p' hey, you asked for it ;) -- : Lars Ellenberg : LINBIT | Your Way to High Availability : DRBD/HA support and consulting http://www.linbit.com DRBD® and LINBIT® are registered trademarks of LINBIT, Austria. _______________________________________________ Pacemaker mailing list Pacemaker@oss.clusterlabs.org http://oss.clusterlabs.org/mailman/listinfo/pacemaker