makeself-header.sh 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. cat << EOF > "$archname"
  2. #!/bin/sh
  3. # This script was generated using Makeself $MS_VERSION
  4. CRCsum="$CRCsum"
  5. MD5="$MD5sum"
  6. TMPROOT=\${TMPDIR:=/tmp}
  7. label="$LABEL"
  8. script="$SCRIPT"
  9. scriptargs="$SCRIPTARGS"
  10. targetdir="$archdirname"
  11. filesizes="$filesizes"
  12. keep=$KEEP
  13. print_cmd_arg=""
  14. if type printf > /dev/null; then
  15. print_cmd="printf"
  16. elif test -x /usr/ucb/echo; then
  17. print_cmd="/usr/ucb/echo"
  18. else
  19. print_cmd="echo"
  20. fi
  21. unset CDPATH
  22. MS_Printf()
  23. {
  24. \$print_cmd \$print_cmd_arg "\$1"
  25. }
  26. MS_Progress()
  27. {
  28. while read a; do
  29. MS_Printf .
  30. done
  31. }
  32. MS_diskspace()
  33. {
  34. (
  35. if test -d /usr/xpg4/bin; then
  36. PATH=/usr/xpg4/bin:\$PATH
  37. fi
  38. df -kP "\$1" | tail -1 | awk '{print \$4}'
  39. )
  40. }
  41. MS_dd()
  42. {
  43. blocks=\`expr \$3 / 1024\`
  44. bytes=\`expr \$3 % 1024\`
  45. dd if="\$1" ibs=\$2 skip=1 obs=1024 conv=sync 2> /dev/null | \\
  46. { test \$blocks -gt 0 && dd ibs=1024 obs=1024 count=\$blocks ; \\
  47. test \$bytes -gt 0 && dd ibs=1 obs=1024 count=\$bytes ; } 2> /dev/null
  48. }
  49. MS_Help()
  50. {
  51. cat << EOH >&2
  52. Makeself version $MS_VERSION
  53. 1) Getting help or info about \$0 :
  54. \$0 --help Print this message
  55. \$0 --info Print embedded info : title, default target directory, embedded script ...
  56. \$0 --lsm Print embedded lsm entry (or no LSM)
  57. \$0 --list Print the list of files in the archive
  58. \$0 --check Checks integrity of the archive
  59. 2) Running \$0 :
  60. \$0 [options] [--] [additional arguments to embedded script]
  61. with following options (in that order)
  62. --confirm Ask before running embedded script
  63. --noexec Do not run embedded script
  64. --keep Do not erase target directory after running
  65. the embedded script
  66. --nox11 Do not spawn an xterm
  67. --nochown Do not give the extracted files to the current user
  68. --target NewDirectory Extract in NewDirectory
  69. --tar arg1 [arg2 ...] Access the contents of the archive through the tar command
  70. -- Following arguments will be passed to the embedded script
  71. EOH
  72. }
  73. MS_Check()
  74. {
  75. OLD_PATH="\$PATH"
  76. PATH=\${GUESS_MD5_PATH:-"\$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"}
  77. MD5_ARG=""
  78. MD5_PATH=\`exec <&- 2>&-; which md5sum || type md5sum\`
  79. test -x "\$MD5_PATH" || MD5_PATH=\`exec <&- 2>&-; which md5 || type md5\`
  80. test -x "\$MD5_PATH" || MD5_PATH=\`exec <&- 2>&-; which digest || type digest\`
  81. PATH="\$OLD_PATH"
  82. MS_Printf "Verifying archive integrity..."
  83. offset=\`head -n $SKIP "\$1" | wc -c | tr -d " "\`
  84. verb=\$2
  85. i=1
  86. for s in \$filesizes
  87. do
  88. crc=\`echo \$CRCsum | cut -d" " -f\$i\`
  89. if test -x "\$MD5_PATH"; then
  90. if test \`basename \$MD5_PATH\` = digest; then
  91. MD5_ARG="-a md5"
  92. fi
  93. md5=\`echo \$MD5 | cut -d" " -f\$i\`
  94. if test \$md5 = "00000000000000000000000000000000"; then
  95. test x\$verb = xy && echo " \$1 does not contain an embedded MD5 checksum." >&2
  96. else
  97. md5sum=\`MS_dd "\$1" \$offset \$s | eval "\$MD5_PATH \$MD5_ARG" | cut -b-32\`;
  98. if test "\$md5sum" != "\$md5"; then
  99. echo "Error in MD5 checksums: \$md5sum is different from \$md5" >&2
  100. exit 2
  101. else
  102. test x\$verb = xy && MS_Printf " MD5 checksums are OK." >&2
  103. fi
  104. crc="0000000000"; verb=n
  105. fi
  106. fi
  107. if test \$crc = "0000000000"; then
  108. test x\$verb = xy && echo " \$1 does not contain a CRC checksum." >&2
  109. else
  110. sum1=\`MS_dd "\$1" \$offset \$s | CMD_ENV=xpg4 cksum | awk '{print \$1}'\`
  111. if test "\$sum1" = "\$crc"; then
  112. test x\$verb = xy && MS_Printf " CRC checksums are OK." >&2
  113. else
  114. echo "Error in checksums: \$sum1 is different from \$crc"
  115. exit 2;
  116. fi
  117. fi
  118. i=\`expr \$i + 1\`
  119. offset=\`expr \$offset + \$s\`
  120. done
  121. echo " All good."
  122. }
  123. UnTAR()
  124. {
  125. tar \$1vf - 2>&1 || { echo Extraction failed. > /dev/tty; kill -15 \$$; }
  126. }
  127. finish=true
  128. xterm_loop=
  129. nox11=$NOX11
  130. copy=$COPY
  131. ownership=y
  132. verbose=n
  133. initargs="\$@"
  134. while true
  135. do
  136. case "\$1" in
  137. -h | --help)
  138. MS_Help
  139. exit 0
  140. ;;
  141. --info)
  142. echo Identification: "\$label"
  143. echo Target directory: "\$targetdir"
  144. echo Uncompressed size: $USIZE KB
  145. echo Compression: $COMPRESS
  146. echo Date of packaging: $DATE
  147. echo Built with Makeself version $MS_VERSION on $OSTYPE
  148. echo Build command was: "$MS_COMMAND"
  149. if test x\$script != x; then
  150. echo Script run after extraction:
  151. echo " " \$script \$scriptargs
  152. fi
  153. if test x"$copy" = xcopy; then
  154. echo "Archive will copy itself to a temporary location"
  155. fi
  156. if test x"$KEEP" = xy; then
  157. echo "directory \$targetdir is permanent"
  158. else
  159. echo "\$targetdir will be removed after extraction"
  160. fi
  161. exit 0
  162. ;;
  163. --dumpconf)
  164. echo LABEL=\"\$label\"
  165. echo SCRIPT=\"\$script\"
  166. echo SCRIPTARGS=\"\$scriptargs\"
  167. echo archdirname=\"$archdirname\"
  168. echo KEEP=$KEEP
  169. echo COMPRESS=$COMPRESS
  170. echo filesizes=\"\$filesizes\"
  171. echo CRCsum=\"\$CRCsum\"
  172. echo MD5sum=\"\$MD5\"
  173. echo OLDUSIZE=$USIZE
  174. echo OLDSKIP=`expr $SKIP + 1`
  175. exit 0
  176. ;;
  177. --lsm)
  178. cat << EOLSM
  179. EOF
  180. eval "$LSM_CMD"
  181. cat << EOF >> "$archname"
  182. EOLSM
  183. exit 0
  184. ;;
  185. --list)
  186. echo Target directory: \$targetdir
  187. offset=\`head -n $SKIP "\$0" | wc -c | tr -d " "\`
  188. for s in \$filesizes
  189. do
  190. MS_dd "\$0" \$offset \$s | eval "$GUNZIP_CMD" | UnTAR t
  191. offset=\`expr \$offset + \$s\`
  192. done
  193. exit 0
  194. ;;
  195. --tar)
  196. offset=\`head -n $SKIP "\$0" | wc -c | tr -d " "\`
  197. arg1="\$2"
  198. shift 2
  199. for s in \$filesizes
  200. do
  201. MS_dd "\$0" \$offset \$s | eval "$GUNZIP_CMD" | tar "\$arg1" - \$*
  202. offset=\`expr \$offset + \$s\`
  203. done
  204. exit 0
  205. ;;
  206. --check)
  207. MS_Check "\$0" y
  208. exit 0
  209. ;;
  210. --confirm)
  211. verbose=y
  212. shift
  213. ;;
  214. --noexec)
  215. script=""
  216. shift
  217. ;;
  218. --keep)
  219. keep=y
  220. shift
  221. ;;
  222. --target)
  223. keep=y
  224. targetdir=\${2:-.}
  225. shift 2
  226. ;;
  227. --nox11)
  228. nox11=y
  229. shift
  230. ;;
  231. --nochown)
  232. ownership=n
  233. shift
  234. ;;
  235. --xwin)
  236. finish="echo Press Return to close this window...; read junk"
  237. xterm_loop=1
  238. shift
  239. ;;
  240. --phase2)
  241. copy=phase2
  242. shift
  243. ;;
  244. --)
  245. shift
  246. break ;;
  247. -*)
  248. echo Unrecognized flag : "\$1" >&2
  249. MS_Help
  250. exit 1
  251. ;;
  252. *)
  253. break ;;
  254. esac
  255. done
  256. case "\$copy" in
  257. copy)
  258. tmpdir=\$TMPROOT/makeself.\$RANDOM.\`date +"%y%m%d%H%M%S"\`.\$\$
  259. mkdir "\$tmpdir" || {
  260. echo "Could not create temporary directory \$tmpdir" >&2
  261. exit 1
  262. }
  263. SCRIPT_COPY="\$tmpdir/makeself"
  264. echo "Copying to a temporary location..." >&2
  265. cp "\$0" "\$SCRIPT_COPY"
  266. chmod +x "\$SCRIPT_COPY"
  267. cd "\$TMPROOT"
  268. exec "\$SCRIPT_COPY" --phase2 -- \$initargs
  269. ;;
  270. phase2)
  271. finish="\$finish ; rm -rf \`dirname \$0\`"
  272. ;;
  273. esac
  274. if test "\$nox11" = "n"; then
  275. if tty -s; then # Do we have a terminal?
  276. :
  277. else
  278. if test x"\$DISPLAY" != x -a x"\$xterm_loop" = x; then # No, but do we have X?
  279. if xset q > /dev/null 2>&1; then # Check for valid DISPLAY variable
  280. GUESS_XTERMS="xterm rxvt dtterm eterm Eterm kvt konsole aterm"
  281. for a in \$GUESS_XTERMS; do
  282. if type \$a >/dev/null 2>&1; then
  283. XTERM=\$a
  284. break
  285. fi
  286. done
  287. chmod a+x \$0 || echo Please add execution rights on \$0
  288. if test \`echo "\$0" | cut -c1\` = "/"; then # Spawn a terminal!
  289. exec \$XTERM -title "\$label" -e "\$0" --xwin "\$initargs"
  290. else
  291. exec \$XTERM -title "\$label" -e "./\$0" --xwin "\$initargs"
  292. fi
  293. fi
  294. fi
  295. fi
  296. fi
  297. if test "\$targetdir" = "."; then
  298. tmpdir="."
  299. else
  300. if test "\$keep" = y; then
  301. echo "Creating directory \$targetdir" >&2
  302. tmpdir="\$targetdir"
  303. dashp="-p"
  304. else
  305. tmpdir="\$TMPROOT/selfgz\$\$\$RANDOM"
  306. dashp=""
  307. fi
  308. mkdir \$dashp \$tmpdir || {
  309. echo 'Cannot create target directory' \$tmpdir >&2
  310. echo 'You should try option --target OtherDirectory' >&2
  311. eval \$finish
  312. exit 1
  313. }
  314. fi
  315. location="\`pwd\`"
  316. if test x\$SETUP_NOCHECK != x1; then
  317. MS_Check "\$0"
  318. fi
  319. offset=\`head -n $SKIP "\$0" | wc -c | tr -d " "\`
  320. if test x"\$verbose" = xy; then
  321. MS_Printf "About to extract $USIZE KB in \$tmpdir ... Proceed ? [Y/n] "
  322. read yn
  323. if test x"\$yn" = xn; then
  324. eval \$finish; exit 1
  325. fi
  326. fi
  327. MS_Printf "Uncompressing \$label"
  328. res=3
  329. if test "\$keep" = n; then
  330. trap 'echo Signal caught, cleaning up >&2; cd \$TMPROOT; /bin/rm -rf \$tmpdir; eval \$finish; exit 15' 1 2 3 15
  331. fi
  332. leftspace=\`MS_diskspace \$tmpdir\`
  333. if test \$leftspace -lt $USIZE; then
  334. echo
  335. echo "Not enough space left in "\`dirname \$tmpdir\`" (\$leftspace KB) to decompress \$0 ($USIZE KB)" >&2
  336. if test "\$keep" = n; then
  337. echo "Consider setting TMPDIR to a directory with more free space."
  338. fi
  339. eval \$finish; exit 1
  340. fi
  341. for s in \$filesizes
  342. do
  343. if MS_dd "\$0" \$offset \$s | eval "$GUNZIP_CMD" | ( cd "\$tmpdir"; UnTAR x ) | MS_Progress; then
  344. if test x"\$ownership" = xy; then
  345. (PATH=/usr/xpg4/bin:\$PATH; cd "\$tmpdir"; chown -R \`id -u\` .; chgrp -R \`id -g\` .)
  346. fi
  347. else
  348. echo
  349. echo "Unable to decompress \$0" >&2
  350. eval \$finish; exit 1
  351. fi
  352. offset=\`expr \$offset + \$s\`
  353. done
  354. echo
  355. cd "\$tmpdir"
  356. res=0
  357. if test x"\$script" != x; then
  358. if test x"\$verbose" = xy; then
  359. MS_Printf "OK to execute: \$script \$scriptargs \$* ? [Y/n] "
  360. read yn
  361. if test x"\$yn" = x -o x"\$yn" = xy -o x"\$yn" = xY; then
  362. eval \$script \$scriptargs \$*; res=\$?;
  363. fi
  364. else
  365. eval \$script \$scriptargs \$*; res=\$?
  366. fi
  367. if test \$res -ne 0; then
  368. test x"\$verbose" = xy && echo "The program '\$script' returned an error code (\$res)" >&2
  369. fi
  370. fi
  371. if test "\$keep" = n; then
  372. cd \$TMPROOT
  373. /bin/rm -rf \$tmpdir
  374. fi
  375. eval \$finish; exit \$res
  376. EOF