michael@13: #!/bin/sh
michael@13: ##
michael@13: ## OpenPKG Source Bootstrap Package (self-extracting shell script)
michael@13: ## Copyright (c) 2000-2007 OpenPKG Foundation e.V.
michael@13: ## Copyright (c) 2000-2007 Ralf S. Engelschall
michael@13: ##
michael@13: ## Permission to use, copy, modify, and distribute this software for
michael@13: ## any purpose with or without fee is hereby granted, provided that
michael@13: ## the above copyright notice and this permission notice appear in all
michael@13: ## copies.
michael@13: ##
michael@13: ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
michael@13: ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@13: ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@13: ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
michael@13: ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@13: ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@13: ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
michael@13: ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
michael@13: ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@13: ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
michael@13: ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@13: ## SUCH DAMAGE.
michael@13: ##
michael@13:
michael@13: # configuration
michael@13: l_me="$0"
michael@13: o_help=no
michael@13: o_version=no
michael@13: o_tar=no
michael@13: l_prefix='/openpkg'
michael@13: l_dir='@l_dir@'
michael@13: l_release="@l_release@"
michael@13: l_version="@l_version@"
michael@13:
michael@13: # establish standard environment
michael@13: PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin"
michael@13: LC_CTYPE=C
michael@13: export LC_CTYPE
michael@13: umask 022
michael@13:
michael@13: # pre-parse command line options
michael@13: for opt
michael@13: do
michael@13: case $opt in
michael@13: -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
michael@13: *) arg='' ;;
michael@13: esac
michael@13: case $opt in
michael@13: -h | --help ) o_help=yes ;;
michael@13: -v | --version ) o_version=yes ;;
michael@13: -t | --tar ) o_tar=yes ;;
michael@13: --prefix=* ) l_prefix=$arg ;;
michael@13: esac
michael@13: done
michael@13: if [ ".$o_help" = .yes ]; then
michael@13: echo "Usage: sh $l_me" 2>&1
michael@13: echo " [--prefix=] [--tag=]" 2>&1
michael@13: echo " [--user=] [--group=]" 2>&1
michael@13: echo " [--{s,m,r,n}usr=] [--{s,m,r,n}grp=]" 2>&1
michael@13: echo " [--{s,m,r,n}uid=] [--{s,m,r,n}gid=]" 2>&1
michael@13: echo " [--use_tar=] [--use_make=] [--use_cc=]" 2>&1
michael@13: echo " [--use_ar=] [--use_ld=] [--use_as=] [--use_strip=]" 2>&1
michael@13: echo " [-t|--tar] [-h|--help] [-v|--version]" 2>&1
michael@13: exit 1
michael@13: fi
michael@13:
michael@13: # make sure all essential unpacking tools are available
michael@13: # (the build tools are checked later from within openpkg.spec)
michael@13: for tool in /bin/sh mkdir cat tar rm chown chgrp sed dd; do
michael@13: found=no
michael@13: case $tool in
michael@13: /* )
michael@13: if [ -f $tool ]; then
michael@13: found=yes
michael@13: fi
michael@13: ;;
michael@13: * )
michael@13: for p in `IFS=:; echo $PATH`; do
michael@13: if [ -f "$p/$tool" ]; then
michael@13: found=yes
michael@13: break
michael@13: fi
michael@13: done
michael@13: ;;
michael@13: esac
michael@13: if [ ".$found" = .no ]; then
michael@13: echo "$l_me:ERROR: unable to find bootstrap tool \"$tool\"" 1>&2
michael@13: exit 1
michael@13: fi
michael@13: done
michael@13:
michael@13: # optionally extract the embedded tarball only
michael@13: if [ ".$o_tar" = .yes ]; then
michael@13: dd if=$l_me bs=8192 skip=8 2>/dev/null
michael@13: exit 0
michael@13: fi
michael@13:
michael@13: # display version and copyright header
michael@13: echo "OpenPKG ${l_release} Source Bootstrap Package, version ${l_version}"
michael@13: if [ ".$o_version" = .yes ]; then
michael@13: exit 0
michael@13: fi
michael@13: echo "Building for prefix ${l_prefix} on current platform"
michael@13:
michael@13: # determine current user/group
michael@13: cusr=`(id -un) 2>/dev/null ||\
michael@13: (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
michael@13: (whoami) 2>/dev/null ||\
michael@13: (who am i | cut "-d " -f1) 2>/dev/null ||\
michael@13: echo $LOGNAME`
michael@13: cgid=`(id -g $cusr) 2>/dev/null ||\
michael@13: ((getent passwd "${cusr}"; grep "^${cusr}:" /etc/passwd; ypmatch "${cusr}" passwd; nismatch "${cusr}" passwd; nidump passwd . | grep "^${cusr}:") 2>/dev/null |\
michael@13: sed -e 'q' | awk -F: '{ print $4; }')`
michael@13: cgrp=`(id -gn $cusr) 2>/dev/null ||\
michael@13: ((getent group; cat /etc/group; ypcat group; niscat group; nidump group .) 2>/dev/null | grep "^[^:]*:[^:]*:${cgid}:" |\
michael@13: sed -e 'q' | awk -F: '{ print $1; }')`
michael@13: if [ ".$cgrp" = . ]; then
michael@13: cgrp="$cusr"
michael@13: fi
michael@13:
michael@13: # extract the source distribution files
michael@13: echo "++ extracting OpenPKG source distribution"
michael@13: rm -rf $l_dir >/dev/null 2>&1
michael@13: mkdir $l_dir || exit 1
michael@13: dd if=$l_me bs=8192 skip=8 2>/dev/null | (cd $l_dir; tar xf - 2>/dev/null)
michael@13: if [ ".$cusr" = .root ]; then
michael@13: ( cd $l_dir || exit 1
michael@13: chown -R -h $cusr . >/dev/null 2>&1 || true
michael@13: chgrp -R -h $cgrp . >/dev/null 2>&1 || true
michael@13: ) || exit 1
michael@13: fi
michael@13: if [ ! -f $l_dir/openpkg.boot ]; then
michael@13: echo "$l_me:ERROR: failed to unpack into directory \"$l_dir\"" 1>&2
michael@13: exit 1
michael@13: fi
michael@13:
michael@13: # perform bootstrap procedure
michael@13: echo "++ building OpenPKG binary distribution"
michael@13: ( cd $l_dir || exit 1
michael@13: ./openpkg.boot ${1+"$@"} || exit 1
michael@13: ) || exit 1
michael@13:
michael@13: # cleanup
michael@13: rm -rf $l_dir >/dev/null 2>&1
michael@13:
michael@13: # die explicitly just before the shell would discover
michael@13: # that we carry mega-bytes of data with us...
michael@13: exit 0
michael@13:
michael@13: # the distribution tarball is appended in raw format directly to the
michael@13: # end of this script, just leaded by padding whitespaces which make
michael@13: # sure that the tarball data starts at the pre-defined offset of 64KB.
michael@13: # This allows us to unpack the tarball by just skipping the leading
michael@13: # 64KB (= 8192*8, see above).
michael@13: