Search code examples
bashanttarself-extracting

Creating a self extracting bash script for linux using Ant on Windows


I'm trying to generate a self extracting script using the method discussed here: http://www.linuxjournal.com/node/1005818

Using ANT (on windows) I create the payload archive using TAR task(gzip compression), and concat the script and the tar using the following CONCAT task.

<concat destfile="${output}/selfextract.bsx" 
            append="true"
            eol="lf">
    <fileset file="${installer}/decompress"/>
    <fileset file="${output}/payload.tar.gz"/>
</concat>

The file is being created, and appears to contain the archive data, but when run on our Red Hat machine gzip complains "invalid compressed data --format violated".

Has anyone succeeded in this before?


Solution

  • Unless you use the fixlastline argument (off by default) then eol isn't used.

    Likely guess: you have an extra line at the end of your "decompress" script after the __ARCHIVE_BELOW__ line. You can't have any extra (even empty) lines there or you'll pipe those bytes into the tar. This could be caused, as Dennis said, by eol problems, but you'd have to have an awk that isn't GNU to have this problem I think.

    Easy way to confirm is change your tail to redirect to a file instead of tar, then hexdump the first few bytes of the original tar and the output tar to see what extra (or missing) bytes are getting in there.

    A final thing to check is do you need to set the binary option in your concat.