openpkg/etc.wrapsrc.sh

Mon, 28 Jan 2013 17:37:18 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 28 Jan 2013 17:37:18 +0100
changeset 758
a2c6460cfb16
parent 445
43a74e63d4a3
permissions
-rw-r--r--

Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.

michael@428 1 #!/bin/sh
michael@428 2 #![OpenPKG]
michael@428 3 ##
michael@428 4 ## OpenPKG Source Bootstrap Package (self-extracting shell script)
michael@428 5 ## Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/>
michael@428 6 ##
michael@428 7 ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
michael@428 8 ## All rights reserved. Licenses which grant limited permission to use,
michael@428 9 ## copy, modify and distribute this software are available from the
michael@428 10 ## OpenPKG GmbH.
michael@428 11 ##
michael@428 12 ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
michael@428 13 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@428 14 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@428 15 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
michael@428 16 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@428 17 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@428 18 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
michael@428 19 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
michael@428 20 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@428 21 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
michael@428 22 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@428 23 ## SUCH DAMAGE.
michael@428 24 ##
michael@428 25
michael@428 26 # configuration
michael@428 27 l_me="$0"
michael@428 28 o_help=no
michael@428 29 o_version=no
michael@428 30 o_tar=no
michael@428 31 l_prefix='/openpkg'
michael@428 32 l_dir='@l_dir@'
michael@428 33 l_release="@l_release@"
michael@428 34 l_version="@l_version@"
michael@428 35
michael@428 36 # establish standard environment
michael@428 37 PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin"
michael@428 38 LC_CTYPE=C
michael@428 39 export LC_CTYPE
michael@428 40 umask 022
michael@428 41
michael@445 42 # preparse command line options
michael@428 43 for opt
michael@428 44 do
michael@428 45 case $opt in
michael@428 46 -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
michael@428 47 *) arg='' ;;
michael@428 48 esac
michael@428 49 case $opt in
michael@428 50 -h | --help ) o_help=yes ;;
michael@428 51 -v | --version ) o_version=yes ;;
michael@428 52 -t | --tar ) o_tar=yes ;;
michael@428 53 --prefix=* ) l_prefix=$arg ;;
michael@428 54 esac
michael@428 55 done
michael@428 56 if [ ".$o_help" = .yes ]; then
michael@428 57 echo "Usage: sh $l_me" 2>&1
michael@428 58 echo " [--prefix=<prefix>] [--tag=<str>]" 2>&1
michael@428 59 echo " [--stack=<name-or-url>] [--unprivileged]" 2>&1
michael@428 60 echo " [--user=<usr>] [--group=<grp>]" 2>&1
michael@428 61 echo " [--{s,m,r,n}usr=<usr>] [--{s,m,r,n}grp=<grp>]" 2>&1
michael@428 62 echo " [--{s,m,r,n}uid=<uid>] [--{s,m,r,n}gid=<gid>]" 2>&1
michael@428 63 echo " [--use_tar=<tar>] [--use_make=<make>] [--use_cc=<cc>]" 2>&1
michael@428 64 echo " [--use_ar=<ar>] [--use_ld=<ld>] [--use_as=<as>] [--use_strip=<strip>]" 2>&1
michael@428 65 echo " [-t|--tar] [-h|--help] [-v|--version]" 2>&1
michael@428 66 exit 1
michael@428 67 fi
michael@428 68
michael@428 69 # make sure all essential unpacking tools are available
michael@428 70 # (the build tools are checked later from within openpkg.spec)
michael@428 71 for tool in /bin/sh mkdir cat tar rm chown chgrp sed dd; do
michael@428 72 found=no
michael@428 73 case $tool in
michael@428 74 /* )
michael@428 75 if [ -f $tool ]; then
michael@428 76 found=yes
michael@428 77 fi
michael@428 78 ;;
michael@428 79 * )
michael@428 80 for p in `IFS=:; echo $PATH`; do
michael@428 81 if [ -f "$p/$tool" ]; then
michael@428 82 found=yes
michael@428 83 break
michael@428 84 fi
michael@428 85 done
michael@428 86 ;;
michael@428 87 esac
michael@428 88 if [ ".$found" = .no ]; then
michael@428 89 echo "$l_me:ERROR: unable to find bootstrap tool \"$tool\"" 1>&2
michael@428 90 exit 1
michael@428 91 fi
michael@428 92 done
michael@428 93
michael@428 94 # optionally extract the embedded tarball only
michael@428 95 if [ ".$o_tar" = .yes ]; then
michael@450 96 dd if=$l_me bs=8192 skip=10 2>/dev/null
michael@428 97 exit 0
michael@428 98 fi
michael@428 99
michael@428 100 # display version and copyright header
michael@428 101 echo "OpenPKG ${l_release} Source Bootstrap Package, version ${l_version}"
michael@428 102 if [ ".$o_version" = .yes ]; then
michael@428 103 exit 0
michael@428 104 fi
michael@428 105 echo "Building for prefix ${l_prefix} on current platform"
michael@428 106
michael@428 107 # determine current user/group
michael@428 108 cusr=`(id -un) 2>/dev/null ||\
michael@428 109 (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
michael@428 110 (whoami) 2>/dev/null ||\
michael@428 111 (who am i | cut "-d " -f1) 2>/dev/null ||\
michael@428 112 echo $LOGNAME`
michael@428 113 cgid=`(id -g $cusr) 2>/dev/null ||\
michael@428 114 ((getent passwd "${cusr}"; grep "^${cusr}:" /etc/passwd; ypmatch "${cusr}" passwd; nismatch "${cusr}" passwd; nidump passwd . | grep "^${cusr}:") 2>/dev/null |\
michael@428 115 sed -e 'q' | awk -F: '{ print $4; }')`
michael@428 116 cgrp=`(id -gn $cusr) 2>/dev/null ||\
michael@428 117 ((getent group; cat /etc/group; ypcat group; niscat group; nidump group .) 2>/dev/null | grep "^[^:]*:[^:]*:${cgid}:" |\
michael@428 118 sed -e 'q' | awk -F: '{ print $1; }')`
michael@428 119 if [ ".$cgrp" = . ]; then
michael@428 120 cgrp="$cusr"
michael@428 121 fi
michael@428 122
michael@428 123 # extract the source distribution files
michael@428 124 echo "++ extracting OpenPKG source distribution"
michael@428 125 rm -rf $l_dir >/dev/null 2>&1
michael@428 126 mkdir $l_dir || exit 1
michael@450 127 dd if=$l_me bs=8192 skip=10 2>/dev/null | (cd $l_dir; tar xf - 2>/dev/null)
michael@428 128 if [ ".$cusr" = .root ]; then
michael@428 129 ( cd $l_dir || exit 1
michael@428 130 chown -R -h $cusr . >/dev/null 2>&1 || true
michael@428 131 chgrp -R -h $cgrp . >/dev/null 2>&1 || true
michael@428 132 ) || exit 1
michael@428 133 fi
michael@428 134 if [ ! -f $l_dir/openpkg.boot ]; then
michael@428 135 echo "$l_me:ERROR: failed to unpack into directory \"$l_dir\"" 1>&2
michael@428 136 exit 1
michael@428 137 fi
michael@428 138
michael@428 139 # perform bootstrap procedure
michael@428 140 echo "++ building OpenPKG binary distribution"
michael@428 141 ( cd $l_dir || exit 1
michael@428 142 sh ./openpkg.boot ${1+"$@"} || exit 1
michael@428 143 ) || exit 1
michael@428 144
michael@428 145 # cleanup
michael@428 146 rm -rf $l_dir >/dev/null 2>&1
michael@428 147
michael@428 148 # die explicitly just before the shell would discover
michael@445 149 # that we carry megabytes of data with us...
michael@428 150 exit 0
michael@428 151
michael@428 152 # the distribution tarball is appended in raw format directly to the
michael@428 153 # end of this script, just leaded by padding whitespaces which make
michael@450 154 # sure that the tarball data starts at the predefined offset of 80KB.
michael@428 155 # This allows us to unpack the tarball by just skipping the leading
michael@450 156 # 80KB (= 8192*10, see above).
michael@428 157

mercurial