[1] | 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 |
|
---|
| 61 | MS_VERSION=2.1.3
|
---|
| 62 |
|
---|
| 63 | # Procedures
|
---|
| 64 |
|
---|
| 65 | MS_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
|
---|
| 98 | if type gzip 2>&1 > /dev/null; then
|
---|
| 99 | COMPRESS=gzip
|
---|
| 100 | else
|
---|
| 101 | COMPRESS=Unix
|
---|
| 102 | fi
|
---|
| 103 | KEEP=n
|
---|
| 104 | CURRENT=n
|
---|
| 105 | NOX11=n
|
---|
| 106 | APPEND=n
|
---|
| 107 | COPY=none
|
---|
| 108 | TAR_ARGS=cvf
|
---|
| 109 | HEADER=`dirname $0`/makeself-header.sh
|
---|
| 110 |
|
---|
| 111 | # LSM file stuff
|
---|
| 112 | LSM_CMD="echo No LSM. >> \"\$archname\""
|
---|
| 113 |
|
---|
| 114 | while true
|
---|
| 115 | do
|
---|
| 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
|
---|
| 192 | done
|
---|
| 193 |
|
---|
| 194 | archdir="$1"
|
---|
| 195 | archname="$2"
|
---|
| 196 | MS_COMMAND="$0 $*"
|
---|
| 197 |
|
---|
| 198 | if 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
|
---|
| 211 | else
|
---|
| 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="$*"
|
---|
| 233 | fi
|
---|
| 234 |
|
---|
| 235 | if 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
|
---|
| 238 | fi
|
---|
| 239 |
|
---|
| 240 | case $COMPRESS in
|
---|
| 241 | gzip)
|
---|
| 242 | GZIP_CMD="gzip -c9"
|
---|
| 243 | GUNZIP_CMD="gzip -cd"
|
---|
| 244 | ;;
|
---|
| 245 | bzip2)
|
---|
| 246 | GZIP_CMD="bzip2 -9"
|
---|
| 247 | GUNZIP_CMD="bzip2 -d"
|
---|
| 248 | ;;
|
---|
| 249 | Unix)
|
---|
| 250 | GZIP_CMD="compress -cf"
|
---|
| 251 | GUNZIP_CMD="exec 2>&-; uncompress -c || test \\\$? -eq 2 || gzip -cd"
|
---|
| 252 | ;;
|
---|
| 253 | none)
|
---|
| 254 | GZIP_CMD="cat"
|
---|
| 255 | GUNZIP_CMD="cat"
|
---|
| 256 | ;;
|
---|
| 257 | esac
|
---|
| 258 |
|
---|
| 259 | tmpfile="${TMPDIR:=/tmp}/mkself$$"
|
---|
| 260 |
|
---|
| 261 | if 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"
|
---|
| 274 | else
|
---|
| 275 | echo "Unable to open header file: $HEADER" >&2
|
---|
| 276 | exit 1
|
---|
| 277 | fi
|
---|
| 278 |
|
---|
| 279 | echo
|
---|
| 280 |
|
---|
| 281 | if test "$APPEND" = n; then
|
---|
| 282 | if test -f "$archname"; then
|
---|
| 283 | echo "WARNING: Overwriting existing file: $archname" >&2
|
---|
| 284 | fi
|
---|
| 285 | fi
|
---|
| 286 |
|
---|
| 287 | test -d "$archdir" || { echo "Error: $archdir does not exist."; rm -f "$tmpfile"; exit 1; }
|
---|
| 288 |
|
---|
| 289 | USIZE=`du -ks $archdir | cut -f1`
|
---|
| 290 | DATE=`LC_ALL=C date`
|
---|
| 291 |
|
---|
| 292 | echo About to compress $USIZE KB of data...
|
---|
| 293 | echo Adding files to archive named \"$archname\"...
|
---|
| 294 | (cd "$archdir"; tar $TAR_ARGS - * | eval "$GZIP_CMD" ) >> "$tmpfile" || { echo Aborting; rm -f "$tmpfile"; exit 1; }
|
---|
[556] | 295 | # The following command seems both superfluous and causing an 'I/O error' message
|
---|
| 296 | # echo >> "$tmpfile" >&- # try to close the archive
|
---|
[1] | 297 |
|
---|
| 298 | fsize=`cat "$tmpfile" | wc -c | tr -d " "`
|
---|
| 299 |
|
---|
| 300 | # Compute the checksums
|
---|
| 301 |
|
---|
| 302 | md5sum=00000000000000000000000000000000
|
---|
| 303 | crcsum=0000000000
|
---|
| 304 |
|
---|
| 305 | if test "$NOCRC" = y; then
|
---|
| 306 | echo "skipping crc at user request"
|
---|
| 307 | else
|
---|
| 308 | crcsum=`cat "$tmpfile" | cksum | sed -e 's/ /Z/' -e 's/ /Z/' | cut -dZ -f1`
|
---|
| 309 | echo "CRC: $crcsum"
|
---|
| 310 | fi
|
---|
| 311 |
|
---|
| 312 | # Try to locate a MD5 binary
|
---|
| 313 | OLD_PATH=$PATH
|
---|
| 314 | PATH=${GUESS_MD5_PATH:-"$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"}
|
---|
| 315 | MD5_PATH=`type -p md5sum`
|
---|
| 316 | MD5_PATH=${MD5_PATH:-`type -p md5`}
|
---|
| 317 | PATH=$OLD_PATH
|
---|
| 318 |
|
---|
| 319 | if test "$NOMD5" = y; then
|
---|
| 320 | echo "skipping md5sum at user request"
|
---|
| 321 | else
|
---|
| 322 | if test -x "$MD5_PATH"; then
|
---|
| 323 | md5sum=`cat "$tmpfile" | "$MD5_PATH" | cut -b-32`;
|
---|
| 324 | echo "MD5: $md5sum"
|
---|
| 325 | else
|
---|
| 326 | echo "MD5: none, md5sum binary not found"
|
---|
| 327 | fi
|
---|
| 328 | fi
|
---|
| 329 |
|
---|
| 330 | if test "$APPEND" = y; then
|
---|
| 331 | mv "$archname" "$archname".bak || exit
|
---|
| 332 |
|
---|
| 333 | # Prepare entry for new archive
|
---|
| 334 | filesizes="$filesizes $fsize"
|
---|
| 335 | CRCsum="$CRCsum $crcsum"
|
---|
| 336 | MD5sum="$MD5sum $md5sum"
|
---|
| 337 | USIZE=`expr $USIZE + $OLDUSIZE`
|
---|
| 338 | # Generate the header
|
---|
| 339 | . $HEADER
|
---|
| 340 | # Append the original data
|
---|
| 341 | tail -n +$OLDSKIP "$archname".bak >> "$archname"
|
---|
| 342 | # Append the new data
|
---|
| 343 | cat "$tmpfile" >> "$archname"
|
---|
| 344 |
|
---|
| 345 | chmod +x "$archname"
|
---|
| 346 | rm -f "$archname".bak
|
---|
| 347 | echo Self-extractible archive \"$archname\" successfully updated.
|
---|
| 348 | else
|
---|
| 349 | filesizes="$fsize"
|
---|
| 350 | CRCsum="$crcsum"
|
---|
| 351 | MD5sum="$md5sum"
|
---|
| 352 |
|
---|
| 353 | # Generate the header
|
---|
| 354 | . $HEADER
|
---|
| 355 |
|
---|
| 356 | # Append the compressed tar data after the stub
|
---|
| 357 | echo
|
---|
| 358 | cat "$tmpfile" >> "$archname"
|
---|
| 359 | chmod +x "$archname"
|
---|
| 360 | echo Self-extractible archive \"$archname\" successfully created.
|
---|
| 361 | fi
|
---|
| 362 | rm -f "$tmpfile"
|
---|