The wikis are now using the new authentication system.
If you did not migrate your account yet, visit https://idp-portal-info.suse.com/

AutoYaST

Jump to: navigation, search

Susemini.png 本文处于需要修订的文章的状态,欢迎您积极参与翻译与修订。 翻译人员:ichair,修订人员:无。

AutoYaST 主页

另见 YaST Autoinstallation

AutoYaST Script例子 AutoYaST Script examples

我见过一些关于autoyast脚本的好的应用,所以我感觉把这些应用放到一起是一个好注意,这里看起来是一个很好的地方。

I've seen some neat things done in autoyast scripts, so I thought it would be a good idea to capture them all in one place and this looks like a good place.

检查你的客户端是否是 vmware VM

这个脚本检查您的客户端是否是 VMware 虚拟机。 其最初的设计目的是作为自定义规则来运行,但是很容易改成作为预先写好的脚本运行。[最初由 qualcom.com 的Mike Marion 发布在opensuse-autoinstall@opensuse.org的邮件列表上

   <rule>
     <custom1>
       <script>
<![CDATA[
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
if [ -n "`ifconfig | awk '/HWaddr/{print $NF}' | egrep -i '^00:0C:29'`"
]
then
  echo vmware
else
  echo default
fi
]]>
       </script>
       <match>*</match>
       <match_type>exact</match_type>
     </custom1>
   </rule>

检查客户端的虚拟机是否为 xen 虚拟机非常简单: 只需用 "00:16:3E"替换上面的 "00:0C:29"。

Detect if your client is a vmware VM

This script detects if your autoyasting client is a VMware virtual machine. Originally designed to run as a custom rule, but easily changed to run as a pre-script. [Originally posted by Mike Marion of qualcom.com on the mailing list opensuse-autoinstall@opensuse.org

   <rule>
     <custom1>
       <script>
<![CDATA[
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
if [ -n "`ifconfig | awk '/HWaddr/{print $NF}' | egrep -i '^00:0C:29'`"
]
then
  echo vmware
else
  echo default
fi
]]>
       </script>
       <match>*</match>
       <match_type>exact</match_type>
     </custom1>
   </rule>

Detecting a xen VM is similar; replace "00:0C:29" above with "00:16:3E"

从ask脚本复制answear至新系统

ask官方指令 [1] 使系统在安装期间方便地读取用户的输入, but what if you don't need to do anything with that until post install ? Well, the following script will take the answers written by the ask directive to a permanent file in the installed system.

在我的ask脚本陈述中,我将所有的answear写入/tmp/answer_* 如:

<ask-list config:type="list">
 <ask>
	<question>Enter the user for this machine</question>
	<default></default>
	<help>填写您的novell 用户ID</help>
	<title>用户ID</title>
	<file>/tmp/answer_user</file>
	<stage>initial</stage>
	<path>general,ask-list,3,default</path>
 </ask>
</ask-list>

And the following script would then copy all of those answers and write them into the installed system. It runs as a "non-chrooted, chroot script" [2] The script also creates a single file containing all the answers in shell var=value format.

#!/bin/bash
mkdir /mnt/var/adm/autoinstall/answers
for FILE in /tmp/answer* 
do
  cp $FILE /mnt/var/adm/autoinstall/answers/.
  ANSWER=`cat $FILE`
  QUESTION=${FILE##*/}
  echo ${QUESTION##*_}=$ANSWER >> /mnt/var/adm/autoinstall/answers/all_answers
done

Copy answers from ask scripts to the newly installed system

The ask directive [3] is great for getting user input during the install, but what if you don't need to do anything with that until post install ? Well, the following script will take the answers written by the ask directive to a permanent file in the installed system.

In my ask statements I write all the answers to /tmp/answer_* as in this example

<ask-list config:type="list">
 <ask>
	<question>Enter the user for this machine</question>
	<default></default>
	<help>Enter your novell userID</help>
	<title>userID</title>
	<file>/tmp/answer_user</file>
	<stage>initial</stage>
	<path>general,ask-list,3,default</path>
 </ask>
</ask-list>

And the following script would then copy all of those answers and write them into the installed system. It runs as a "non-chrooted, chroot script" [4] The script also creates a single file containing all the answers in shell var=value format.

#!/bin/bash
mkdir /mnt/var/adm/autoinstall/answers
for FILE in /tmp/answer* 
do
  cp $FILE /mnt/var/adm/autoinstall/answers/.
  ANSWER=`cat $FILE`
  QUESTION=${FILE##*/}
  echo ${QUESTION##*_}=$ANSWER >> /mnt/var/adm/autoinstall/answers/all_answers
done

Using classes with opensuse 10.3

I had some trouble getting classes to work correctly in opensuse 10.3, due to differences in the XML document definitions between the profile itself and the included class file. In the end, I found that this worked.

In the profile, include the class by using

<?xml version="1.0"?>
<!DOCTYPE profile SYSTEM "/usr/share/autoinstall/dtd/profile.dtd">
<profile xmlns="http://www.suse.com/1.0/yast2ns"
xmlns:config="http://www.suse.com/1.0/configns">
  <classes config:type="list">
    <class>
      <class_name>10.3</class_name>
      <configuration>default.xml</configuration>
    </class>
  </classes>
  .
  .
  .
</profile>

This will cause autoyast to look for the class file at classes/10.3/default.xml of the directory where your profiles are stored. If you're pulling from an http source, for example, you might point to a profile at nfs://instserver.example.com/autoyast/sampleprofile.xml; the class file included within that profile would then be sought at nfs://instserver.example.com/autoyast/classes/10.3/default.xml

The file classes/10.3/default.xml has a slightly different XML definition at the top. This one works (others may as well, but this one is known to):

<?xml version="1.0"?>
<profile xmlns="http://www.suse.com/1.0/yast2ns"
xmlns:config="http://www.suse.com/1.0/configns">
  <section1>
  </section1>
  .
  .
  .
</profile>