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