3
# Makeself version 2.1.x
4
# by Stephane Peter <megastep@megastep.org>
6
# $Id: makeself.sh,v 1.55 2005/06/02 22:35:17 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.
50
# Added --noexec to prevent execution of embedded scripts.
51
# Added --nomd5 and --nocrc to avoid creating checksums in archives.
52
# Added command used to create the archive in --info output.
53
# Run the embedded script through eval.
54
# - 2.1.4 : Fixed --info output.
55
# Generate random directory name when extracting files to . to avoid problems. (Jason Trent)
56
# Better handling of errors with wrong permissions for the directory containing the files. (Jason Trent)
57
# Avoid some race conditions (Ludwig Nussel)
58
# Unset the $CDPATH variable to avoid problems if it is set. (Debian)
59
# Better handling of dot files in the archive directory.
61
# (C) 1998-2005 by St�phane Peter <megastep@megastep.org>
63
# This software is released under the terms of the GNU GPL version 2 and above
64
# Please read the license at http://www.gnu.org/copyleft/gpl.html
71
for f in "${1+"$@"}"; do
72
MS_COMMAND="$MS_COMMAND \\\\
80
echo "Usage: $0 [params] archive_dir file_name label [startup_script] [args]"
81
echo "params can be one or more of the following :"
82
echo " --version | -v : Print out Makeself version number and exit"
83
echo " --help | -h : Print out this help message"
84
echo " --gzip : Compress using gzip (default if detected)"
85
echo " --bzip2 : Compress using bzip2 instead of gzip"
86
echo " --compress : Compress using the UNIX 'compress' command"
87
echo " --nocomp : Do not compress the data"
88
echo " --notemp : The archive will create archive_dir in the"
89
echo " current directory and uncompress in ./archive_dir"
90
echo " --copy : Upon extraction, the archive will first copy itself to"
91
echo " a temporary directory"
92
echo " --append : Append more files to an existing Makeself archive"
93
echo " The label and startup scripts will then be ignored"
94
echo " --current : Files will be extracted to the current directory."
95
echo " Implies --notemp."
96
echo " --nomd5 : Don't calculate an MD5 for archive"
97
echo " --nocrc : Don't calculate a CRC for archive"
98
echo " --header file : Specify location of the header script"
99
echo " --follow : Follow the symlinks in the archive"
100
echo " --nox11 : Disable automatic spawn of a xterm"
101
echo " --nowait : Do not wait for user input after executing embedded"
102
echo " program from an xterm"
103
echo " --lsm file : LSM file describing the package"
105
echo "Do not forget to give a fully qualified startup script name"
106
echo "(i.e. with a ./ prefix if inside the archive)."
111
if type gzip 2>&1 > /dev/null; then
122
HEADER=`dirname $0`/makeself-header.sh
125
LSM_CMD="echo No LSM. >> \"\$archname\""
131
echo Makeself version $MS_VERSION
191
LSM_CMD="cat \"$2\" >> \"\$archname\""
198
echo Unrecognized flag : "$1"
210
if test "$APPEND" = y; then
211
if test $# -lt 2; then
215
# Gather the info from the original archive
216
OLDENV=`sh "$archname" --dumpconf`
217
if test $? -ne 0; then
218
echo "Unable to update archive: $archname" >&2
224
if test "$KEEP" = n -a $# = 3; then
225
echo "ERROR: Making a temporary archive with no embedded command does not make sense!" >&2
229
# We don't really want to create an absolute directory...
230
if test "$CURRENT" = y; then
233
archdirname=`basename "$1"`
236
if test $# -lt 3; then
242
test x$SCRIPT = x || shift 1
247
if test "$KEEP" = n -a "$CURRENT" = y; then
248
echo "ERROR: It is A VERY DANGEROUS IDEA to try to combine --notemp and --current." >&2
255
GUNZIP_CMD="gzip -cd"
259
GUNZIP_CMD="bzip2 -d"
262
GZIP_CMD="compress -cf"
263
GUNZIP_CMD="exec 2>&-; uncompress -c || test \\\$? -eq 2 || gzip -cd"
271
tmpfile="${TMPDIR:=/tmp}/mkself$$"
273
if test -f $HEADER; then
274
oldarchname="$archname"
276
# Generate a fake header to count its lines
279
SKIP=`cat "$tmpfile" |wc -l`
280
# Get rid of any spaces
283
echo Header is $SKIP lines long >&2
285
archname="$oldarchname"
287
echo "Unable to open header file: $HEADER" >&2
293
if test "$APPEND" = n; then
294
if test -f "$archname"; then
295
echo "WARNING: Overwriting existing file: $archname" >&2
299
USIZE=`du -ks $archdir | cut -f1`
302
if test "." = "$archdirname"; then
303
if test "$KEEP" = n; then
304
archdirname="makeself-$$-`date +%Y%m%d%H%M%S`"
308
test -d "$archdir" || { echo "Error: $archdir does not exist."; rm -f "$tmpfile"; exit 1; }
309
echo About to compress $USIZE KB of data...
310
echo Adding files to archive named \"$archname\"...
311
(cd "$archdir" && ( tar $TAR_ARGS - . | eval "$GZIP_CMD" ) >> "$tmpfile") || { echo Aborting: Archive directory not found or temporary file: "$tmpfile" could not be created.; rm -f "$tmpfile"; exit 1; }
312
echo >> "$tmpfile" >&- # try to close the archive
314
fsize=`cat "$tmpfile" | wc -c | tr -d " "`
316
# Compute the checksums
318
md5sum=00000000000000000000000000000000
321
if test "$NOCRC" = y; then
322
echo "skipping crc at user request"
324
crcsum=`cat "$tmpfile" | CMD_ENV=xpg4 cksum | sed -e 's/ /Z/' -e 's/ /Z/' | cut -dZ -f1`
328
# Try to locate a MD5 binary
330
PATH=${GUESS_MD5_PATH:-"$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"}
331
MD5_PATH=`type -p md5sum`
332
MD5_PATH=${MD5_PATH:-`type -p md5`}
335
if test "$NOMD5" = y; then
336
echo "skipping md5sum at user request"
338
if test -x "$MD5_PATH"; then
339
md5sum=`cat "$tmpfile" | "$MD5_PATH" | cut -b-32`;
342
echo "MD5: none, md5sum binary not found"
346
if test "$APPEND" = y; then
347
mv "$archname" "$archname".bak || exit
349
# Prepare entry for new archive
350
filesizes="$filesizes $fsize"
351
CRCsum="$CRCsum $crcsum"
352
MD5sum="$MD5sum $md5sum"
353
USIZE=`expr $USIZE + $OLDUSIZE`
354
# Generate the header
356
# Append the original data
357
tail -n +$OLDSKIP "$archname".bak >> "$archname"
358
# Append the new data
359
cat "$tmpfile" >> "$archname"
362
rm -f "$archname".bak
363
echo Self-extractible archive \"$archname\" successfully updated.
369
# Generate the header
372
# Append the compressed tar data after the stub
374
cat "$tmpfile" >> "$archname"
376
echo Self-extractible archive \"$archname\" successfully created.