makeself-header.sh 9.1 KB

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