source: trunk/scripts/makeself/makeself.sh@ 462

Last change on this file since 462 was 1, checked in by katerina, 19 years ago

Initial import

File size: 9.9 KB
Line 
1#!/bin/sh
2#
3# Makeself version 2.1.x
4# by Stephane Peter <megastep@megastep.org>
5#
6# $Id: makeself.sh,v 1.44 2004/04/23 18:28:48 megastep Exp $
7#
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.
12#
13# Makeself home page: http://www.megastep.org/makeself/
14#
15# Version 2.0 is a rewrite of version 1.0 to make the code easier to read and maintain.
16#
17# Version history :
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#
55# (C) 1998-2004 by Stéphane Peter <megastep@megastep.org>
56#
57# This software is released under the terms of the GNU GPL
58# Please read the license at http://www.gnu.org/copyleft/gpl.html
59#
60
61MS_VERSION=2.1.3
62
63# Procedures
64
65MS_Usage()
66{
67 echo "Usage: $0 [params] archive_dir file_name label [startup_script] [args]"
68 echo "params can be one or more of the following :"
69 echo " --version | -v : Print out Makeself version number and exit"
70 echo " --help | -h : Print out this help message"
71 echo " --gzip : Compress using gzip (default if detected)"
72 echo " --bzip2 : Compress using bzip2 instead of gzip"
73 echo " --compress : Compress using the UNIX 'compress' command"
74 echo " --nocomp : Do not compress the data"
75 echo " --notemp : The archive will create archive_dir in the"
76 echo " current directory and uncompress in ./archive_dir"
77 echo " --copy : Upon extraction, the archive will first copy itself to"
78 echo " a temporary directory"
79 echo " --append : Append more files to an existing Makeself archive"
80 echo " The label and startup scripts will then be ignored"
81 echo " --current : Files will be extracted to the current directory."
82 echo " Implies --notemp."
83 echo " --nomd5 : Don't calculate an MD5 for archive"
84 echo " --nocrc : Don't calculate a CRC for archive"
85 echo " --header file : Specify location of the header script"
86 echo " --follow : Follow the symlinks in the archive"
87 echo " --nox11 : Disable automatic spawn of a xterm"
88 echo " --nowait : Do not wait for user input after executing embedded"
89 echo " program from an xterm"
90 echo " --lsm file : LSM file describing the package"
91 echo
92 echo "Do not forget to give a fully qualified startup script name"
93 echo "(i.e. with a ./ prefix if inside the archive)."
94 exit 1
95}
96
97# Default settings
98if type gzip 2>&1 > /dev/null; then
99 COMPRESS=gzip
100else
101 COMPRESS=Unix
102fi
103KEEP=n
104CURRENT=n
105NOX11=n
106APPEND=n
107COPY=none
108TAR_ARGS=cvf
109HEADER=`dirname $0`/makeself-header.sh
110
111# LSM file stuff
112LSM_CMD="echo No LSM. >> \"\$archname\""
113
114while true
115do
116 case "$1" in
117 --version | -v)
118 echo Makeself version $MS_VERSION
119 exit 0
120 ;;
121 --bzip2)
122 COMPRESS=bzip2
123 shift
124 ;;
125 --gzip)
126 COMPRESS=gzip
127 shift
128 ;;
129 --compress)
130 COMPRESS=Unix
131 shift
132 ;;
133 --nocomp)
134 COMPRESS=none
135 shift
136 ;;
137 --notemp)
138 KEEP=y
139 shift
140 ;;
141 --copy)
142 COPY=copy
143 shift
144 ;;
145 --current)
146 CURRENT=y
147 KEEP=y
148 shift
149 ;;
150 --header)
151 HEADER="$2"
152 shift 2
153 ;;
154 --follow)
155 TAR_ARGS=cvfh
156 shift
157 ;;
158 --nox11)
159 NOX11=y
160 shift
161 ;;
162 --nowait)
163 shift
164 ;;
165 --nomd5)
166 NOMD5=y
167 shift
168 ;;
169 --nocrc)
170 NOCRC=y
171 shift
172 ;;
173 --append)
174 APPEND=y
175 shift
176 ;;
177 --lsm)
178 LSM_CMD="cat \"$2\" >> \"\$archname\""
179 shift 2
180 ;;
181 -h | --help)
182 MS_Usage
183 ;;
184 -*)
185 echo Unrecognized flag : "$1"
186 MS_Usage
187 ;;
188 *)
189 break
190 ;;
191 esac
192done
193
194archdir="$1"
195archname="$2"
196MS_COMMAND="$0 $*"
197
198if test "$APPEND" = y; then
199 if test $# -lt 2; then
200 MS_Usage
201 fi
202
203 # Gather the info from the original archive
204 OLDENV=`sh "$archname" --dumpconf`
205 if test $? -ne 0; then
206 echo "Unable to update archive: $archname" >&2
207 exit 1
208 else
209 eval "$OLDENV"
210 fi
211else
212 if test "$KEEP" = n -a $# = 3; then
213 echo "ERROR: Making a temporary archive with no embedded command does not make sense!" >&2
214 echo
215 MS_Usage
216 fi
217 # We don't really want to create an absolute directory...
218 if test "$CURRENT" = y; then
219 archdirname="."
220 else
221 archdirname=`basename "$1"`
222 fi
223
224 if test $# -lt 3; then
225 MS_Usage
226 fi
227
228 LABEL="$3"
229 SCRIPT="$4"
230 test x$SCRIPT = x || shift 1
231 shift 3
232 SCRIPTARGS="$*"
233fi
234
235if test "$KEEP" = n -a "$CURRENT" = y; then
236 echo "ERROR: It is A VERY DANGEROUS IDEA to try to combine --notemp and --current." >&2
237 exit 1
238fi
239
240case $COMPRESS in
241gzip)
242 GZIP_CMD="gzip -c9"
243 GUNZIP_CMD="gzip -cd"
244 ;;
245bzip2)
246 GZIP_CMD="bzip2 -9"
247 GUNZIP_CMD="bzip2 -d"
248 ;;
249Unix)
250 GZIP_CMD="compress -cf"
251 GUNZIP_CMD="exec 2>&-; uncompress -c || test \\\$? -eq 2 || gzip -cd"
252 ;;
253none)
254 GZIP_CMD="cat"
255 GUNZIP_CMD="cat"
256 ;;
257esac
258
259tmpfile="${TMPDIR:=/tmp}/mkself$$"
260
261if test -f $HEADER; then
262 oldarchname="$archname"
263 archname="$tmpfile"
264 # Generate a fake header to count its lines
265 SKIP=0
266 . $HEADER
267 SKIP=`cat "$tmpfile" |wc -l`
268 # Get rid of any spaces
269 SKIP=`expr $SKIP`
270 rm -f "$tmpfile"
271 echo Header is $SKIP lines long >&2
272
273 archname="$oldarchname"
274else
275 echo "Unable to open header file: $HEADER" >&2
276 exit 1
277fi
278
279echo
280
281if test "$APPEND" = n; then
282 if test -f "$archname"; then
283 echo "WARNING: Overwriting existing file: $archname" >&2
284 fi
285fi
286
287test -d "$archdir" || { echo "Error: $archdir does not exist."; rm -f "$tmpfile"; exit 1; }
288
289USIZE=`du -ks $archdir | cut -f1`
290DATE=`LC_ALL=C date`
291
292echo About to compress $USIZE KB of data...
293echo Adding files to archive named \"$archname\"...
294(cd "$archdir"; tar $TAR_ARGS - * | eval "$GZIP_CMD" ) >> "$tmpfile" || { echo Aborting; rm -f "$tmpfile"; exit 1; }
295echo >> "$tmpfile" >&- # try to close the archive
296
297fsize=`cat "$tmpfile" | wc -c | tr -d " "`
298
299# Compute the checksums
300
301md5sum=00000000000000000000000000000000
302crcsum=0000000000
303
304if test "$NOCRC" = y; then
305 echo "skipping crc at user request"
306else
307 crcsum=`cat "$tmpfile" | cksum | sed -e 's/ /Z/' -e 's/ /Z/' | cut -dZ -f1`
308 echo "CRC: $crcsum"
309fi
310
311# Try to locate a MD5 binary
312OLD_PATH=$PATH
313PATH=${GUESS_MD5_PATH:-"$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"}
314MD5_PATH=`type -p md5sum`
315MD5_PATH=${MD5_PATH:-`type -p md5`}
316PATH=$OLD_PATH
317
318if test "$NOMD5" = y; then
319 echo "skipping md5sum at user request"
320else
321 if test -x "$MD5_PATH"; then
322 md5sum=`cat "$tmpfile" | "$MD5_PATH" | cut -b-32`;
323 echo "MD5: $md5sum"
324 else
325 echo "MD5: none, md5sum binary not found"
326 fi
327fi
328
329if test "$APPEND" = y; then
330 mv "$archname" "$archname".bak || exit
331
332 # Prepare entry for new archive
333 filesizes="$filesizes $fsize"
334 CRCsum="$CRCsum $crcsum"
335 MD5sum="$MD5sum $md5sum"
336 USIZE=`expr $USIZE + $OLDUSIZE`
337 # Generate the header
338 . $HEADER
339 # Append the original data
340 tail -n +$OLDSKIP "$archname".bak >> "$archname"
341 # Append the new data
342 cat "$tmpfile" >> "$archname"
343
344 chmod +x "$archname"
345 rm -f "$archname".bak
346 echo Self-extractible archive \"$archname\" successfully updated.
347else
348 filesizes="$fsize"
349 CRCsum="$crcsum"
350 MD5sum="$md5sum"
351
352 # Generate the header
353 . $HEADER
354
355 # Append the compressed tar data after the stub
356 echo
357 cat "$tmpfile" >> "$archname"
358 chmod +x "$archname"
359 echo Self-extractible archive \"$archname\" successfully created.
360fi
361rm -f "$tmpfile"
Note: See TracBrowser for help on using the repository browser.