~vcs-imports/unetbootin/trunk

« back to all changes in this revision

Viewing changes to makeself/makeself.sh

  • Committer: Geza Kovacs
  • Date: 2015-07-30 10:46:05 UTC
  • Revision ID: git-v1:60f5a6234f67bcddcdfccc5cef4b49b812775e3e
clean up old unused parts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# Makeself version 2.1.x
4
 
#  by Stephane Peter <megastep@megastep.org>
5
 
#
6
 
# $Id: makeself.sh,v 1.55 2005/06/02 22:35:17 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
 
# - 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.
60
 
#
61
 
# (C) 1998-2005 by St�phane Peter <megastep@megastep.org>
62
 
#
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
65
 
#
66
 
 
67
 
MS_VERSION=2.1.4
68
 
MS_COMMAND="$0"
69
 
unset CDPATH
70
 
 
71
 
for f in "${1+"$@"}"; do
72
 
    MS_COMMAND="$MS_COMMAND \\\\
73
 
    \\\"$f\\\""
74
 
done
75
 
 
76
 
# Procedures
77
 
 
78
 
MS_Usage()
79
 
{
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"
104
 
    echo
105
 
    echo "Do not forget to give a fully qualified startup script name"
106
 
    echo "(i.e. with a ./ prefix if inside the archive)."
107
 
    exit 1
108
 
}
109
 
 
110
 
# Default settings
111
 
if type gzip 2>&1 > /dev/null; then
112
 
    COMPRESS=gzip
113
 
else
114
 
    COMPRESS=Unix
115
 
fi
116
 
KEEP=n
117
 
CURRENT=n
118
 
NOX11=n
119
 
APPEND=n
120
 
COPY=none
121
 
TAR_ARGS=cvf
122
 
HEADER=`dirname $0`/makeself-header.sh
123
 
 
124
 
# LSM file stuff
125
 
LSM_CMD="echo No LSM. >> \"\$archname\""
126
 
 
127
 
while true
128
 
do
129
 
    case "$1" in
130
 
    --version | -v)
131
 
        echo Makeself version $MS_VERSION
132
 
        exit 0
133
 
        ;;
134
 
    --bzip2)
135
 
        COMPRESS=bzip2
136
 
        shift
137
 
        ;;
138
 
    --gzip)
139
 
        COMPRESS=gzip
140
 
        shift
141
 
        ;;
142
 
    --compress)
143
 
        COMPRESS=Unix
144
 
        shift
145
 
        ;;
146
 
    --nocomp)
147
 
        COMPRESS=none
148
 
        shift
149
 
        ;;
150
 
    --notemp)
151
 
        KEEP=y
152
 
        shift
153
 
        ;;
154
 
    --copy)
155
 
        COPY=copy
156
 
        shift
157
 
        ;;
158
 
    --current)
159
 
        CURRENT=y
160
 
        KEEP=y
161
 
        shift
162
 
        ;;
163
 
    --header)
164
 
        HEADER="$2"
165
 
        shift 2
166
 
        ;;
167
 
    --follow)
168
 
        TAR_ARGS=cvfh
169
 
        shift
170
 
        ;;
171
 
    --nox11)
172
 
        NOX11=y
173
 
        shift
174
 
        ;;
175
 
    --nowait)
176
 
        shift
177
 
        ;;
178
 
    --nomd5)
179
 
        NOMD5=y
180
 
        shift
181
 
        ;;
182
 
    --nocrc)
183
 
        NOCRC=y
184
 
        shift
185
 
        ;;
186
 
    --append)
187
 
        APPEND=y
188
 
        shift
189
 
        ;;
190
 
    --lsm)
191
 
        LSM_CMD="cat \"$2\" >> \"\$archname\""
192
 
        shift 2
193
 
        ;;
194
 
    -h | --help)
195
 
        MS_Usage
196
 
        ;;
197
 
    -*)
198
 
        echo Unrecognized flag : "$1"
199
 
        MS_Usage
200
 
        ;;
201
 
    *)
202
 
        break
203
 
        ;;
204
 
    esac
205
 
done
206
 
 
207
 
archdir="$1"
208
 
archname="$2"
209
 
 
210
 
if test "$APPEND" = y; then
211
 
    if test $# -lt 2; then
212
 
        MS_Usage
213
 
    fi
214
 
 
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
219
 
        exit 1
220
 
    else
221
 
        eval "$OLDENV"
222
 
    fi
223
 
else
224
 
    if test "$KEEP" = n -a $# = 3; then
225
 
        echo "ERROR: Making a temporary archive with no embedded command does not make sense!" >&2
226
 
        echo
227
 
        MS_Usage
228
 
    fi
229
 
    # We don't really want to create an absolute directory...
230
 
    if test "$CURRENT" = y; then
231
 
        archdirname="."
232
 
    else
233
 
        archdirname=`basename "$1"`
234
 
    fi
235
 
 
236
 
    if test $# -lt 3; then
237
 
        MS_Usage
238
 
    fi
239
 
 
240
 
    LABEL="$3"
241
 
    SCRIPT="$4"
242
 
    test x$SCRIPT = x || shift 1
243
 
    shift 3
244
 
    SCRIPTARGS="$*"
245
 
fi
246
 
 
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
249
 
    exit 1
250
 
fi
251
 
 
252
 
case $COMPRESS in
253
 
gzip)
254
 
    GZIP_CMD="gzip -c9"
255
 
    GUNZIP_CMD="gzip -cd"
256
 
    ;;
257
 
bzip2)
258
 
    GZIP_CMD="bzip2 -9"
259
 
    GUNZIP_CMD="bzip2 -d"
260
 
    ;;
261
 
Unix)
262
 
    GZIP_CMD="compress -cf"
263
 
    GUNZIP_CMD="exec 2>&-; uncompress -c || test \\\$? -eq 2 || gzip -cd"
264
 
    ;;
265
 
none)
266
 
    GZIP_CMD="cat"
267
 
    GUNZIP_CMD="cat"
268
 
    ;;
269
 
esac
270
 
 
271
 
tmpfile="${TMPDIR:=/tmp}/mkself$$"
272
 
 
273
 
if test -f $HEADER; then
274
 
        oldarchname="$archname"
275
 
        archname="$tmpfile"
276
 
        # Generate a fake header to count its lines
277
 
        SKIP=0
278
 
    . $HEADER
279
 
    SKIP=`cat "$tmpfile" |wc -l`
280
 
        # Get rid of any spaces
281
 
        SKIP=`expr $SKIP`
282
 
        rm -f "$tmpfile"
283
 
    echo Header is $SKIP lines long >&2
284
 
 
285
 
        archname="$oldarchname"
286
 
else
287
 
    echo "Unable to open header file: $HEADER" >&2
288
 
    exit 1
289
 
fi
290
 
 
291
 
echo
292
 
 
293
 
if test "$APPEND" = n; then
294
 
    if test -f "$archname"; then
295
 
                echo "WARNING: Overwriting existing file: $archname" >&2
296
 
    fi
297
 
fi
298
 
 
299
 
USIZE=`du -ks $archdir | cut -f1`
300
 
DATE=`LC_ALL=C date`
301
 
 
302
 
if test "." = "$archdirname"; then
303
 
        if test "$KEEP" = n; then
304
 
                archdirname="makeself-$$-`date +%Y%m%d%H%M%S`"
305
 
        fi
306
 
fi
307
 
 
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
313
 
 
314
 
fsize=`cat "$tmpfile" | wc -c | tr -d " "`
315
 
 
316
 
# Compute the checksums
317
 
 
318
 
md5sum=00000000000000000000000000000000
319
 
crcsum=0000000000
320
 
 
321
 
if test "$NOCRC" = y; then
322
 
        echo "skipping crc at user request"
323
 
else
324
 
        crcsum=`cat "$tmpfile" | CMD_ENV=xpg4 cksum | sed -e 's/ /Z/' -e 's/    /Z/' | cut -dZ -f1`
325
 
        echo "CRC: $crcsum"
326
 
fi
327
 
 
328
 
# Try to locate a MD5 binary
329
 
OLD_PATH=$PATH
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`}
333
 
PATH=$OLD_PATH
334
 
 
335
 
if test "$NOMD5" = y; then
336
 
        echo "skipping md5sum at user request"
337
 
else
338
 
        if test -x "$MD5_PATH"; then
339
 
                md5sum=`cat "$tmpfile" | "$MD5_PATH" | cut -b-32`;
340
 
                echo "MD5: $md5sum"
341
 
        else
342
 
                echo "MD5: none, md5sum binary not found"
343
 
        fi
344
 
fi
345
 
 
346
 
if test "$APPEND" = y; then
347
 
    mv "$archname" "$archname".bak || exit
348
 
 
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
355
 
    . $HEADER
356
 
    # Append the original data
357
 
    tail -n +$OLDSKIP "$archname".bak >> "$archname"
358
 
    # Append the new data
359
 
    cat "$tmpfile" >> "$archname"
360
 
 
361
 
    chmod +x "$archname"
362
 
    rm -f "$archname".bak
363
 
    echo Self-extractible archive \"$archname\" successfully updated.
364
 
else
365
 
    filesizes="$fsize"
366
 
    CRCsum="$crcsum"
367
 
    MD5sum="$md5sum"
368
 
 
369
 
    # Generate the header
370
 
    . $HEADER
371
 
 
372
 
    # Append the compressed tar data after the stub
373
 
    echo
374
 
    cat "$tmpfile" >> "$archname"
375
 
    chmod +x "$archname"
376
 
    echo Self-extractible archive \"$archname\" successfully created.
377
 
fi
378
 
rm -f "$tmpfile"