- 论坛徽章:
- 0
|
5可用积分
有谁知道shell脚本中如何嵌入二进制数据?以前有人在论坛里问过,但没有人给出确切的答案,在网上搜索也没有结果,有没有高人指点迷津?
下面的脚本已经去掉了后面紧跟着的二进制数据。
#! /bin/sh
skip=222
# This script was generated using Makeself 1.5.5
CRCsum=3603969685
MD5=00000000000000000000000000000000
label="CrossOver Linux Professional"
script=./setup.sh
targetdir=cxoffice
scriptargs=""
keep=n
TMPROOT=${TMPDIR:=/tmp}
finish=true
xterm_loop=""
# Shells really don't like CR/LFs. So use some CR/LF-resistant
# code to perform a quick sanity check.
crlf_sentry=
if [ -n "$crlf_sentry" ]; then #
echo "Line ends have been converted to CR/LF." #
echo #
echo "You need to download the installer again, as this one" #
echo "has been corrupted." #
echo #
echo "If your download appeared to be successful, try a different" #
echo "browser. Some browsers, such as Netscape, are known to corrupt" #
echo "some types of binary files by trying treating them as text." #
echo #
exit 2 #
fi #
LOKISCRIPTPATH=`which $0 2>/dev/null`
if [ ! -f "$LOKISCRIPTPATH" ]; then
LOKISCRIPTPATH=$0
fi
echo $LOKISCRIPTPATH | egrep "^/" >/dev/null
rc=$?
if [ $rc -ne 0 -a -f "$LOKISCRIPTPATH" -a -f "`pwd`/$LOKISCRIPTPATH" ]; then
LOKISCRIPTPATH="`pwd`/$LOKISCRIPTPATH"
fi
export LOKISCRIPTPATH
if tail -n 1 /dev/null >/dev/null 2>&1
then
TAIL_CMD="tail -n"
else
TAIL_CMD="tail"
fi
[ x"$1" = x-xwin ] && {
finish="echo Press Return to close this window...; read junk"; xterm_loop=1; shift 1;
}
if [ x"$1" = "x-help" -o x"$1" = "x--help" ]; then
cat << tac
1) Getting help or info about $0 :
$0 --help Print this message
$0 --info Print embedded info : title, default target directory, embedded script ...
$0 --lsm Print embedded lsm entry (or no LSM)
$0 --list Print the list of files in the archive
$0 --check Checks integrity of the archive
2) Running $0 :
$0 [options] [additional arguments to embedded script]
with following options (in that order)
--confirm Ask before running embedded script
--keep Do not erase target directory after running embedded script
--target NewDirectory Extract in NewDirectory
tac
exit 0;
fi
if [ x"$1" = "x-lsm" -o x"$1" = "x--lsm" ]; then
cat << EOF_LSM
no LSM
EOF_LSM
exit 0;
fi
if [ "$1" = "--info" ]; then
echo Identification: $label
echo Target directory: $targetdir
echo Uncompressed size: 63244 KB
echo Compression: gzip
echo Date of packaging: Fri Jan 5 12:24:05 CST 2007
echo script run after extraction: $script $scriptargs
[ x"$keep" = xy ] && echo "directory $targetdir is permanent" || echo "$targetdir will be removed after extraction"
exit 0;
fi
if [ "$1" = "--list" ]; then
echo Target directory: $targetdir
$TAIL_CMD +$skip "$0" | gzip -cd | tar tvf -
exit 0;
fi
if [ "$1" = "--check" ]; then
sum1=`$TAIL_CMD +6 "$0" | cksum | sed -e 's/ /Z/' -e 's/ /Z/' | cut -dZ -f1`
[ "$sum1" != "$CRCsum" ] && {
echo "Error in checksums $sum1 != $CRCsum"
exit 2;
}
if [ $MD5 != "00000000000000000000000000000000" ]; then
# space separated list of directories
[ x"$GUESS_MD5_PATH" = "x" ] && GUESS_MD5_PATH="/usr/local/ssl/bin"
MD5_PATH=""
for a in $GUESS_MD5_PATH; do
if which $a/md5 >/dev/null 2>&1 ; then
MD5_PATH=$a;
fi
done
if [ -x $MD5_PATH/md5 ]; then
md5sum=`$TAIL_CMD +6 "$0" | $MD5_PATH/md5`;
[ $md5sum != $MD5 ] && {
echo Error in md5 sums $md5sum $MD5
exit 2
} || { echo check sums and md5 sums are ok; exit 0; }
fi
if [ ! -x $MD5_PATH/md5 ]; then
echo an embedded md5 sum of the archive exists but no md5 program was found in $GUESS_MD5_PATH
echo if you have md5 on your system, you should try :
echo env GUESS_MD5_PATH=\"FirstDirectory SecondDirectory ...\" $0 -check
fi
else
echo check sums are OK ; echo $0 does not contain embedded md5 sum ;
fi
exit 0;
fi
[ x"$finish" = x ] && finish=true
parsing=yes
x11=y
while [ x"$parsing" != x ]; do
case "$1" in
-confirm|--confirm) verbose=y; shift;;
-keep|--keep) keep=y; shift;;
-nox11|--nox11) x11=n; shift;;
-target|--target) if [ x"$2" != x ]; then targetdir="$2"; keep=y; shift 2; fi;;
*) parsing="";;
esac
done
mask=`umask`
umask 077
if [ x"$keep" = xy ]; then echo "Creating directory $targetdir"; tmpdir=$targetdir;
else tmpdir="$TMPROOT/selfgz$$"; fi
mkdir $tmpdir || {
echo 'Cannot create target directory' $tmpdir >&2
echo 'you should perhaps try option -target OtherDirectory' >&2
eval $finish; exit 1;
}
# Create a wrapper script which can be exec'd so we don't lock the CD
wrapperbase=`basename "$LOKISCRIPTPATH"`-wrapper
wrapperpath="$tmpdir/$wrapperbase"
echo '#!/bin/sh' >"$wrapperpath"
[ x"$keep" = xy ] || echo "trap 'echo Signal caught, cleaning up > /dev/tty; cd \"$TMPROOT\"; /bin/rm -rf \"$tmpdir\"; exit 15' 1 2 15" >>"$wrapperpath"
echo "$script $scriptargs $*" >>"$wrapperpath"
echo "cd $TMPROOT" >>"$wrapperpath"
if [ x"$keep" = xy ] ; then
echo "exec rm -f \"$wrapperpath\"" >>"$wrapperpath"
else
echo "exec rm -rf \"$tmpdir\"" >>"$wrapperpath"
fi
chmod +rx "$wrapperpath"
umask $mask
location="`pwd`"
if [ -x /usr/bin/printf ]
then
echo_n=/usr/bin/printf
elif [ -x /usr/ucb/echo ]
then
echo_n="/usr/ucb/echo -n"
else
echo_n="echo -n"
fi
if [ x$SETUP_NOCHECK != x1 ]; then
$echo_n "Verifying archive integrity..."
sum1=`$TAIL_CMD +6 "$0" | cksum | sed -e 's/ /Z/' -e 's/ /Z/' | cut -dZ -f1`
[ "$sum1" != "$CRCsum" ] && {
echo "Error in check sums $sum1 != $CRCsum"
echo
echo "You need to download the installer again, as it is corrupt."
echo
echo "If your download appeared to be successful, try a different"
echo "browser. Some browsers, such as Netscape, are known to corrupt"
echo "some types of binary files by trying treating them as text."
echo
eval $finish; exit 2;
}
echo OK
fi
if [ $MD5 != "00000000000000000000000000000000" ]; then
# space separated list of directories
[ x$GUESS_MD5_PATH = x ] && GUESS_MD5_PATH="/usr/local/ssl/bin"
MD5_PATH=""
for a in $GUESS_MD5_PATH; do
if which $a/md5 >/dev/null 2>&1 ; then
MD5_PATH=$a;
fi
done
if [ -x $MD5_PATH/md5 ]; then
md5sum=`$TAIL_CMD +6 "$0" | $MD5_PATH/md5`;
[ $md5sum != $MD5 ] && {
echo "Error in md5 sums $md5sum $MD5"
eval $finish; exit 2;
}
fi
fi
UnTAR() { tar xvf - || { echo Extraction failed. > /dev/tty; kill -15 $$; } ; }
echo "Uncompressing $label"
cd $tmpdir ; res=3
[ "$keep" = y ] || trap 'echo Signal caught, cleaning up > /dev/tty; cd $TMPROOT; /bin/rm -rf $tmpdir; eval $finish; exit 15' 1 2 15
if (cd "$location"; $TAIL_CMD +$skip "$0"; ) | gzip -cd | UnTAR | (while read a; do $echo_n .; done; echo; ); then
uid=`id | sed -e 's/^uid=\([0-9]*\)(.*/\1/'`
gid=`id | sed -e 's/^.* gid=\([0-9]*\)(.*/\1/'`
chown -Rf $uidgid .
res=0; if [ x"$script" != x ]; then
if [ x"$verbose" = xy ]; then
echo "OK to execute: $script $scriptargs $* ? [Y/n] "
read yn
[ x"$yn" = x -o x"$yn" = xy -o x"$yn" = xY ] && { exec "./$wrapperbase"; res=$?; }
else
exec "./$wrapperbase" ; res=$?
fi
#[ $res != 0 ] && echo "The program returned an error code ($res)"
fi
[ "$keep" = y ] || { cd $TMPROOT; /bin/rm -rf $tmpdir; }
else
echo "Cannot decompress $0"; eval $finish; exit 1
fi
eval $finish; exit $res
END_OF_STUB |
最佳答案
查看完整内容
分割线是就是准备让你分割数据时用的,如果你不用这条线怎么分割?
|