SUSE Manager customers using autoyast are in the lucky position to set many variables and use them in autoyast xml file directly. e.g. hostip=192.168.1.200 can be referred in autoinst.xml as $hostip which is great. Admins could set the values in the autoinstallation profile in conjunction with the autoyast xml file referring to it.
But when it comes to be more flexible and say if filesystem type is xfs instead of brfs then the value should be replaced and the section of "<subvolumes config:type="list">" should be removed.
To accomplish a such "flexibility" there are several ways one can do. I tried the way with rules as stated in the official autoyast docu but ended up with prescript modifying /tmp/profile/autoinst.xml
But writing a prescript to modify the autoinst.xml into a modified.xml with lot of find, replace, insert lead me to use sed awk which can become quite complicate.
This code below is my learnings how to achieve some find, replace, remove, insert within the autoinst.xml.
Before continue reading below I assume that you are aware about what is autoinst.xml and modifying it during yast installation happens through pre-scripts which generate a new modified.xml which will be next re-read by the yast installer. pre-script-doc
<pre-scripts config:type="list">
<script>
<source>
<![CDATA[
#!/bin/sh
fst="$fs_type"
dskt="$desktop"
cp /tmp/profile/autoinst.xml /tmp/profile/temp.xml
if [ $fst == "xfs" ]
then
sed -i '/[[:space:]]<partitioning config:type="list">$/,/[[:space:]]<\/partitioning>$/ s/[[:space:]]<filesystem config:type="symbol">btrfs<\/filesystem>$/<filesystem config:type="symbol">xfs<\/filesystem>/g' /tmp/profile/temp.xml
sed -i '/[[:space:]]<subvolumes config:type="list">$/,/[[:space:]]<\/subvolumes>$/{//!d}' /tmp/profile/temp.xml
fi
if [ $dskt == "yes" ]
then
wget http://192.168.122.181/profile/rules/with-gnome.xml -O /tmp/profile/software.xml
if [ -f /tmp/profile/temp.xml ]
then
awk '/<\/patterns>/{while(getline line<"/tmp/profile/software.xml"){print line}} //' /tmp/profile/temp.xml>/tmp/profile/modified.xml
else
awk '/<\/patterns>/{while(getline line<"/tmp/profile/software.xml"){print line}} //' /tmp/profile/autoinst.xml>/tmp/profile/modified.xml
fi
cp /tmp/profile/modified.xml /mnt/tmp/
fi
]]>
</source>
</script>
</pre-scripts>
Now, piece by piece explain it: