Skip to content

Instantly share code, notes, and snippets.

@cthiel
Created June 30, 2011 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cthiel/1056056 to your computer and use it in GitHub Desktop.
Save cthiel/1056056 to your computer and use it in GitHub Desktop.
SUSE Studio: Run AutoYaST profile on appliance's first boot, example 2
<?xml version="1.0"?>
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<general>
<ask-list config:type="list">
<ask>
<dialog config:type="integer">20</dialog>
<element config:type="integer">20</element>
<help><![CDATA[
<p><b>Virtual IP address</b><br>Enter the IP address
matching the Virtual Hostname for your system.</p>
]]></help>
<file>/tmp/ay_q_virt_ip_addr</file>
<question>Enter (virt.) IP-Addr</question>
<stage>cont</stage>
<default>10.0.0.1</default>
<script>
<filename>chk_virt_ip.sh</filename>
<rerun_on_error config:type="boolean">true</rerun_on_error>
<environment config:type="boolean">true</environment>
<source><![CDATA[
function check_ip() {
local ip=$1 tmp phys_ip
[ -z "$ip" ] && echo "You must provide a valid IP address!" &&
return 1
[ "${#ip}" -lt 7 ] && echo "Is this a valid IP address? You
entered only '${#ip}' chars." && return 1
[ -n "${ip//[0-9.]/}" ] && echo "An IP address can only
contain digits and dots ('.'). Found this: '${ip//[0-9.]/}'." &&
return 1
tmp="${ip//[0-9]/}"
[ "${#tmp}" -ne 3 ] && echo "An IP address can only contain 3
dots." && return 1
[ "${phys_ip}" = "${ip}" ] && echo "The virt. IP address has
to differ from the phys. IP address ($ip)." && return 1
return 0
}
check_ip "$VAL"
]]></source>
<debug config:type="boolean">false</debug>
<feedback config:type="boolean">true</feedback>
</script>
</ask>
</ask-list>
</general>
</profile>
@jleon71
Copy link

jleon71 commented Sep 29, 2014

Good morning,

I would like to ask you for help, I am not to experienced on using linux automation xml files.
I was asked to create a xml file that prompts for server name, IP, default gateway, and other options, will sufring the internet I found your autoyast.xml example. I tried to mimic the same format with in my xml file. When I test the xml I get prompted to enter the server name, however the script is not executed, the script work is to validate the input entered to be less than 13 characters, only alfanumeric and not null input. The validation part is not working, can you help me with this question.

My OS is SLE SE 11 SP2, below is the part in my xml that I am prompting for the server name.

Thank you

Juan

606   <general>
607     <ask-list config:type="list">
608       <ask>
609         <question>Please enter the Hostname:</question>
610         <title>Server Configuration</title>
611         <type>string</type>
612         <stage>initial</stage>
613         <script>
614           <feedback config:type="boolean">true</feedback>
615           <rerun_on_error config:type="boolean">true</rerun_on_error>
616           <environment config:type="boolean">true</environment>
617           <debug config:type="boolean">false</debug>
618           <filename>configure-server.sh</filename>
619           <source>
620             <![CDATA[
621               #!/bin/bash
622               VAL=$1
623               function check_hostname()
624                        {
625                         local host=$1
626                         LC_ALL=POSIX
627                         [ -z "$host" ] && echo "You need to provide a hostname."  && return 1
628                         [ "${#host}" -gt 13 ] && echo "The hostname cannot be longer than 13 chars. You entered '${#host}' chars." && return 1
629                         [ -n "${host//[0-9A-Za-z-]/}" ]  && echo "The hostname can only consist of an alphanumeric string and a hyphen ('-'). Found         this: '${host//[0-9A-Za-z-]/}'."  && return 1
630                         return 0
631                        }
632                check_hostname "$VAL"
633
634
635             ]]>
636           </source>
637         </script>
638       </ask>
639     </ask-list>
640     <mode>
641       <confirm config:type="boolean">false</confirm>
642     </mode>
643   </general>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment