self-extract-src.sh
changeset 4 c6c431cf0a89
parent 1 dbce0b16b0c1
equal deleted inserted replaced
3:859eeb3579b2 4:c6c431cf0a89
     6     cmd="./$0"
     6     cmd="./$0"
     7   fi
     7   fi
     8   echo "This script is designed to be run using GNU bash."
     8   echo "This script is designed to be run using GNU bash."
     9   echo "Try: chmod +x $0 && $cmd"
     9   echo "Try: chmod +x $0 && $cmd"
    10   exit 1
    10   exit 1
       
    11 fi
       
    12 
       
    13 # OS X sed (at least leopard and up) seem to support -E
       
    14 sedflags=Ee
       
    15 if ( sed --version 2>&1 | grep 'GNU sed' 2>&1 ) > /dev/null ; then
       
    16 	sedflags=re
    11 fi
    17 fi
    12 
    18 
    13 my_which_real()
    19 my_which_real()
    14 {
    20 {
    15   test -n "$1" || return 1
    21   test -n "$1" || return 1
    71   offset=$((offset + 1))
    77   offset=$((offset + 1))
    72   $cat $0 | $tail -n+$offset
    78   $cat $0 | $tail -n+$offset
    73 }
    79 }
    74 
    80 
    75 # Go through each required command, and make sure it's on the system. If not, fail.
    81 # Go through each required command, and make sure it's on the system. If not, fail.
    76 for cmd in bzip2 tar grep tail cat wc dd md5sum; do
    82 for cmd in bzip2 tar grep tail cat wc dd; do
    77   my_which $cmd>/dev/null || exit 1
    83   my_which $cmd>/dev/null || exit 1
    78   eval $cmd=`my_which $cmd`
    84   eval $cmd=`my_which $cmd`
    79   if test x$? = x1; then
    85   if test x$? = x1; then
    80     exit 1
    86     exit 1
    81   fi
    87   fi
    82 done
    88 done
       
    89 
       
    90 # special case for md5sum
       
    91 if my_which_real md5sum 2>&1 > /dev/null; then
       
    92 	md5sum=`my_which_real md5sum`
       
    93 elif my_which_real openssl 2>&1 > /dev/null; then
       
    94 	md5sum=md5sum
       
    95 	md5sum()
       
    96 	{
       
    97 		local f=${1:--}
       
    98 		cat $f | openssl dgst -md5 | sed -$sedflags 's/^\(stdin\)= //'
       
    99 	}
       
   100 else
       
   101 	echo "Could not find md5sum or openssl"
       
   102 	exit 1
       
   103 fi
    83 
   104 
    84 tempdir=""
   105 tempdir=""
    85 extractonly=0
   106 extractonly=0
    86 while test -n "$1"; do
   107 while test -n "$1"; do
    87   case "$1" in
   108   case "$1" in
    88     -x)
   109     -x)
    89       extractonly=1
   110       extractonly=1
    90       if test -n "$2"; then
   111       if test -n "$2"; then
    91         tempdir=$2
   112         tempdir=$2
    92       else
   113       else
    93         tempdir=`echo $0 | sed -re 's/\.[a-z0-9_-]{1,5}$//'`
   114         tempdir=`echo $0 | sed -$sedflags 's/\.[a-z0-9_-]{1,5}$//'`
    94       fi
   115       fi
    95       ;;
   116       ;;
    96   esac
   117   esac
    97   shift
   118   shift
    98 done
   119 done