makeself.sh 21 KB

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