makeself-header.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. # SPDX-License-Identifier: GPL-3.0-or-later
  2. # shellcheck shell=sh
  3. # shellcheck disable=SC2154,SC2039
  4. cat << EOF > "$archname"
  5. #!/bin/sh
  6. # This script was generated using Makeself $MS_VERSION
  7. ORIG_UMASK=\`umask\`
  8. if test "$KEEP_UMASK" = n; then
  9. umask 077
  10. fi
  11. CRCsum="$CRCsum"
  12. MD5="$MD5sum"
  13. TMPROOT=\${TMPDIR:=/tmp}
  14. USER_PWD="\$PWD"; export USER_PWD
  15. label="$LABEL"
  16. script="$SCRIPT"
  17. scriptargs="$SCRIPTARGS"
  18. licensetxt="$LICENSE"
  19. helpheader='$HELPHEADER'
  20. targetdir="$archdirname"
  21. filesizes="$filesizes"
  22. keep="$KEEP"
  23. nooverwrite="$NOOVERWRITE"
  24. quiet="n"
  25. accept="n"
  26. nodiskspace="n"
  27. export_conf="$EXPORT_CONF"
  28. print_cmd_arg=""
  29. if type printf > /dev/null; then
  30. print_cmd="printf"
  31. elif test -x /usr/ucb/echo; then
  32. print_cmd="/usr/ucb/echo"
  33. else
  34. print_cmd="echo"
  35. fi
  36. if test -d /usr/xpg4/bin; then
  37. PATH=/usr/xpg4/bin:\$PATH
  38. export PATH
  39. fi
  40. unset CDPATH
  41. MS_Printf()
  42. {
  43. \$print_cmd \$print_cmd_arg "\$1"
  44. }
  45. MS_PrintLicense()
  46. {
  47. if test x"\$licensetxt" != x; then
  48. echo "\$licensetxt"
  49. if test x"\$accept" != xy; then
  50. while true
  51. do
  52. MS_Printf "Please type y to accept, n otherwise: "
  53. read yn
  54. if test x"\$yn" = xn; then
  55. keep=n
  56. eval \$finish; exit 1
  57. break;
  58. elif test x"\$yn" = xy; then
  59. break;
  60. fi
  61. done
  62. fi
  63. fi
  64. }
  65. MS_diskspace()
  66. {
  67. (
  68. df -kP "\$1" | tail -1 | awk '{ if (\$4 ~ /%/) {print \$3} else {print \$4} }'
  69. )
  70. }
  71. MS_dd()
  72. {
  73. blocks=\`expr \$3 / 1024\`
  74. bytes=\`expr \$3 % 1024\`
  75. dd if="\$1" ibs=\$2 skip=1 obs=1024 conv=sync 2> /dev/null | \\
  76. { test \$blocks -gt 0 && dd ibs=1024 obs=1024 count=\$blocks ; \\
  77. test \$bytes -gt 0 && dd ibs=1 obs=1024 count=\$bytes ; } 2> /dev/null
  78. }
  79. MS_dd_Progress()
  80. {
  81. if test x"\$noprogress" = xy; then
  82. MS_dd \$@
  83. return \$?
  84. fi
  85. file="\$1"
  86. offset=\$2
  87. length=\$3
  88. pos=0
  89. bsize=4194304
  90. while test \$bsize -gt \$length; do
  91. bsize=\`expr \$bsize / 4\`
  92. done
  93. blocks=\`expr \$length / \$bsize\`
  94. bytes=\`expr \$length % \$bsize\`
  95. (
  96. dd ibs=\$offset skip=1 2>/dev/null
  97. pos=\`expr \$pos \+ \$bsize\`
  98. MS_Printf " 0%% " 1>&2
  99. if test \$blocks -gt 0; then
  100. while test \$pos -le \$length; do
  101. dd bs=\$bsize count=1 2>/dev/null
  102. pcent=\`expr \$length / 100\`
  103. pcent=\`expr \$pos / \$pcent\`
  104. if test \$pcent -lt 100; then
  105. MS_Printf "\b\b\b\b\b\b\b" 1>&2
  106. if test \$pcent -lt 10; then
  107. MS_Printf " \$pcent%% " 1>&2
  108. else
  109. MS_Printf " \$pcent%% " 1>&2
  110. fi
  111. fi
  112. pos=\`expr \$pos \+ \$bsize\`
  113. done
  114. fi
  115. if test \$bytes -gt 0; then
  116. dd bs=\$bytes count=1 2>/dev/null
  117. fi
  118. MS_Printf "\b\b\b\b\b\b\b" 1>&2
  119. MS_Printf " 100%% " 1>&2
  120. ) < "\$file"
  121. }
  122. MS_Help()
  123. {
  124. cat << EOH >&2
  125. \${helpheader}Makeself version $MS_VERSION
  126. 1) Getting help or info about \$0 :
  127. \$0 --help Print this message
  128. \$0 --info Print embedded info : title, default target directory, embedded script ...
  129. \$0 --lsm Print embedded lsm entry (or no LSM)
  130. \$0 --list Print the list of files in the archive
  131. \$0 --check Checks integrity of the archive
  132. 2) Running \$0 :
  133. \$0 [options] [--] [additional arguments to embedded script]
  134. with following options (in that order)
  135. --confirm Ask before running embedded script
  136. --quiet Do not print anything except error messages
  137. --accept Accept the license
  138. --noexec Do not run embedded script
  139. --keep Do not erase target directory after running
  140. the embedded script
  141. --noprogress Do not show the progress during the decompression
  142. --nox11 Do not spawn an xterm
  143. --nochown Do not give the extracted files to the current user
  144. --nodiskspace Do not check for available disk space
  145. --target dir Extract directly to a target directory
  146. directory path can be either absolute or relative
  147. --tar arg1 [arg2 ...] Access the contents of the archive through the tar command
  148. -- Following arguments will be passed to the embedded script
  149. EOH
  150. }
  151. MS_Check()
  152. {
  153. OLD_PATH="\$PATH"
  154. PATH=\${GUESS_MD5_PATH:-"\$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"}
  155. MD5_ARG=""
  156. MD5_PATH=\`exec <&- 2>&-; which md5sum || command -v md5sum || type md5sum\`
  157. test -x "\$MD5_PATH" || MD5_PATH=\`exec <&- 2>&-; which md5 || command -v md5 || type md5\`
  158. test -x "\$MD5_PATH" || MD5_PATH=\`exec <&- 2>&-; which digest || command -v digest || type digest\`
  159. PATH="\$OLD_PATH"
  160. if test x"\$quiet" = xn; then
  161. MS_Printf "Verifying archive integrity..."
  162. fi
  163. offset=\`head -n $SKIP "\$1" | wc -c | tr -d " "\`
  164. verb=\$2
  165. i=1
  166. for s in \$filesizes
  167. do
  168. crc=\`echo \$CRCsum | cut -d" " -f\$i\`
  169. if test -x "\$MD5_PATH"; then
  170. if test x"\`basename \$MD5_PATH\`" = xdigest; then
  171. MD5_ARG="-a md5"
  172. fi
  173. md5=\`echo \$MD5 | cut -d" " -f\$i\`
  174. if test x"\$md5" = x00000000000000000000000000000000; then
  175. test x"\$verb" = xy && echo " \$1 does not contain an embedded MD5 checksum." >&2
  176. else
  177. md5sum=\`MS_dd_Progress "\$1" \$offset \$s | eval "\$MD5_PATH \$MD5_ARG" | cut -b-32\`;
  178. if test x"\$md5sum" != x"\$md5"; then
  179. echo "Error in MD5 checksums: \$md5sum is different from \$md5" >&2
  180. exit 2
  181. else
  182. test x"\$verb" = xy && MS_Printf " MD5 checksums are OK." >&2
  183. fi
  184. crc="0000000000"; verb=n
  185. fi
  186. fi
  187. if test x"\$crc" = x0000000000; then
  188. test x"\$verb" = xy && echo " \$1 does not contain a CRC checksum." >&2
  189. else
  190. sum1=\`MS_dd_Progress "\$1" \$offset \$s | CMD_ENV=xpg4 cksum | awk '{print \$1}'\`
  191. if test x"\$sum1" = x"\$crc"; then
  192. test x"\$verb" = xy && MS_Printf " CRC checksums are OK." >&2
  193. else
  194. echo "Error in checksums: \$sum1 is different from \$crc" >&2
  195. exit 2;
  196. fi
  197. fi
  198. i=\`expr \$i + 1\`
  199. offset=\`expr \$offset + \$s\`
  200. done
  201. if test x"\$quiet" = xn; then
  202. echo " All good."
  203. fi
  204. }
  205. UnTAR()
  206. {
  207. if test x"\$quiet" = xn; then
  208. tar \$1vf - $UNTAR_EXTRA 2>&1 || { echo " ... Extraction failed." > /dev/tty; kill -15 \$$; }
  209. else
  210. tar \$1f - $UNTAR_EXTRA 2>&1 || { echo Extraction failed. > /dev/tty; kill -15 \$$; }
  211. fi
  212. }
  213. finish=true
  214. xterm_loop=
  215. noprogress=$NOPROGRESS
  216. nox11=$NOX11
  217. copy=$COPY
  218. ownership=y
  219. verbose=n
  220. initargs="\$@"
  221. while true
  222. do
  223. case "\$1" in
  224. -h | --help)
  225. MS_Help
  226. exit 0
  227. ;;
  228. -q | --quiet)
  229. quiet=y
  230. noprogress=y
  231. shift
  232. ;;
  233. --accept)
  234. accept=y
  235. shift
  236. ;;
  237. --info)
  238. echo Identification: "\$label"
  239. echo Target directory: "\$targetdir"
  240. echo Uncompressed size: $USIZE KB
  241. echo Compression: $COMPRESS
  242. echo Date of packaging: $DATE
  243. echo Built with Makeself version $MS_VERSION on $OSTYPE
  244. echo Build command was: "$MS_COMMAND"
  245. if test x"\$script" != x; then
  246. echo Script run after extraction:
  247. echo " " \$script \$scriptargs
  248. fi
  249. if test x"$copy" = xcopy; then
  250. echo "Archive will copy itself to a temporary location"
  251. fi
  252. if test x"$NEED_ROOT" = xy; then
  253. echo "Root permissions required for extraction"
  254. fi
  255. if test x"$KEEP" = xy; then
  256. echo "directory \$targetdir is permanent"
  257. else
  258. echo "\$targetdir will be removed after extraction"
  259. fi
  260. exit 0
  261. ;;
  262. --dumpconf)
  263. echo LABEL=\"\$label\"
  264. echo SCRIPT=\"\$script\"
  265. echo SCRIPTARGS=\"\$scriptargs\"
  266. echo archdirname=\"$archdirname\"
  267. echo KEEP=$KEEP
  268. echo NOOVERWRITE=$NOOVERWRITE
  269. echo COMPRESS=$COMPRESS
  270. echo filesizes=\"\$filesizes\"
  271. echo CRCsum=\"\$CRCsum\"
  272. echo MD5sum=\"\$MD5\"
  273. echo OLDUSIZE=$USIZE
  274. echo OLDSKIP=$((SKIP + 1))
  275. exit 0
  276. ;;
  277. --lsm)
  278. cat << EOLSM
  279. EOF
  280. eval "$LSM_CMD"
  281. cat << EOF >> "$archname"
  282. EOLSM
  283. exit 0
  284. ;;
  285. --list)
  286. echo Target directory: \$targetdir
  287. offset=\`head -n $SKIP "\$0" | wc -c | tr -d " "\`
  288. for s in \$filesizes
  289. do
  290. MS_dd "\$0" \$offset \$s | eval "$GUNZIP_CMD" | UnTAR t
  291. offset=\`expr \$offset + \$s\`
  292. done
  293. exit 0
  294. ;;
  295. --tar)
  296. offset=\`head -n $SKIP "\$0" | wc -c | tr -d " "\`
  297. arg1="\$2"
  298. if ! shift 2; then MS_Help; exit 1; fi
  299. for s in \$filesizes
  300. do
  301. MS_dd "\$0" \$offset \$s | eval "$GUNZIP_CMD" | tar "\$arg1" - "\$@"
  302. offset=\`expr \$offset + \$s\`
  303. done
  304. exit 0
  305. ;;
  306. --check)
  307. MS_Check "\$0" y
  308. exit 0
  309. ;;
  310. --confirm)
  311. verbose=y
  312. shift
  313. ;;
  314. --noexec)
  315. script=""
  316. shift
  317. ;;
  318. --keep)
  319. keep=y
  320. shift
  321. ;;
  322. --target)
  323. keep=y
  324. targetdir=\${2:-.}
  325. if ! shift 2; then MS_Help; exit 1; fi
  326. ;;
  327. --noprogress)
  328. noprogress=y
  329. shift
  330. ;;
  331. --nox11)
  332. nox11=y
  333. shift
  334. ;;
  335. --nochown)
  336. ownership=n
  337. shift
  338. ;;
  339. --nodiskspace)
  340. nodiskspace=y
  341. shift
  342. ;;
  343. --xwin)
  344. if test "$NOWAIT" = n; then
  345. finish="echo Press Return to close this window...; read junk"
  346. fi
  347. xterm_loop=1
  348. shift
  349. ;;
  350. --phase2)
  351. copy=phase2
  352. shift
  353. ;;
  354. --)
  355. shift
  356. break ;;
  357. -*)
  358. echo Unrecognized flag : "\$1" >&2
  359. MS_Help
  360. exit 1
  361. ;;
  362. *)
  363. break ;;
  364. esac
  365. done
  366. if test x"\$quiet" = xy -a x"\$verbose" = xy; then
  367. echo Cannot be verbose and quiet at the same time. >&2
  368. exit 1
  369. fi
  370. if test x"$NEED_ROOT" = xy -a \`id -u\` -ne 0; then
  371. echo "Administrative privileges required for this archive (use su or sudo)" >&2
  372. exit 1
  373. fi
  374. if test x"\$copy" \!= xphase2; then
  375. MS_PrintLicense
  376. fi
  377. case "\$copy" in
  378. copy)
  379. tmpdir=\$TMPROOT/makeself.\$RANDOM.\`date +"%y%m%d%H%M%S"\`.\$\$
  380. mkdir "\$tmpdir" || {
  381. echo "Could not create temporary directory \$tmpdir" >&2
  382. exit 1
  383. }
  384. SCRIPT_COPY="\$tmpdir/makeself"
  385. echo "Copying to a temporary location..." >&2
  386. cp "\$0" "\$SCRIPT_COPY"
  387. chmod +x "\$SCRIPT_COPY"
  388. cd "\$TMPROOT"
  389. exec "\$SCRIPT_COPY" --phase2 -- \$initargs
  390. ;;
  391. phase2)
  392. finish="\$finish ; rm -rf \`dirname \$0\`"
  393. ;;
  394. esac
  395. if test x"\$nox11" = xn; then
  396. if tty -s; then # Do we have a terminal?
  397. :
  398. else
  399. if test x"\$DISPLAY" != x -a x"\$xterm_loop" = x; then # No, but do we have X?
  400. if xset q > /dev/null 2>&1; then # Check for valid DISPLAY variable
  401. GUESS_XTERMS="xterm gnome-terminal rxvt dtterm eterm Eterm xfce4-terminal lxterminal kvt konsole aterm terminology"
  402. for a in \$GUESS_XTERMS; do
  403. if type \$a >/dev/null 2>&1; then
  404. XTERM=\$a
  405. break
  406. fi
  407. done
  408. chmod a+x \$0 || echo Please add execution rights on \$0
  409. if test \`echo "\$0" | cut -c1\` = "/"; then # Spawn a terminal!
  410. exec \$XTERM -title "\$label" -e "\$0" --xwin "\$initargs"
  411. else
  412. exec \$XTERM -title "\$label" -e "./\$0" --xwin "\$initargs"
  413. fi
  414. fi
  415. fi
  416. fi
  417. fi
  418. if test x"\$targetdir" = x.; then
  419. tmpdir="."
  420. else
  421. if test x"\$keep" = xy; then
  422. if test x"\$nooverwrite" = xy && test -d "\$targetdir"; then
  423. echo "Target directory \$targetdir already exists, aborting." >&2
  424. exit 1
  425. fi
  426. if test x"\$quiet" = xn; then
  427. echo "Creating directory \$targetdir" >&2
  428. fi
  429. tmpdir="\$targetdir"
  430. dashp="-p"
  431. else
  432. tmpdir="\$TMPROOT/selfgz\$\$\$RANDOM"
  433. dashp=""
  434. fi
  435. mkdir \$dashp \$tmpdir || {
  436. echo 'Cannot create target directory' \$tmpdir >&2
  437. echo 'You should try option --target dir' >&2
  438. eval \$finish
  439. exit 1
  440. }
  441. fi
  442. location="\`pwd\`"
  443. if test x"\$SETUP_NOCHECK" != x1; then
  444. MS_Check "\$0"
  445. fi
  446. offset=\`head -n $SKIP "\$0" | wc -c | tr -d " "\`
  447. if test x"\$verbose" = xy; then
  448. MS_Printf "About to extract $USIZE KB in \$tmpdir ... Proceed ? [Y/n] "
  449. read yn
  450. if test x"\$yn" = xn; then
  451. eval \$finish; exit 1
  452. fi
  453. fi
  454. if test x"\$quiet" = xn; then
  455. MS_Printf "Uncompressing \$label"
  456. fi
  457. res=3
  458. if test x"\$keep" = xn; then
  459. trap 'echo Signal caught, cleaning up >&2; cd \$TMPROOT; /bin/rm -rf \$tmpdir; eval \$finish; exit 15' 1 2 3 15
  460. fi
  461. if test x"\$nodiskspace" = xn; then
  462. leftspace=\`MS_diskspace \$tmpdir\`
  463. if test -n "\$leftspace"; then
  464. if test "\$leftspace" -lt $USIZE; then
  465. echo
  466. echo "Not enough space left in "\`dirname \$tmpdir\`" (\$leftspace KB) to decompress \$0 ($USIZE KB)" >&2
  467. echo "Use --nodiskspace option to skip this check and proceed anyway" >&2
  468. if test x"\$keep" = xn; then
  469. echo "Consider setting TMPDIR to a directory with more free space."
  470. fi
  471. eval \$finish; exit 1
  472. fi
  473. fi
  474. fi
  475. for s in \$filesizes
  476. do
  477. if MS_dd_Progress "\$0" \$offset \$s | eval "$GUNZIP_CMD" | ( cd "\$tmpdir"; umask \$ORIG_UMASK ; UnTAR xp ) 1>/dev/null; then
  478. if test x"\$ownership" = xy; then
  479. (cd "\$tmpdir"; chown -R \`id -u\` .; chgrp -R \`id -g\` .)
  480. fi
  481. else
  482. echo >&2
  483. echo "Unable to decompress \$0" >&2
  484. eval \$finish; exit 1
  485. fi
  486. offset=\`expr \$offset + \$s\`
  487. done
  488. if test x"\$quiet" = xn; then
  489. echo
  490. fi
  491. cd "\$tmpdir"
  492. res=0
  493. if test x"\$script" != x; then
  494. if test x"\$export_conf" = x"y"; then
  495. MS_BUNDLE="\$0"
  496. MS_LABEL="\$label"
  497. MS_SCRIPT="\$script"
  498. MS_SCRIPTARGS="\$scriptargs"
  499. MS_ARCHDIRNAME="\$archdirname"
  500. MS_KEEP="\$KEEP"
  501. MS_NOOVERWRITE="\$NOOVERWRITE"
  502. MS_COMPRESS="\$COMPRESS"
  503. export MS_BUNDLE MS_LABEL MS_SCRIPT MS_SCRIPTARGS
  504. export MS_ARCHDIRNAME MS_KEEP MS_NOOVERWRITE MS_COMPRESS
  505. fi
  506. if test x"\$verbose" = x"y"; then
  507. MS_Printf "OK to execute: \$script \$scriptargs \$* ? [Y/n] "
  508. read yn
  509. if test x"\$yn" = x -o x"\$yn" = xy -o x"\$yn" = xY; then
  510. eval "\"\$script\" \$scriptargs \"\\\$@\""; res=\$?;
  511. fi
  512. else
  513. eval "\"\$script\" \$scriptargs \"\\\$@\""; res=\$?
  514. fi
  515. if test "\$res" -ne 0; then
  516. test x"\$verbose" = xy && echo "The program '\$script' returned an error code (\$res)" >&2
  517. fi
  518. fi
  519. if test x"\$keep" = xn; then
  520. cd \$TMPROOT
  521. /bin/rm -rf \$tmpdir
  522. fi
  523. eval \$finish; exit \$res
  524. EOF