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