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