| 1 | #!/bin/sh |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | # |
| 5 | # shellcheck disable=SC2209,SC2006,SC2016,SC2034,SC2086,SC2003,SC2268,SC1090,SC2002,SC2046 |
| 6 | # |
| 7 | # Makeself version 2.5.x |
| 8 | # by Stephane Peter <megastep@megastep.org> |
| 9 | # |
| 10 | # Utility to create self-extracting tar.gz archives. |
| 11 | # The resulting archive is a file holding the tar.gz archive with |
| 12 | # a small Shell script stub that uncompresses the archive to a temporary |
| 13 | # directory and then executes a given script from withing that directory. |
| 14 | # |
| 15 | # Makeself home page: https://makeself.io/ - Version history available on GitHub |
| 16 | # |
| 17 | # (C) 1998-2023 by Stephane Peter <megastep@megastep.org> |
| 18 | # |
| 19 | # This software is released under the terms of the GNU GPL version 2 and above |
| 20 | # Please read the license at http://www.gnu.org/copyleft/gpl.html |
| 21 | # Self-extracting archives created with this script are explictly NOT released under the term of the GPL |
| 22 | # |
| 23 | |
| 24 | MS_VERSION=2.5.0 |
| 25 | MS_COMMAND="$0" |
| 26 | unset CDPATH |
| 27 | |
| 28 | for f in ${1+"$@"}; do |
| 29 | MS_COMMAND="$MS_COMMAND \\\\ |
| 30 | \\\"$f\\\"" |
| 31 | done |
| 32 | |
| 33 | # For Solaris systems |
| 34 | if test -d /usr/xpg4/bin; then |
| 35 | PATH=/usr/xpg4/bin:$PATH |
| 36 | export PATH |
| 37 | fi |
| 38 | |
| 39 | # Procedures |
| 40 | |
| 41 | MS_Usage() |
| 42 | { |
| 43 | echo "Usage: $0 [args] archive_dir file_name label startup_script [script_args]" |
| 44 | echo "args can be one or more of the following :" |
| 45 | echo " --version | -v : Print out Makeself version number and exit" |
| 46 | echo " --help | -h : Print out this help message" |
| 47 | echo " --tar-quietly : Suppress verbose output from the tar command" |
| 48 | echo " --quiet | -q : Do not print any messages other than errors." |
| 49 | echo " --gzip : Compress using gzip (default if detected)" |
| 50 | echo " --pigz : Compress with pigz" |
| 51 | echo " --zstd : Compress with zstd" |
| 52 | echo " --bzip2 : Compress using bzip2 instead of gzip" |
| 53 | echo " --pbzip2 : Compress using pbzip2 instead of gzip" |
| 54 | echo " --bzip3 : Compress using bzip3 instead of gzip" |
| 55 | echo " --xz : Compress using xz instead of gzip" |
| 56 | echo " --lzo : Compress using lzop instead of gzip" |
| 57 | echo " --lz4 : Compress using lz4 instead of gzip" |
| 58 | echo " --compress : Compress using the UNIX 'compress' command" |
| 59 | echo " --complevel lvl : Compression level for gzip pigz zstd xz lzo lz4 bzip2 pbzip2 and bzip3 (default 9)" |
| 60 | echo " --threads thds : Number of threads to be used by compressors that support parallelization." |
| 61 | echo " Omit to use compressor's default. Most useful (and required) for opting" |
| 62 | echo " into xz's threading, usually with '--threads=0' for all available cores." |
| 63 | echo " pbzip2 and pigz are parallel by default, and setting this value allows" |
| 64 | echo " limiting the number of threads they use." |
| 65 | echo " --base64 : Instead of compressing, encode the data using base64" |
| 66 | echo " --gpg-encrypt : Instead of compressing, encrypt the data using GPG" |
| 67 | echo " --gpg-asymmetric-encrypt-sign" |
| 68 | echo " : Instead of compressing, asymmetrically encrypt and sign the data using GPG" |
| 69 | echo " --gpg-extra opt : Append more options to the gpg command line" |
| 70 | echo " --ssl-encrypt : Instead of compressing, encrypt the data using OpenSSL" |
| 71 | echo " --ssl-passwd pass : Use the given password to encrypt the data using OpenSSL" |
| 72 | echo " --ssl-pass-src src : Use the given src as the source of password to encrypt the data" |
| 73 | echo " using OpenSSL. See \"PASS PHRASE ARGUMENTS\" in man openssl." |
| 74 | echo " If this option is not supplied, the user will be asked to enter" |
| 75 | echo " encryption password on the current terminal." |
| 76 | echo " --ssl-no-md : Do not use \"-md\" option not supported by older OpenSSL." |
| 77 | echo " --nochown : Do not give the target folder to the current user (default)" |
| 78 | echo " --chown : Give the target folder to the current user recursively" |
| 79 | echo " --nocomp : Do not compress the data" |
| 80 | echo " --notemp : The archive will create archive_dir in the current directory" |
| 81 | echo " and uncompress in ./archive_dir" |
| 82 | echo " Note: persistent archives do not strictly require a startup_script" |
| 83 | echo " --needroot : Check that the root user is extracting the archive before proceeding" |
| 84 | echo " --copy : Upon extraction, the archive will first copy itself to" |
| 85 | echo " a temporary directory" |
| 86 | echo " --append : Append more files to an existing Makeself archive" |
| 87 | echo " The label and startup scripts will then be ignored" |
| 88 | echo " --target dir : Extract directly to a target directory" |
| 89 | echo " directory path can be either absolute or relative" |
| 90 | echo " --current : Files will be extracted to the current directory" |
| 91 | echo " Both --current and --target imply --notemp, and do not require a startup_script" |
| 92 | echo " --nooverwrite : Do not extract the archive if the specified target directory exists" |
| 93 | echo " --tar-format opt : Specify a tar archive format (default is ustar)" |
| 94 | echo " --tar-extra opt : Append more options to the tar command line" |
| 95 | echo " --untar-extra opt : Append more options to the during the extraction of the tar archive" |
| 96 | echo " --nomd5 : Don't calculate an MD5 for archive" |
| 97 | echo " --nocrc : Don't calculate a CRC for archive" |
| 98 | echo " --sha256 : Compute a SHA256 checksum for the archive" |
| 99 | echo " --header file : Specify location of the header script" |
| 100 | echo " --cleanup file : Specify a cleanup script that executes on interrupt and when finished successfully." |
| 101 | echo " --follow : Follow the symlinks in the archive" |
| 102 | echo " --noprogress : Do not show the progress during the decompression" |
| 103 | echo " --nox11 : Disable automatic spawn of a xterm" |
| 104 | echo " --nowait : Do not wait for user input after executing embedded" |
| 105 | echo " program from an xterm" |
| 106 | echo " --sign passphrase : Signature private key to sign the package with" |
| 107 | echo " --lsm file : LSM file describing the package" |
| 108 | echo " --license file : Append a license file" |
| 109 | echo " --help-header file : Add a header to the archive's --help output" |
| 110 | echo " --packaging-date date" |
| 111 | echo " : Use provided string as the packaging date" |
| 112 | echo " instead of the current date." |
| 113 | echo |
| 114 | echo " --keep-umask : Keep the umask set to shell default, rather than overriding when executing self-extracting archive." |
| 115 | echo " --export-conf : Export configuration variables to startup_script" |
| 116 | echo |
| 117 | echo "Do not forget to give a fully qualified startup script name" |
| 118 | echo "(i.e. with a ./ prefix if inside the archive)." |
| 119 | exit 1 |
| 120 | } |
| 121 | |
| 122 | # Default settings |
| 123 | if type gzip >/dev/null 2>&1; then |
| 124 | COMPRESS=gzip |
| 125 | elif type compress >/dev/null 2>&1; then |
| 126 | COMPRESS=compress |
| 127 | else |
| 128 | echo "ERROR: missing commands: gzip, compress" >&2 |
| 129 | MS_Usage |
| 130 | fi |
| 131 | ENCRYPT=n |
| 132 | PASSWD="" |
| 133 | PASSWD_SRC="" |
| 134 | OPENSSL_NO_MD=n |
| 135 | COMPRESS_LEVEL=9 |
| 136 | DEFAULT_THREADS=123456 # Sentinel value |
| 137 | THREADS=$DEFAULT_THREADS |
| 138 | KEEP=n |
| 139 | CURRENT=n |
| 140 | NOX11=n |
| 141 | NOWAIT=n |
| 142 | APPEND=n |
| 143 | TAR_QUIETLY=n |
| 144 | KEEP_UMASK=n |
| 145 | QUIET=n |
| 146 | NOPROGRESS=n |
| 147 | COPY=none |
| 148 | NEED_ROOT=n |
| 149 | TAR_ARGS=rvf |
| 150 | TAR_FORMAT=ustar |
| 151 | TAR_EXTRA="" |
| 152 | GPG_EXTRA="" |
| 153 | DU_ARGS=-ks |
| 154 | HEADER=`dirname "$0"`/makeself-header.sh |
| 155 | SIGNATURE="" |
| 156 | TARGETDIR="" |
| 157 | NOOVERWRITE=n |
| 158 | DATE=`LC_ALL=C date` |
| 159 | EXPORT_CONF=n |
| 160 | SHA256=n |
| 161 | OWNERSHIP=n |
| 162 | SIGN=n |
| 163 | GPG_PASSPHRASE="" |
| 164 | |
| 165 | # LSM file stuff |
| 166 | LSM_CMD="echo No LSM. >> \"\$archname\"" |
| 167 | |
| 168 | while true |
| 169 | do |
| 170 | case "$1" in |
| 171 | --version | -v) |
| 172 | echo Makeself version $MS_VERSION |
| 173 | exit 0 |
| 174 | ;; |
| 175 | --pbzip2) |
| 176 | COMPRESS=pbzip2 |
| 177 | shift |
| 178 | ;; |
| 179 | --bzip3) |
| 180 | COMPRESS=bzip3 |
| 181 | shift |
| 182 | ;; |
| 183 | --bzip2) |
| 184 | COMPRESS=bzip2 |
| 185 | shift |
| 186 | ;; |
| 187 | --gzip) |
| 188 | COMPRESS=gzip |
| 189 | shift |
| 190 | ;; |
| 191 | --pigz) |
| 192 | COMPRESS=pigz |
| 193 | shift |
| 194 | ;; |
| 195 | --zstd) |
| 196 | COMPRESS=zstd |
| 197 | shift |
| 198 | ;; |
| 199 | --xz) |
| 200 | COMPRESS=xz |
| 201 | shift |
| 202 | ;; |
| 203 | --lzo) |
| 204 | COMPRESS=lzo |
| 205 | shift |
| 206 | ;; |
| 207 | --lz4) |
| 208 | COMPRESS=lz4 |
| 209 | shift |
| 210 | ;; |
| 211 | --compress) |
| 212 | COMPRESS=compress |
| 213 | shift |
| 214 | ;; |
| 215 | --base64) |
| 216 | COMPRESS=base64 |
| 217 | shift |
| 218 | ;; |
| 219 | --gpg-encrypt) |
| 220 | COMPRESS=gpg |
| 221 | shift |
| 222 | ;; |
| 223 | --gpg-asymmetric-encrypt-sign) |
| 224 | COMPRESS=gpg-asymmetric |
| 225 | shift |
| 226 | ;; |
| 227 | --gpg-extra) |
| 228 | GPG_EXTRA="$2" |
| 229 | shift 2 || { MS_Usage; exit 1; } |
| 230 | ;; |
| 231 | --ssl-encrypt) |
| 232 | ENCRYPT=openssl |
| 233 | shift |
| 234 | ;; |
| 235 | --ssl-passwd) |
| 236 | PASSWD=$2 |
| 237 | shift 2 || { MS_Usage; exit 1; } |
| 238 | ;; |
| 239 | --ssl-pass-src) |
| 240 | PASSWD_SRC=$2 |
| 241 | shift 2 || { MS_Usage; exit 1; } |
| 242 | ;; |
| 243 | --ssl-no-md) |
| 244 | OPENSSL_NO_MD=y |
| 245 | shift |
| 246 | ;; |
| 247 | --nocomp) |
| 248 | COMPRESS=none |
| 249 | shift |
| 250 | ;; |
| 251 | --complevel) |
| 252 | COMPRESS_LEVEL="$2" |
| 253 | shift 2 || { MS_Usage; exit 1; } |
| 254 | ;; |
| 255 | --threads) |
| 256 | THREADS="$2" |
| 257 | shift 2 || { MS_Usage; exit 1; } |
| 258 | ;; |
| 259 | --nochown) |
| 260 | OWNERSHIP=n |
| 261 | shift |
| 262 | ;; |
| 263 | --chown) |
| 264 | OWNERSHIP=y |
| 265 | shift |
| 266 | ;; |
| 267 | --notemp) |
| 268 | KEEP=y |
| 269 | shift |
| 270 | ;; |
| 271 | --copy) |
| 272 | COPY=copy |
| 273 | shift |
| 274 | ;; |
| 275 | --current) |
| 276 | CURRENT=y |
| 277 | KEEP=y |
| 278 | shift |
| 279 | ;; |
| 280 | --tar-format) |
| 281 | TAR_FORMAT="$2" |
| 282 | shift 2 || { MS_Usage; exit 1; } |
| 283 | ;; |
| 284 | --tar-extra) |
| 285 | TAR_EXTRA="$2" |
| 286 | shift 2 || { MS_Usage; exit 1; } |
| 287 | ;; |
| 288 | --untar-extra) |
| 289 | UNTAR_EXTRA="$2" |
| 290 | shift 2 || { MS_Usage; exit 1; } |
| 291 | ;; |
| 292 | --target) |
| 293 | TARGETDIR="$2" |
| 294 | KEEP=y |
| 295 | shift 2 || { MS_Usage; exit 1; } |
| 296 | ;; |
| 297 | --sign) |
| 298 | SIGN=y |
| 299 | GPG_PASSPHRASE="$2" |
| 300 | shift 2 || { MS_Usage; exit 1; } |
| 301 | ;; |
| 302 | --nooverwrite) |
| 303 | NOOVERWRITE=y |
| 304 | shift |
| 305 | ;; |
| 306 | --needroot) |
| 307 | NEED_ROOT=y |
| 308 | shift |
| 309 | ;; |
| 310 | --header) |
| 311 | HEADER="$2" |
| 312 | shift 2 || { MS_Usage; exit 1; } |
| 313 | ;; |
| 314 | --cleanup) |
| 315 | CLEANUP_SCRIPT="$2" |
| 316 | shift 2 || { MS_Usage; exit 1; } |
| 317 | ;; |
| 318 | --license) |
| 319 | # We need to escape all characters having a special meaning in double quotes |
| 320 | LICENSE=$(sed 's/\\/\\\\/g; s/"/\\\"/g; s/`/\\\`/g; s/\$/\\\$/g' "$2") |
| 321 | shift 2 || { MS_Usage; exit 1; } |
| 322 | ;; |
| 323 | --follow) |
| 324 | TAR_ARGS=rvhf |
| 325 | DU_ARGS=-ksL |
| 326 | shift |
| 327 | ;; |
| 328 | --noprogress) |
| 329 | NOPROGRESS=y |
| 330 | shift |
| 331 | ;; |
| 332 | --nox11) |
| 333 | NOX11=y |
| 334 | shift |
| 335 | ;; |
| 336 | --nowait) |
| 337 | NOWAIT=y |
| 338 | shift |
| 339 | ;; |
| 340 | --nomd5) |
| 341 | NOMD5=y |
| 342 | shift |
| 343 | ;; |
| 344 | --sha256) |
| 345 | SHA256=y |
| 346 | shift |
| 347 | ;; |
| 348 | --nocrc) |
| 349 | NOCRC=y |
| 350 | shift |
| 351 | ;; |
| 352 | --append) |
| 353 | APPEND=y |
| 354 | shift |
| 355 | ;; |
| 356 | --lsm) |
| 357 | LSM_CMD="awk 1 \"$2\" >> \"\$archname\"" |
| 358 | shift 2 || { MS_Usage; exit 1; } |
| 359 | ;; |
| 360 | --packaging-date) |
| 361 | DATE="$2" |
| 362 | shift 2 || { MS_Usage; exit 1; } |
| 363 | ;; |
| 364 | --help-header) |
| 365 | HELPHEADER=`sed -e "s/'/'\\\\\''/g" $2` |
| 366 | shift 2 || { MS_Usage; exit 1; } |
| 367 | [ -n "$HELPHEADER" ] && HELPHEADER="$HELPHEADER |
| 368 | " |
| 369 | ;; |
| 370 | --tar-quietly) |
| 371 | TAR_QUIETLY=y |
| 372 | shift |
| 373 | ;; |
| 374 | --keep-umask) |
| 375 | KEEP_UMASK=y |
| 376 | shift |
| 377 | ;; |
| 378 | --export-conf) |
| 379 | EXPORT_CONF=y |
| 380 | shift |
| 381 | ;; |
| 382 | -q | --quiet) |
| 383 | QUIET=y |
| 384 | shift |
| 385 | ;; |
| 386 | -h | --help) |
| 387 | MS_Usage |
| 388 | ;; |
| 389 | -*) |
| 390 | echo Unrecognized flag : "$1" |
| 391 | MS_Usage |
| 392 | ;; |
| 393 | *) |
| 394 | break |
| 395 | ;; |
| 396 | esac |
| 397 | done |
| 398 | |
| 399 | if test $# -lt 1; then |
| 400 | MS_Usage |
| 401 | else |
| 402 | if test -d "$1"; then |
| 403 | archdir="$1" |
| 404 | else |
| 405 | echo "Directory $1 does not exist." >&2 |
| 406 | exit 1 |
| 407 | fi |
| 408 | fi |
| 409 | archname="$2" |
| 410 | |
| 411 | if test "$QUIET" = "y" || test "$TAR_QUIETLY" = "y"; then |
| 412 | if test "$TAR_ARGS" = "rvf"; then |
| 413 | TAR_ARGS="rf" |
| 414 | elif test "$TAR_ARGS" = "rvhf"; then |
| 415 | TAR_ARGS="rhf" |
| 416 | fi |
| 417 | fi |
| 418 | |
| 419 | if test "$APPEND" = y; then |
| 420 | if test $# -lt 2; then |
| 421 | MS_Usage |
| 422 | fi |
| 423 | |
| 424 | # Gather the info from the original archive |
| 425 | OLDENV=`sh "$archname" --dumpconf` |
| 426 | if test $? -ne 0; then |
| 427 | echo "Unable to update archive: $archname" >&2 |
| 428 | exit 1 |
| 429 | else |
| 430 | eval "$OLDENV" |
| 431 | OLDSKIP=`expr $SKIP + 1` |
| 432 | fi |
| 433 | else |
| 434 | if test "$KEEP" = n -a $# = 3; then |
| 435 | echo "ERROR: Making a temporary archive with no embedded command does not make sense!" >&2 |
| 436 | echo >&2 |
| 437 | MS_Usage |
| 438 | fi |
| 439 | # We don't want to create an absolute directory unless a target directory is defined |
| 440 | if test "$CURRENT" = y; then |
| 441 | archdirname="." |
| 442 | elif test x"$TARGETDIR" != x; then |
| 443 | archdirname="$TARGETDIR" |
| 444 | else |
| 445 | archdirname=`basename "$1"` |
| 446 | fi |
| 447 | |
| 448 | if test $# -lt 3; then |
| 449 | MS_Usage |
| 450 | fi |
| 451 | |
| 452 | LABEL="$3" |
| 453 | SCRIPT="$4" |
| 454 | test "x$SCRIPT" = x || shift 1 |
| 455 | shift 3 |
| 456 | SCRIPTARGS="$*" |
| 457 | fi |
| 458 | |
| 459 | if test "$KEEP" = n -a "$CURRENT" = y; then |
| 460 | echo "ERROR: It is A VERY DANGEROUS IDEA to try to combine --notemp and --current." >&2 |
| 461 | exit 1 |
| 462 | fi |
| 463 | |
| 464 | case $COMPRESS in |
| 465 | gzip) |
| 466 | GZIP_CMD="gzip -c$COMPRESS_LEVEL" |
| 467 | GUNZIP_CMD="gzip -cd" |
| 468 | ;; |
| 469 | pigz) |
| 470 | GZIP_CMD="pigz -$COMPRESS_LEVEL" |
| 471 | if test $THREADS -ne $DEFAULT_THREADS; then # Leave as the default if threads not indicated |
| 472 | GZIP_CMD="$GZIP_CMD --processes $THREADS" |
| 473 | fi |
| 474 | GUNZIP_CMD="gzip -cd" |
| 475 | ;; |
| 476 | zstd) |
| 477 | GZIP_CMD="zstd -$COMPRESS_LEVEL" |
| 478 | if test $THREADS -ne $DEFAULT_THREADS; then # Leave as the default if threads not indicated |
| 479 | GZIP_CMD="$GZIP_CMD --threads=$THREADS" |
| 480 | fi |
| 481 | GUNZIP_CMD="zstd -cd" |
| 482 | ;; |
| 483 | pbzip2) |
| 484 | GZIP_CMD="pbzip2 -c$COMPRESS_LEVEL" |
| 485 | if test $THREADS -ne $DEFAULT_THREADS; then # Leave as the default if threads not indicated |
| 486 | GZIP_CMD="$GZIP_CMD -p$THREADS" |
| 487 | fi |
| 488 | GUNZIP_CMD="bzip2 -d" |
| 489 | ;; |
| 490 | bzip3) |
| 491 | # Map the compression level to a block size in MiB as 2^(level-1). |
| 492 | BZ3_COMPRESS_LEVEL=`echo "2^($COMPRESS_LEVEL-1)" | bc` |
| 493 | GZIP_CMD="bzip3 -b$BZ3_COMPRESS_LEVEL" |
| 494 | if test $THREADS -ne $DEFAULT_THREADS; then # Leave as the default if threads not indicated |
| 495 | GZIP_CMD="$GZIP_CMD -j$THREADS" |
| 496 | fi |
| 497 | JOBS=`echo "10-$COMPRESS_LEVEL" | bc` |
| 498 | GUNZIP_CMD="bzip3 -dj$JOBS" |
| 499 | ;; |
| 500 | bzip2) |
| 501 | GZIP_CMD="bzip2 -$COMPRESS_LEVEL" |
| 502 | GUNZIP_CMD="bzip2 -d" |
| 503 | ;; |
| 504 | xz) |
| 505 | GZIP_CMD="xz -c$COMPRESS_LEVEL" |
| 506 | # Must opt-in by specifying a value since not all versions of xz support threads |
| 507 | if test $THREADS -ne $DEFAULT_THREADS; then |
| 508 | GZIP_CMD="$GZIP_CMD --threads=$THREADS" |
| 509 | fi |
| 510 | GUNZIP_CMD="xz -d" |
| 511 | ;; |
| 512 | lzo) |
| 513 | GZIP_CMD="lzop -c$COMPRESS_LEVEL" |
| 514 | GUNZIP_CMD="lzop -d" |
| 515 | ;; |
| 516 | lz4) |
| 517 | GZIP_CMD="lz4 -c$COMPRESS_LEVEL" |
| 518 | GUNZIP_CMD="lz4 -d" |
| 519 | ;; |
| 520 | base64) |
| 521 | GZIP_CMD="base64" |
| 522 | GUNZIP_CMD="base64 --decode -i -" |
| 523 | ;; |
| 524 | gpg) |
| 525 | GZIP_CMD="gpg $GPG_EXTRA -ac -z$COMPRESS_LEVEL" |
| 526 | GUNZIP_CMD="gpg -d" |
| 527 | ENCRYPT="gpg" |
| 528 | ;; |
| 529 | gpg-asymmetric) |
| 530 | GZIP_CMD="gpg $GPG_EXTRA -z$COMPRESS_LEVEL -es" |
| 531 | GUNZIP_CMD="gpg --yes -d" |
| 532 | ENCRYPT="gpg" |
| 533 | ;; |
| 534 | compress) |
| 535 | GZIP_CMD="compress -fc" |
| 536 | GUNZIP_CMD="(type compress >/dev/null 2>&1 && compress -fcd || gzip -cd)" |
| 537 | ;; |
| 538 | none) |
| 539 | GZIP_CMD="cat" |
| 540 | GUNZIP_CMD="cat" |
| 541 | ;; |
| 542 | esac |
| 543 | |
| 544 | if test x"$ENCRYPT" = x"openssl"; then |
| 545 | if test x"$APPEND" = x"y"; then |
| 546 | echo "Appending to existing archive is not compatible with OpenSSL encryption." >&2 |
| 547 | fi |
| 548 | |
| 549 | ENCRYPT_CMD="openssl enc -aes-256-cbc -salt" |
| 550 | DECRYPT_CMD="openssl enc -aes-256-cbc -d" |
| 551 | |
| 552 | if test x"$OPENSSL_NO_MD" != x"y"; then |
| 553 | ENCRYPT_CMD="$ENCRYPT_CMD -md sha256" |
| 554 | DECRYPT_CMD="$DECRYPT_CMD -md sha256" |
| 555 | fi |
| 556 | |
| 557 | if test -n "$PASSWD_SRC"; then |
| 558 | ENCRYPT_CMD="$ENCRYPT_CMD -pass $PASSWD_SRC" |
| 559 | elif test -n "$PASSWD"; then |
| 560 | ENCRYPT_CMD="$ENCRYPT_CMD -pass pass:$PASSWD" |
| 561 | fi |
| 562 | fi |
| 563 | |
| 564 | tmpfile="${TMPDIR:-/tmp}/mkself$$" |
| 565 | |
| 566 | if test -f "$HEADER"; then |
| 567 | oldarchname="$archname" |
| 568 | archname="$tmpfile" |
| 569 | # Generate a fake header to count its lines |
| 570 | SKIP=0 |
| 571 | . "$HEADER" |
| 572 | SKIP=`cat "$tmpfile" |wc -l` |
| 573 | # Get rid of any spaces |
| 574 | SKIP=`expr $SKIP` |
| 575 | rm -f "$tmpfile" |
| 576 | if test "$QUIET" = "n"; then |
| 577 | echo "Header is $SKIP lines long" >&2 |
| 578 | fi |
| 579 | archname="$oldarchname" |
| 580 | else |
| 581 | echo "Unable to open header file: $HEADER" >&2 |
| 582 | exit 1 |
| 583 | fi |
| 584 | |
| 585 | if test "$QUIET" = "n"; then |
| 586 | echo |
| 587 | fi |
| 588 | |
| 589 | if test "$APPEND" = n; then |
| 590 | if test -f "$archname"; then |
| 591 | echo "WARNING: Overwriting existing file: $archname" >&2 |
| 592 | fi |
| 593 | fi |
| 594 | |
| 595 | USIZE=`du $DU_ARGS "$archdir" | awk '{print $1}'` |
| 596 | |
| 597 | if test "." = "$archdirname"; then |
| 598 | if test "$KEEP" = n; then |
| 599 | archdirname="makeself-$$-`date +%Y%m%d%H%M%S`" |
| 600 | fi |
| 601 | fi |
| 602 | |
| 603 | test -d "$archdir" || { echo "Error: $archdir does not exist."; rm -f "$tmpfile"; exit 1; } |
| 604 | if test "$QUIET" = "n"; then |
| 605 | echo "About to compress $USIZE KB of data..." |
| 606 | echo "Adding files to archive named \"$archname\"..." |
| 607 | fi |
| 608 | |
| 609 | # See if we have GNU tar |
| 610 | TAR=`exec <&- 2>&-; which gtar || command -v gtar || type gtar` |
| 611 | test -x "$TAR" || TAR=`exec <&- 2>&-; which bsdtar || command -v bsdtar || type bsdtar` |
| 612 | test -x "$TAR" || TAR=tar |
| 613 | |
| 614 | tmparch="${TMPDIR:-/tmp}/mkself$$.tar" |
| 615 | ( |
| 616 | if test "$APPEND" = "y"; then |
| 617 | tail -n "+$OLDSKIP" "$archname" | eval "$GUNZIP_CMD" > "$tmparch" |
| 618 | fi |
| 619 | cd "$archdir" |
| 620 | # "Determining if a directory is empty" |
| 621 | # https://www.etalabs.net/sh_tricks.html |
| 622 | find . \ |
| 623 | \( \ |
| 624 | ! -type d \ |
| 625 | -o \ |
| 626 | \( -links 2 -exec sh -c ' |
| 627 | is_empty () ( |
| 628 | cd "$1" |
| 629 | set -- .[!.]* ; test -f "$1" && return 1 |
| 630 | set -- ..?* ; test -f "$1" && return 1 |
| 631 | set -- * ; test -f "$1" && return 1 |
| 632 | return 0 |
| 633 | ) |
| 634 | is_empty "$0"' {} \; \ |
| 635 | \) \ |
| 636 | \) -print \ |
| 637 | | LC_ALL=C sort \ |
| 638 | | sed 's/./\\&/g' \ |
| 639 | | xargs $TAR $TAR_EXTRA --format $TAR_FORMAT -$TAR_ARGS "$tmparch" |
| 640 | ) || { |
| 641 | echo "ERROR: failed to create temporary archive: $tmparch" |
| 642 | rm -f "$tmparch" "$tmpfile" |
| 643 | exit 1 |
| 644 | } |
| 645 | |
| 646 | USIZE=`du $DU_ARGS "$tmparch" | awk '{print $1}'` |
| 647 | |
| 648 | eval "$GZIP_CMD" <"$tmparch" >"$tmpfile" || { |
| 649 | echo "ERROR: failed to create temporary file: $tmpfile" |
| 650 | rm -f "$tmparch" "$tmpfile" |
| 651 | exit 1 |
| 652 | } |
| 653 | rm -f "$tmparch" |
| 654 | |
| 655 | if test x"$ENCRYPT" = x"openssl"; then |
| 656 | echo "About to encrypt archive \"$archname\"..." |
| 657 | { eval "$ENCRYPT_CMD -in $tmpfile -out ${tmpfile}.enc" && mv -f ${tmpfile}.enc $tmpfile; } || \ |
| 658 | { echo Aborting: could not encrypt temporary file: "$tmpfile".; rm -f "$tmpfile"; exit 1; } |
| 659 | fi |
| 660 | |
| 661 | fsize=`cat "$tmpfile" | wc -c | tr -d " "` |
| 662 | |
| 663 | # Compute the checksums |
| 664 | |
| 665 | shasum=0000000000000000000000000000000000000000000000000000000000000000 |
| 666 | md5sum=00000000000000000000000000000000 |
| 667 | crcsum=0000000000 |
| 668 | |
| 669 | if test "$NOCRC" = y; then |
| 670 | if test "$QUIET" = "n"; then |
| 671 | echo "skipping crc at user request" |
| 672 | fi |
| 673 | else |
| 674 | crcsum=`CMD_ENV=xpg4 cksum < "$tmpfile" | sed -e 's/ /Z/' -e 's/ /Z/' | cut -dZ -f1` |
| 675 | if test "$QUIET" = "n"; then |
| 676 | echo "CRC: $crcsum" |
| 677 | fi |
| 678 | fi |
| 679 | |
| 680 | if test "$SHA256" = y; then |
| 681 | SHA_PATH=`exec <&- 2>&-; which shasum || command -v shasum || type shasum` |
| 682 | if test -x "$SHA_PATH"; then |
| 683 | shasum=`eval "$SHA_PATH -a 256" < "$tmpfile" | cut -b-64` |
| 684 | else |
| 685 | SHA_PATH=`exec <&- 2>&-; which sha256sum || command -v sha256sum || type sha256sum` |
| 686 | shasum=`eval "$SHA_PATH" < "$tmpfile" | cut -b-64` |
| 687 | fi |
| 688 | if test "$QUIET" = "n"; then |
| 689 | if test -x "$SHA_PATH"; then |
| 690 | echo "SHA256: $shasum" |
| 691 | else |
| 692 | echo "SHA256: none, SHA command not found" |
| 693 | fi |
| 694 | fi |
| 695 | fi |
| 696 | if test "$NOMD5" = y; then |
| 697 | if test "$QUIET" = "n"; then |
| 698 | echo "Skipping md5sum at user request" |
| 699 | fi |
| 700 | else |
| 701 | # Try to locate a MD5 binary |
| 702 | OLD_PATH=$PATH |
| 703 | PATH=${GUESS_MD5_PATH:-"$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"} |
| 704 | MD5_ARG="" |
| 705 | MD5_PATH=`exec <&- 2>&-; which md5sum || command -v md5sum || type md5sum` |
| 706 | test -x "$MD5_PATH" || MD5_PATH=`exec <&- 2>&-; which md5 || command -v md5 || type md5` |
| 707 | test -x "$MD5_PATH" || MD5_PATH=`exec <&- 2>&-; which digest || command -v digest || type digest` |
| 708 | PATH=$OLD_PATH |
| 709 | if test -x "$MD5_PATH"; then |
| 710 | if test `basename ${MD5_PATH}`x = digestx; then |
| 711 | MD5_ARG="-a md5" |
| 712 | fi |
| 713 | md5sum=`eval "$MD5_PATH $MD5_ARG" < "$tmpfile" | cut -b-32` |
| 714 | if test "$QUIET" = "n"; then |
| 715 | echo "MD5: $md5sum" |
| 716 | fi |
| 717 | else |
| 718 | if test "$QUIET" = "n"; then |
| 719 | echo "MD5: none, MD5 command not found" |
| 720 | fi |
| 721 | fi |
| 722 | fi |
| 723 | if test "$SIGN" = y; then |
| 724 | GPG_PATH=`exec <&- 2>&-; which gpg || command -v gpg || type gpg` |
| 725 | if test -x "$GPG_PATH"; then |
| 726 | SIGNATURE=`$GPG_PATH --pinentry-mode=loopback --batch --yes $GPG_EXTRA --passphrase "$GPG_PASSPHRASE" --output - --detach-sig $tmpfile | base64 | tr -d \\\\n` |
| 727 | if test "$QUIET" = "n"; then |
| 728 | echo "Signature: $SIGNATURE" |
| 729 | fi |
| 730 | else |
| 731 | echo "Missing gpg command" >&2 |
| 732 | fi |
| 733 | fi |
| 734 | |
| 735 | totalsize=0 |
| 736 | for size in $fsize; |
| 737 | do |
| 738 | totalsize=`expr $totalsize + $size` |
| 739 | done |
| 740 | |
| 741 | if test "$APPEND" = y; then |
| 742 | mv "$archname" "$archname".bak || exit |
| 743 | |
| 744 | # Prepare entry for new archive |
| 745 | filesizes="$fsize" |
| 746 | CRCsum="$crcsum" |
| 747 | MD5sum="$md5sum" |
| 748 | SHAsum="$shasum" |
| 749 | Signature="$SIGNATURE" |
| 750 | # Generate the header |
| 751 | . "$HEADER" |
| 752 | # Append the new data |
| 753 | cat "$tmpfile" >> "$archname" |
| 754 | |
| 755 | chmod +x "$archname" |
| 756 | rm -f "$archname".bak |
| 757 | if test "$QUIET" = "n"; then |
| 758 | echo "Self-extractable archive \"$archname\" successfully updated." |
| 759 | fi |
| 760 | else |
| 761 | filesizes="$fsize" |
| 762 | CRCsum="$crcsum" |
| 763 | MD5sum="$md5sum" |
| 764 | SHAsum="$shasum" |
| 765 | Signature="$SIGNATURE" |
| 766 | |
| 767 | # Generate the header |
| 768 | . "$HEADER" |
| 769 | |
| 770 | # Append the compressed tar data after the stub |
| 771 | if test "$QUIET" = "n"; then |
| 772 | echo |
| 773 | fi |
| 774 | cat "$tmpfile" >> "$archname" |
| 775 | chmod +x "$archname" |
| 776 | if test "$QUIET" = "n"; then |
| 777 | echo Self-extractable archive \"$archname\" successfully created. |
| 778 | fi |
| 779 | fi |
| 780 | rm -f "$tmpfile" |