4.12. Custom user scripts

By adding scripts to the auto-installation process you can customize the installation for your needs and take control in different stages of the installation.

In the auto-installation process, four types of scripts can be executed and they will be described here in order of "appearance" during the installation.

4.12.1. Pre-Install Scripts

Executed before YaST2 does any real change to the system (Before partitioning and package installation but after the hardware detection)

You can use the pre-script to modify your profile and let autoyast read it again. If you want to do that, you can find your profile in "/tmp/profile/autoinst.xml". Do what you want to do with that file and store the modified version in "/tmp/profile/modified.xml". Autoyast will read that modified script then again after the pre-script is done.

With SUSE Linux 10.0 and all following versions it's possible to change the partitioning with fdisk in your pre-script. With pre 10.0 versions of SUSE Linux (like SLES9), that was not possible.

[Note]Pre-Install Scripts with confirmation

Pre-scripts are executed at an early stage of the installation. This means if you have requested to confirm the installation, the pre-scripts will be executed before the confirmation screen shows up. (profile/install/general/mode/confirm)

The following elements must be between the <pre-scripts config:type="list"><script> ... </script></pre-scripts> tags

Table 4.6. pre script XML representation

ElementDescriptionComment
locationyou can define a location from where the script gets fetched. Locations can be the same like for the profile (http,ftp,nfs,...).
<location>http://10.10.0.1/myPreScript.sh</location>
either <location> or <source> must be defined
sourcethe script itself. The source code of the script if you want so. Encapsulated in a CDATA tag. If you don't want to put the whole shell script into the XML profile, look at the location parameter.
<source>
<![CDATA[ 
echo "Testing the pre script" > /tmp/pre-script_out.txt 
]]>
</source>
Either <location> or <source> must be defined
interpreterthe interpreter that must be used for the script. Supported options are shell and perl.
<interpreter>perl</interpreter>
optional (default is shell)
filenamethe filename of the script. It will be stored in a temporary directory under /tmp/...
<filename>myPreScript5.sh</filename>
optional. The default is the type of the script (pre-scripts) in this case
feedbackif this boolean is true, stdout and stderr of the script will be shown in a popup that the user has to confirm via ok-button. If stdout and stderr are empty, no popup is shown and so no confirmation is needed.
<feedback config:type="boolean">true</feedback>
optional. The default is false. This option was invented with SL 10.1 / SLES10
debugif this is true, every single line of a shell script is logged. Perl scripts are run with warnings turned on.
<debug config:type="boolean">true</debug>
optional. The default is true. This option was invented with SL 10.1 / SLES10


4.12.2. Chroot environment scripts

Chroot scripts are executed before the machine reboots for the first time. Actually chroot scripts are two differnt kind of script with one name. You can execute chroot script before the installation chroots into the installed system and configures the boot loader and you can execute a script after the chroot into the installed system has happend (look at the "chrooted" parameter for that). Both types of scripts are executed before yast2 boots for the first time.

The following elements must be between the <chroot-scripts config:type="list"><script> ... </script></chroot-scripts> tags

Table 4.7. chroot script XML representation

ElementDescriptionComment
locationyou can define a location from where the script gets fetched. Locations can be the same like for the profile (http,ftp,nfs,...).

<location>http://10.10.0.1/myChrootScript.sh</location>

either <location> or <source> must be defined
sourcethe script itself. The source code of the script if you want so. Encapsulated in a CDATA tag. If you don't want to put the whole shell script into the XML profile, look at the location parameter.
<source>
<![CDATA[ 
echo "Testing the chroot script" > /tmp/chroot_out.txt 
]]>
</source>
either <location> or <source> must be defined
chrootedthis value can be true or false. "False" means that the installed system is still mounted at "/mnt" and no chrooting has happened till now. The bootloader is not installed too at that stage. "True" means, we did a chroot into /mnt, so we are now in the installed system. The bootloader is installed and if you want to change anything in the installed system, you don't have to use the "/mnt/" prefix anymore.
<chrooted config:type="boolean">true</chrooted>
optional (the default is false)
interpreterthe interpreter that must be used for the script. Supported options are shell and perl.and if you are in a chrooted=true condition, you can use python too if it's installed.
<interpreter>perl</interpreter>
optional (default is shell)
filenamethe filename of the script. It will be stored in a temporary directory under /tmp/...
<filename>myPreScript5.sh</filename>
optional. The default is the type of the script (pre-scripts) in this case
feedbackif this boolean is true, stdout and stderr of the script will be shown in a popup that the user has to confirm via ok-button. If stdout and stderr are empty, no popup is shown and so no confirmation is needed.
<feedback config:type="boolean">true</feedback>
optional. The default is false. This option was invented with SL 10.1 / SLES10
debugif this is true, every single line of a shell script is logged. Perl scripts are run with warnings turned on.
<debug config:type="boolean">true</debug>
optional. The default is true. This option was invented with SL 10.1 / SLES10


4.12.3. Post-Install Scripts

These scripts are executed after AutoYaST has completed the system configuration and after it has booted the system for the first time.

Starting from SLES9, network is not available during post-installation script execution. To access the network, network device has to be configured in the script.

It is possible to execute the post scripts in an earlier phase while the installation network is still up and before AutoYaST configures the system. To run network enabled post scripts, the boolean property network_needed has to be set to true.

The following elements must be between the <post-scripts config:type="list"><script> ... </script></post-scripts> tags

Table 4.8. post script XML representation

ElementDescriptionComment
locationyou can define a location from where the script gets fetched. Locations can be the same like for the profile (http,ftp,nfs,...) but then you need a running network interface of course

<location>http://10.10.0.1/myPostScript.sh</location>

either <location> or <source> must be defined
sourcethe script itself. The source code of the script if you want so. Encapsulated in a CDATA tag. If you don't want to put the whole shell script into the XML profile, look at the location parameter.
<source>
<![CDATA[ 
echo "Testing the chroot script" > /tmp/chroot_out.txt 
]]>
</source>
either <location> or <source> must be defined
network_neededthis value can be true or false. On "false" the script will run after the yast modules like the user configuration and everything else are done. The network is configured but still not up and running. With this value on "true", the script runs before(!) all yast modules are configured. So there is no local user and no network is configured but the installation network is still up and running (of course only if you did a network installation).
<network_needed config:type="boolean">true</network_needed>
optional (the default is false)
interpreterthe interpreter that must be used for the script. Supported options are shell, perl and python if it's installed.
<interpreter>perl</interpreter>
optional (default is shell)
filenamethe filename of the script. It will be stored in a temporary directory under /tmp/...
<filename>myPostScript5.sh</filename>
optional. The default is the type of the script (post-scripts) in this case
feedbackif this boolean is true, stdout and stderr of the script will be shown in a popup that the user has to confirm via ok-button. If stdout and stderr are empty, no popup is shown and so no confirmation is needed.
<feedback config:type="boolean">true</feedback>
optional. The default is false. This option was invented with SL 10.1 / SLES10
debugif this is true, every single line of a shell script is logged. Perl scripts are run with warnings turned on.
<debug config:type="boolean">true</debug>
optional. The default is true. This option was invented with SL 10.1 / SLES10


4.12.4. Init Scripts

[Note]Note

Available starting from SLES9 only.

These scripts are executed during the initial boot process and after YaST2 has finished. The final scripts are executed using a special init.d script which is executed only once. The final scripts are executed toward the end of the boot process and after network has been intialized.

Init scripts are configured using the tag init-scripts and are run using the special purpose init.d script /etc/init.d/autoyast.

The following elements must be between the <init-scripts config:type="list"><script> ... </script></init-scripts> tags

Table 4.9. init script XML representation

ElementDescriptionComment
locationyou can define a location from where the script gets fetched. Locations can be the same like for the profile (http,ftp,nfs,...) but then you need a running network interface of course

<location>http://10.10.0.1/myInitScript.sh</location>

either <location> or <source> must be defined
sourcethe script itself. The source code of the script if you want so. Encapsulated in a CDATA tag. If you don't want to put the whole shell script into the XML profile, look at the location parameter.
<source>
<![CDATA[ 
echo "Testing the init script" > /tmp/init_out.txt 
]]>
</source>
either <location> or <source> must be defined
filenamethe filename of the script. It will be stored in a temporary directory under /tmp/...
<filename>mynitScript5.sh</filename>
optional. The default is the type of the script (init-scripts) in this case


When added to the control file manually, the scripts have to be included in a CDATA element to avoid confusion with the file syntax and other tags defined in the control file.

4.12.5. Script example

Example 4.34. Post script configuration

    <?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">
        <scripts>
            <chroot-scripts config:type="list">
                <script>
                    <chrooted config:type="boolean">true</chrooted>
                    <filename>chroot.sh</filename>
                    <interpreter>shell</interpreter>
                    <source><![CDATA[
#!/bin/sh
echo "Testing chroot (chrooted) scripts"
ls
]]>                    
                    </source>
                </script>
                <script>
                    <filename>chroot.sh</filename>
                    <interpreter>shell</interpreter>
                    <source><![CDATA[
#!/bin/sh
echo "Testing chroot scripts"
df
cd /mnt
ls
]]>                    
                    </source>
                </script>
            </chroot-scripts>
            <post-scripts config:type="list">
                <script>
                    <filename>post.sh</filename>
                    <interpreter>shell</interpreter>
                    <source><![CDATA[
#!/bin/sh

echo "Running Post-install script"
/etc/init.d/portmap start
mount -a 192.168.1.1:/local /mnt
cp /mnt/test.sh /tmp
umount /mnt
]]>
                </source>
                </script>
                <script>
                    <filename>post.pl</filename>
                    <interpreter>perl</interpreter>
                    <source><![CDATA[
#!/usr/bin/perl
print "Running Post-install script";

]]>
                    </source>
                </script>
            </post-scripts>
            <pre-scripts config:type="list">
                <script>
                    <interpreter>shell</interpreter>
                    <location>http://192.168.1.1/profiles/scripts/prescripts.sh</location>
                </script>
                <script>
                    <filename>pre.sh</filename>
                    <interpreter>shell</interpreter>
                    <source><![CDATA[
#!/bin/sh
echo "Running pre-install script"
]]>
                    </source>
                </script>
            </pre-scripts>
        </scripts>
</profile>


	

After installation is finished, the scripts and the output logs can be found in the directory /var/adm/autoinstall. The scripts are located in scripts and the output logs of the scripts are located in the log directory.

The log is the output resulting when executing the shell scripts using the following command:

      
      /bin/sh -x <script_name> 2&> /var/adm/autoinstall/logs/<script_name>.log