source: trunk/scripts/makeself/makeself-header.sh@ 372

Last change on this file since 372 was 1, checked in by katerina, 19 years ago

Initial import

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