第 4.31.1 节,“预安装脚本” 已经描述了如何使用预安装脚本来修改当前配置。 简而言之,如果脚本创建了一个 /tmp/profile/modified.xml 文件,AutoYaST 将导入该配置并忽略初始配置。
这是一种非常灵活的方法,唯一的限制是您需要依赖于安装介质中可用的语言和库。
与 规则 不同,可以将 ERB 模板与脚本结合使用。 AutoYaST 在运行脚本之前将评估您在脚本中包含的任何 ERB 标签。 此行为仅适用于配置文件中定义的脚本,而不适用于外部脚本。
下面的脚本示例下载一个基于 MAC 地址的配置。 将文件保存为 /tmp/profile/modified.xml 将导致 AutoYaST 加载并使用下载的配置。
<scripts>
<pre-scripts config:type="list">
<script>
<interpreter>shell</interpreter>
<filename>load_profile.sh</filename>
<% mac = network_cards.first >
<source><![CDATA[#!/bin/bash
wget -O /tmp/profile/modified.xml http://myserver/<%= network_cards.first[:mac] %>.xml
]]></source>
</script>
</pre-scripts>
</scripts>可以在 Ruby 脚本中使用 ERB 助手。 要使用这些助手,需要 require yast 和 autoinstall/y2erb 库,并使用 Y2Autoinstall::Y2ERB::TemplateEnvironment 类来访问它们。
<scripts>
<pre-scripts config:type="list">
<script>
<interpreter>/usr/bin/ruby</interpreter>
<filename>load_profile.rb</filename>
<source><![CDATA[#!/usr/bin/env ruby
require "yast"
require "autoinstall/y2erb"
helpers = Y2Autoinstallation::Y2ERB::TemplateEnvironment.new
# Now you can use the TemplateEnvironment instance to call the helpers
disk_devices = helpers.disks.map { |d| d[:device] }
File.write("/root/disks.txt", disk_devices.join("\n"))
]]></source>
</script>
</pre-scripts>
</scripts>