| |
1 #!/bin/sh |
| |
2 ## |
| |
3 ## OpenPKG Source Bootstrap Package (self-extracting shell script) |
| |
4 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/> |
| |
5 ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/> |
| |
6 ## |
| |
7 ## Permission to use, copy, modify, and distribute this software for |
| |
8 ## any purpose with or without fee is hereby granted, provided that |
| |
9 ## the above copyright notice and this permission notice appear in all |
| |
10 ## copies. |
| |
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 ## |
| |
25 |
| |
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@" |
| |
35 |
| |
36 # establish standard environment |
| |
37 PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin" |
| |
38 LC_CTYPE=C |
| |
39 export LC_CTYPE |
| |
40 umask 022 |
| |
41 |
| |
42 # pre-parse 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 " [--user=<usr>] [--group=<grp>]" 2>&1 |
| |
60 echo " [--{s,m,r,n}usr=<usr>] [--{s,m,r,n}grp=<grp>]" 2>&1 |
| |
61 echo " [--{s,m,r,n}uid=<uid>] [--{s,m,r,n}gid=<gid>]" 2>&1 |
| |
62 echo " [--use_tar=<tar>] [--use_make=<make>] [--use_cc=<cc>]" 2>&1 |
| |
63 echo " [--use_ar=<ar>] [--use_ld=<ld>] [--use_as=<as>] [--use_strip=<strip>]" 2>&1 |
| |
64 echo " [-t|--tar] [-h|--help] [-v|--version]" 2>&1 |
| |
65 exit 1 |
| |
66 fi |
| |
67 |
| |
68 # make sure all essential unpacking tools are available |
| |
69 # (the build tools are checked later from within openpkg.spec) |
| |
70 for tool in /bin/sh mkdir cat tar rm chown chgrp sed dd; do |
| |
71 found=no |
| |
72 case $tool in |
| |
73 /* ) |
| |
74 if [ -f $tool ]; then |
| |
75 found=yes |
| |
76 fi |
| |
77 ;; |
| |
78 * ) |
| |
79 for p in `IFS=:; echo $PATH`; do |
| |
80 if [ -f "$p/$tool" ]; then |
| |
81 found=yes |
| |
82 break |
| |
83 fi |
| |
84 done |
| |
85 ;; |
| |
86 esac |
| |
87 if [ ".$found" = .no ]; then |
| |
88 echo "$l_me:ERROR: unable to find bootstrap tool \"$tool\"" 1>&2 |
| |
89 exit 1 |
| |
90 fi |
| |
91 done |
| |
92 |
| |
93 # optionally extract the embedded tarball only |
| |
94 if [ ".$o_tar" = .yes ]; then |
| |
95 dd if=$l_me bs=8192 skip=8 2>/dev/null |
| |
96 exit 0 |
| |
97 fi |
| |
98 |
| |
99 # display version and copyright header |
| |
100 echo "OpenPKG ${l_release} Source Bootstrap Package, version ${l_version}" |
| |
101 if [ ".$o_version" = .yes ]; then |
| |
102 exit 0 |
| |
103 fi |
| |
104 echo "Building for prefix ${l_prefix} on current platform" |
| |
105 |
| |
106 # determine current user/group |
| |
107 cusr=`(id -un) 2>/dev/null ||\ |
| |
108 (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\ |
| |
109 (whoami) 2>/dev/null ||\ |
| |
110 (who am i | cut "-d " -f1) 2>/dev/null ||\ |
| |
111 echo $LOGNAME` |
| |
112 cgid=`(id -g $cusr) 2>/dev/null ||\ |
| |
113 ((getent passwd "${cusr}"; grep "^${cusr}:" /etc/passwd; ypmatch "${cusr}" passwd; nismatch "${cusr}" passwd; nidump passwd . | grep "^${cusr}:") 2>/dev/null |\ |
| |
114 sed -e 'q' | awk -F: '{ print $4; }')` |
| |
115 cgrp=`(id -gn $cusr) 2>/dev/null ||\ |
| |
116 ((getent group; cat /etc/group; ypcat group; niscat group; nidump group .) 2>/dev/null | grep "^[^:]*:[^:]*:${cgid}:" |\ |
| |
117 sed -e 'q' | awk -F: '{ print $1; }')` |
| |
118 if [ ".$cgrp" = . ]; then |
| |
119 cgrp="$cusr" |
| |
120 fi |
| |
121 |
| |
122 # extract the source distribution files |
| |
123 echo "++ extracting OpenPKG source distribution" |
| |
124 rm -rf $l_dir >/dev/null 2>&1 |
| |
125 mkdir $l_dir || exit 1 |
| |
126 dd if=$l_me bs=8192 skip=8 2>/dev/null | (cd $l_dir; tar xf - 2>/dev/null) |
| |
127 if [ ".$cusr" = .root ]; then |
| |
128 ( cd $l_dir || exit 1 |
| |
129 chown -R -h $cusr . >/dev/null 2>&1 || true |
| |
130 chgrp -R -h $cgrp . >/dev/null 2>&1 || true |
| |
131 ) || exit 1 |
| |
132 fi |
| |
133 if [ ! -f $l_dir/openpkg.boot ]; then |
| |
134 echo "$l_me:ERROR: failed to unpack into directory \"$l_dir\"" 1>&2 |
| |
135 exit 1 |
| |
136 fi |
| |
137 |
| |
138 # perform bootstrap procedure |
| |
139 echo "++ building OpenPKG binary distribution" |
| |
140 ( cd $l_dir || exit 1 |
| |
141 ./openpkg.boot ${1+"$@"} || exit 1 |
| |
142 ) || exit 1 |
| |
143 |
| |
144 # cleanup |
| |
145 rm -rf $l_dir >/dev/null 2>&1 |
| |
146 |
| |
147 # die explicitly just before the shell would discover |
| |
148 # that we carry mega-bytes of data with us... |
| |
149 exit 0 |
| |
150 |
| |
151 # the distribution tarball is appended in raw format directly to the |
| |
152 # end of this script, just leaded by padding whitespaces which make |
| |
153 # sure that the tarball data starts at the pre-defined offset of 64KB. |
| |
154 # This allows us to unpack the tarball by just skipping the leading |
| |
155 # 64KB (= 8192*8, see above). |
| |
156 |