openpkg/etc.wrapsrc.sh

changeset 428
f880f219c566
child 445
43a74e63d4a3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/openpkg/etc.wrapsrc.sh	Tue Jul 31 12:23:42 2012 +0200
     1.3 @@ -0,0 +1,157 @@
     1.4 +#!/bin/sh
     1.5 +#![OpenPKG]
     1.6 +##
     1.7 +##  OpenPKG Source Bootstrap Package (self-extracting shell script)
     1.8 +##  Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/>
     1.9 +##
    1.10 +##  This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
    1.11 +##  All rights reserved. Licenses which grant limited permission to use,
    1.12 +##  copy, modify and distribute this software are available from the
    1.13 +##  OpenPKG GmbH.
    1.14 +##
    1.15 +##  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
    1.16 +##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    1.17 +##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    1.18 +##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
    1.19 +##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.20 +##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.21 +##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    1.22 +##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.23 +##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.24 +##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    1.25 +##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.26 +##  SUCH DAMAGE.
    1.27 +##
    1.28 +
    1.29 +#   configuration
    1.30 +l_me="$0"
    1.31 +o_help=no
    1.32 +o_version=no
    1.33 +o_tar=no
    1.34 +l_prefix='/openpkg'
    1.35 +l_dir='@l_dir@'
    1.36 +l_release="@l_release@"
    1.37 +l_version="@l_version@"
    1.38 +
    1.39 +#   establish standard environment
    1.40 +PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin"
    1.41 +LC_CTYPE=C
    1.42 +export LC_CTYPE
    1.43 +umask 022
    1.44 +
    1.45 +#   pre-parse command line options
    1.46 +for opt
    1.47 +do
    1.48 +    case $opt in
    1.49 +        -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
    1.50 +           *) arg='' ;;
    1.51 +    esac
    1.52 +    case $opt in
    1.53 +        -h | --help     ) o_help=yes    ;;
    1.54 +        -v | --version  ) o_version=yes ;;
    1.55 +        -t | --tar      ) o_tar=yes     ;;
    1.56 +        --prefix=*      ) l_prefix=$arg ;;
    1.57 +    esac
    1.58 +done
    1.59 +if [ ".$o_help" = .yes ]; then
    1.60 +    echo "Usage: sh $l_me" 2>&1
    1.61 +    echo "       [--prefix=<prefix>] [--tag=<str>]" 2>&1
    1.62 +    echo "       [--stack=<name-or-url>] [--unprivileged]" 2>&1
    1.63 +    echo "       [--user=<usr>] [--group=<grp>]" 2>&1
    1.64 +    echo "       [--{s,m,r,n}usr=<usr>] [--{s,m,r,n}grp=<grp>]" 2>&1
    1.65 +    echo "       [--{s,m,r,n}uid=<uid>] [--{s,m,r,n}gid=<gid>]" 2>&1
    1.66 +    echo "       [--use_tar=<tar>] [--use_make=<make>] [--use_cc=<cc>]" 2>&1
    1.67 +    echo "       [--use_ar=<ar>] [--use_ld=<ld>] [--use_as=<as>] [--use_strip=<strip>]" 2>&1
    1.68 +    echo "       [-t|--tar] [-h|--help] [-v|--version]" 2>&1
    1.69 +    exit 1
    1.70 +fi
    1.71 +
    1.72 +#   make sure all essential unpacking tools are available
    1.73 +#   (the build tools are checked later from within openpkg.spec)
    1.74 +for tool in /bin/sh mkdir cat tar rm chown chgrp sed dd; do
    1.75 +    found=no
    1.76 +    case $tool in
    1.77 +        /* )
    1.78 +            if [ -f $tool ]; then
    1.79 +                found=yes
    1.80 +            fi
    1.81 +            ;;
    1.82 +        * )
    1.83 +            for p in `IFS=:; echo $PATH`; do
    1.84 +                if [ -f "$p/$tool" ]; then
    1.85 +                    found=yes
    1.86 +                    break
    1.87 +                fi
    1.88 +            done
    1.89 +            ;;
    1.90 +    esac
    1.91 +    if [ ".$found" = .no ]; then
    1.92 +        echo "$l_me:ERROR: unable to find bootstrap tool \"$tool\"" 1>&2
    1.93 +        exit 1
    1.94 +    fi
    1.95 +done
    1.96 +
    1.97 +#   optionally extract the embedded tarball only
    1.98 +if [ ".$o_tar" = .yes ]; then
    1.99 +    dd if=$l_me bs=8192 skip=8 2>/dev/null
   1.100 +    exit 0
   1.101 +fi
   1.102 +
   1.103 +#   display version and copyright header
   1.104 +echo "OpenPKG ${l_release} Source Bootstrap Package, version ${l_version}"
   1.105 +if [ ".$o_version" = .yes ]; then
   1.106 +    exit 0
   1.107 +fi
   1.108 +echo "Building for prefix ${l_prefix} on current platform"
   1.109 +
   1.110 +#   determine current user/group
   1.111 +cusr=`(id -un) 2>/dev/null ||\
   1.112 +      (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
   1.113 +      (whoami) 2>/dev/null ||\
   1.114 +      (who am i | cut "-d " -f1) 2>/dev/null ||\
   1.115 +      echo $LOGNAME`
   1.116 +cgid=`(id -g $cusr) 2>/dev/null ||\
   1.117 +      ((getent passwd "${cusr}"; grep "^${cusr}:" /etc/passwd; ypmatch "${cusr}" passwd; nismatch "${cusr}" passwd; nidump passwd . | grep "^${cusr}:") 2>/dev/null |\
   1.118 +      sed -e 'q' | awk -F: '{ print $4; }')`
   1.119 +cgrp=`(id -gn $cusr) 2>/dev/null ||\
   1.120 +      ((getent group; cat /etc/group; ypcat group; niscat group; nidump group .) 2>/dev/null | grep "^[^:]*:[^:]*:${cgid}:" |\
   1.121 +      sed -e 'q' | awk -F: '{ print $1; }')`
   1.122 +if [ ".$cgrp" = . ]; then
   1.123 +    cgrp="$cusr"
   1.124 +fi
   1.125 +
   1.126 +#   extract the source distribution files
   1.127 +echo "++ extracting OpenPKG source distribution"
   1.128 +rm -rf $l_dir >/dev/null 2>&1
   1.129 +mkdir $l_dir || exit 1
   1.130 +dd if=$l_me bs=8192 skip=8 2>/dev/null | (cd $l_dir; tar xf - 2>/dev/null)
   1.131 +if [ ".$cusr" = .root ]; then
   1.132 +    ( cd $l_dir || exit 1
   1.133 +      chown -R -h $cusr . >/dev/null 2>&1 || true
   1.134 +      chgrp -R -h $cgrp . >/dev/null 2>&1 || true
   1.135 +    ) || exit 1
   1.136 +fi
   1.137 +if [ ! -f $l_dir/openpkg.boot ]; then
   1.138 +    echo "$l_me:ERROR: failed to unpack into directory \"$l_dir\"" 1>&2
   1.139 +    exit 1
   1.140 +fi
   1.141 +
   1.142 +#   perform bootstrap procedure
   1.143 +echo "++ building OpenPKG binary distribution"
   1.144 +( cd $l_dir || exit 1
   1.145 +  sh ./openpkg.boot ${1+"$@"} || exit 1
   1.146 +) || exit 1
   1.147 +
   1.148 +#   cleanup
   1.149 +rm -rf $l_dir >/dev/null 2>&1
   1.150 +
   1.151 +#   die explicitly just before the shell would discover
   1.152 +#   that we carry mega-bytes of data with us...
   1.153 +exit 0
   1.154 +
   1.155 +#   the distribution tarball is appended in raw format directly to the
   1.156 +#   end of this script, just leaded by padding whitespaces which make
   1.157 +#   sure that the tarball data starts at the pre-defined offset of 64KB.
   1.158 +#   This allows us to unpack the tarball by just skipping the leading
   1.159 +#   64KB (= 8192*8, see above).
   1.160 +

mercurial