3 # Makeself version 2.1.x
4 # by Stephane Peter <megastep@megastep.org>
6 # $Id: makeself.sh,v 1.40 2003/09/12 02:19:29 megastep Exp $
8 # Utility to create self-extracting tar.gz archives.
9 # The resulting archive is a file holding the tar.gz archive with
10 # a small Shell script stub that uncompresses the archive to a temporary
11 # directory and then executes a given script from withing that directory.
13 # Makeself home page: http://www.megastep.org/makeself/
15 # Version 2.0 is a rewrite of version 1.0 to make the code easier to read and maintain.
18 # - 1.0 : Initial public release
19 # - 1.1 : The archive can be passed parameters that will be passed on to
20 # the embedded script, thanks to John C. Quillan
21 # - 1.2 : Package distribution, bzip2 compression, more command line options,
22 # support for non-temporary archives. Ideas thanks to Francois Petitjean
23 # - 1.3 : More patches from Bjarni R. Einarsson and Francois Petitjean:
24 # Support for no compression (--nocomp), script is no longer mandatory,
25 # automatic launch in an xterm, optional verbose output, and -target
26 # archive option to indicate where to extract the files.
27 # - 1.4 : Improved UNIX compatibility (Francois Petitjean)
28 # Automatic integrity checking, support of LSM files (Francois Petitjean)
29 # - 1.5 : Many bugfixes. Optionally disable xterm spawning.
30 # - 1.5.1 : More bugfixes, added archive options -list and -check.
31 # - 1.5.2 : Cosmetic changes to inform the user of what's going on with big
32 # archives (Quake III demo)
33 # - 1.5.3 : Check for validity of the DISPLAY variable before launching an xterm.
34 # More verbosity in xterms and check for embedded command's return value.
35 # Bugfix for Debian 2.0 systems that have a different "print" command.
36 # - 1.5.4 : Many bugfixes. Print out a message if the extraction failed.
37 # - 1.5.5 : More bugfixes. Added support for SETUP_NOCHECK environment variable to
38 # bypass checksum verification of archives.
39 # - 1.6.0 : Compute MD5 checksums with the md5sum command (patch from Ryan Gordon)
40 # - 2.0 : Brand new rewrite, cleaner architecture, separated header and UNIX ports.
41 # - 2.0.1 : Added --copy
42 # - 2.1.0 : Allow multiple tarballs to be stored in one archive, and incremental updates.
43 # Added --nochown for archives
44 # Stopped doing redundant checksums when not necesary
45 # - 2.1.1 : Work around insane behavior from certain Linux distros with no 'uncompress' command
46 # Cleaned up the code to handle error codes from compress. Simplified the extraction code.
47 # - 2.1.2 : Some bug fixes. Use head -n to avoid problems.
48 # - 2.1.3 : Bug fixes with command line when spawning terminals.
49 # Added --tar for archives, allowing to give arbitrary arguments to tar on the contents of the archive.
51 # (C) 1998-2003 by Stéphane Peter <megastep@megastep.org>
53 # This software is released under the terms of the GNU GPL
54 # Please read the license at http://www.gnu.org/copyleft/gpl.html
63 echo "Usage: $0 [params] archive_dir file_name label [startup_script] [args]"
64 echo "params can be one or more of the following :"
65 echo " --version | -v : Print out Makeself version number and exit"
66 echo " --help | -h : Print out this help message"
67 echo " --gzip : Compress using gzip (default if detected)"
68 echo " --bzip2 : Compress using bzip2 instead of gzip"
69 echo " --compress : Compress using the UNIX 'compress' command"
70 echo " --nocomp : Do not compress the data"
71 echo " --notemp : The archive will create archive_dir in the"
72 echo " current directory and uncompress in ./archive_dir"
73 echo " --copy : Upon extraction, the archive will first copy itself to"
74 echo " a temporary directory"
75 echo " --append : Append more files to an existing Makeself archive"
76 echo " The label and startup scripts will then be ignored"
77 echo " --current : Files will be extracted to the current directory."
78 echo " Implies --notemp."
79 echo " --header file : Specify location of the header script"
80 echo " --follow : Follow the symlinks in the archive"
81 echo " --nox11 : Disable automatic spawn of a xterm"
82 echo " --nowait : Do not wait for user input after executing embedded"
83 echo " program from an xterm"
84 echo " --lsm file : LSM file describing the package"
86 echo "Do not forget to give a fully qualified startup script name"
87 echo "(i.e. with a ./ prefix if inside the archive)."
92 if type gzip 2>&1 > /dev/null; then
103 HEADER=`dirname $0`/makeself-header.sh
106 LSM_CMD="echo No LSM. >> \"\$archname\""
112 echo Makeself version $MS_VERSION
164 LSM_CMD="cat \"$2\" >> \"\$archname\""
171 echo Unrecognized flag : "$1"
183 if test "$APPEND" = y; then
184 if test $# -lt 2; then
188 # Gather the info from the original archive
189 OLDENV=`sh "$archname" --dumpconf`
190 if test $? -ne 0; then
191 echo "Unable to update archive: $archname" >&2
197 if test "$KEEP" = n -a $# = 3; then
198 echo "ERROR: Making a temporary archive with no embedded command does not make sense!" >&2
202 # We don't really want to create an absolute directory...
203 if test "$CURRENT" = y; then
206 archdirname=`basename "$1"`
209 if test $# -lt 3; then
215 test x$SCRIPT = x || shift 1
220 if test "$KEEP" = n -a "$CURRENT" = y; then
221 echo "ERROR: It is A VERY DANGEROUS IDEA to try to combine --notemp and --current." >&2
228 GUNZIP_CMD="gzip -cd"
232 GUNZIP_CMD="bzip2 -d"
235 GZIP_CMD="compress -cf"
236 GUNZIP_CMD="exec 2>&-; uncompress -c || test \\\$? -eq 2 || gzip -cd"
244 tmpfile="${TMPDIR:=/tmp}/mkself$$"
246 if test -f $HEADER; then
247 oldarchname="$archname"
249 # Generate a fake header to count its lines
252 SKIP=`cat "$tmpfile" |wc -l`
253 # Get rid of any spaces
256 echo Header is $SKIP lines long >&2
258 archname="$oldarchname"
260 echo "Unable to open header file: $HEADER" >&2
266 if test "$APPEND" = n; then
267 if test -f "$archname"; then
268 echo "WARNING: Overwriting existing file: $archname" >&2
272 USIZE=`du -ks $archdir | cut -f1`
275 echo About to compress $USIZE KB of data...
276 echo Adding files to archive named \"$archname\"...
277 (cd "$archdir"; tar $TAR_ARGS - * | eval "$GZIP_CMD" ) >> "$tmpfile" || { echo Aborting; rm -f "$tmpfile"; exit 1; }
278 echo >> "$tmpfile" >&- # try to close the archive
280 fsize=`cat "$tmpfile" | wc -c | tr -d " "`
282 # Compute the checksums
284 md5sum=00000000000000000000000000000000
285 crcsum=`cat "$tmpfile" | cksum | sed -e 's/ /Z/' -e 's/ /Z/' | cut -dZ -f1`
288 # Try to locate a MD5 binary
290 PATH=${GUESS_MD5_PATH:-"$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"}
291 MD5_PATH=`type -p md5sum`
292 MD5_PATH=${MD5_PATH:-`type -p md5`}
295 if test -x "$MD5_PATH"; then
296 md5sum=`cat "$tmpfile" | "$MD5_PATH" | cut -b-32`;
299 echo "MD5: none, md5sum binary not found"
302 if test "$APPEND" = y; then
303 mv "$archname" "$archname".bak || exit
305 # Prepare entry for new archive
306 filesizes="$filesizes $fsize"
307 CRCsum="$CRCsum $crcsum"
308 MD5sum="$MD5sum $md5sum"
309 USIZE=`expr $USIZE + $OLDUSIZE`
310 # Generate the header
312 # Append the original data
313 tail -n +$OLDSKIP "$archname".bak >> "$archname"
314 # Append the new data
315 cat "$tmpfile" >> "$archname"
318 rm -f "$archname".bak
319 echo Self-extractible archive \"$archname\" successfully updated.
325 # Generate the header
328 # Append the compressed tar data after the stub
330 cat "$tmpfile" >> "$archname"
332 echo Self-extractible archive \"$archname\" successfully created.