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