SUSE Support

Here When You Need Us

Using a self extracting archive in AutoYaST

This document (3041207) is provided subject to the disclaimer at the end of this document.

Environment


SUSE Linux Enterprise Server 10 SP1

Situation

You need to copy many different files from the media where the autoinst.xml file is located to the installed system. But from the normal scipts it's very hard to find the right medium where the files are located that should be copied to the system.
 

Resolution

Create a self extracting archive and include it as a post-install script in AutoYaST.

As a first step create a directory and store all the files you need to copy or install to the system inside this directory

mkdir myarchiv
cp pure-ftp.conf myarchiv/
cp other.conf myarchiv/
cp different.conf myarchiv/


Now cd into this directory and create a script that handles the complete installation of the files. Make sure to name this script install.sh because later on we rely on this name.

cd myarchiv/
vi install.sh

#!/bin/bash
echo "Installing please wait ...."
cp pure-ftp.conf /etc/
cp other.conf /var/lib/somewhere/
cp different.conf /usr/share/doc/different/
echo "done"
exit 0


Make this script executable

chmod +x install.sh

Test your script and make sure it works before going further. Next step is to create a TAR archive from the complete directory. In this example bz2 compression is used for a smaller size.

tar cfvj /tmp/myarch.tar.bz2 *

Now comes a important step. You can't include the archive as it is into the XML, because any binary data in a XML file must be base64 encoded. To encode the archive to base64 use the following command

openssl enc -base64 -e -in myarch.tar.bz2 -out myb64arch.tar.bz2

To automatically extract the just created archive a little script is needed that does this job. Create a file called selfextract-header.sh with the following content.

#!/bin/sh
echo ""
echo "Autoyast postinstaller v0.1 - starting installation... please wait"
echo ""

# create a temp directory to extract to.
export WRKDIR=`mktemp -d /tmp/selfextract.XXXXXX`

SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`

# Take the TGZ portion of this file and pipe it to tar.
tail +$SKIP $0 | openssl enc -base64 -d | tar xj -C $WRKDIR

# execute the installation script

PREV=`pwd`
cd $WRKDIR
./install.sh


# delete the temp files
cd $PREV
rm -rf $WRKDIR

exit 0

__ARCHIVE_FOLLOWS__


Make sure that the line containing __ARCHIVE_FOLLOWS__ is the last line in the script, not even a empty newline should follow. Otherwise the self extract won't work.

Technical Information: The line

SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`

calculates how many lines are in this script until the __ARCHIVE_FOLLOWS__ line. With this information we know at which line number our archive will start.

The line

tail +$SKIP $0 | openssl enc -base64 -d | tar xj -C $WRKDIR

makes a tail on itself ($0) but skips all lines prior to __ARCHIVE_FOLLOWS__ . The openssl command does the decoding from base64 to binary and finally the tar will extract the archive

Finally bring this script header together with the archive

cat selfextract-header.sh myb64arch.tar.bz2>ready-script.sh

The just created script ready-script.sh can be included in AutoYaST as a chroot-post-install script.
 

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:3041207
  • Creation Date: 14-Sep-2007
  • Modified Date:22-Feb-2021
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

tick icon

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

tick icon

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.

tick icon

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.