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