| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- #!/bin/sh
- ##
- ## OpenPKG Binary Bootstrap Package (self-extracting shell script)
- ## Copyright (c) 2000-2004 The OpenPKG Project <http://www.openpkg.org/>
- ## Copyright (c) 2000-2004 Ralf S. Engelschall <rse@engelschall.com>
- ## Copyright (c) 2000-2004 Cable & Wireless <http://www.cw.com/>
- ##
- ## Permission to use, copy, modify, and distribute this software for
- ## any purpose with or without fee is hereby granted, provided that
- ## the above copyright notice and this permission notice appear in all
- ## copies.
- ##
- ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
- ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- ## SUCH DAMAGE.
- ##
- # configuration
- l_me="$0"
- o_help=no
- o_version=no
- l_prefix='@l_prefix@'
- l_musr='@MUSR@'
- l_mgrp='@MGRP@'
- l_platform="@l_platform@"
- l_release="@l_release@"
- l_version="@l_version@"
- # establish standard environment
- LC_CTYPE=C
- export LC_CTYPE
- umask 022
- # parse command line options
- for opt
- do
- case $opt in
- -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
- *) arg='' ;;
- esac
- case $opt in
- -h | --help ) o_help=yes ;;
- -v | --version ) o_version=yes ;;
- --prefix=* ) l_prefix=$arg ;;
- * ) o_help=yes ;;
- esac
- done
- if [ ".$o_version" = .no -a ".$l_prefix" = . ]; then
- o_help=yes
- fi
- if [ ".$o_help" = .yes ]; then
- echo "Usage: sh $l_me [--prefix=<prefix>]" 2>&1
- echo " [-h|--help] [-v|--version]" 2>&1
- exit 1
- fi
- # display version and copyright header
- echo "OpenPKG ${l_release} Binary Bootstrap Package, version ${l_version}"
- echo "Built for prefix ${l_prefix} on target platform ${l_platform}"
- if [ ".$o_version" = .yes ]; then
- exit 0
- fi
- # make sure all essential installation tools are available
- for tool in sed mkdir dd tar chown chgrp; do
- found=no
- case $tool in
- /* )
- if [ -f $tool ]; then
- found=yes
- fi
- ;;
- * )
- for p in `IFS=:; echo $PATH`; do
- if [ -f "$p/$tool" ]; then
- found=yes
- break
- fi
- done
- ;;
- esac
- if [ ".$found" = .no ]; then
- echo "$l_me:ERROR: unable to find installation tool \"$tool\"" 1>&2
- exit 1
- fi
- done
- # determine current username
- cusr=`(id -un) 2>/dev/null ||\
- (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
- (whoami) 2>/dev/null ||\
- (who am i | cut "-d " -f1) 2>/dev/null ||\
- echo ${LOGNAME-"NN"}`
- # running the embedded %pre script for hooking into the system environment
- echo "++ hooking OpenPKG instance into system environment"
- prefix="$l_prefix"
- susr='@SUSR@'; sgrp='@SGRP@'
- musr='@MUSR@'; mgrp='@MGRP@'
- rusr='@RUSR@'; rgrp='@RGRP@'
- nusr='@NUSR@'; ngrp='@NGRP@'
- suid='@SUID@'; sgid='@SGID@'
- muid='@MUID@'; mgid='@MGID@'
- ruid='@RUID@'; rgid='@RGID@'
- nuid='@NUID@'; ngid='@NGID@'
- set -- 1 # emulate RPM's $1 when executing scripts
- # ---- BEGIN EMBEDDED %pre SCRIPT ----
- @PRE@
- # ---- END EMBEDDED %pre SCRIPT ----
- # make sure prefix/root directory exists
- # and has correct permissions and owner/group
- if [ ! -d $l_prefix ]; then
- # create prefix/root directory from scratch
- echo "++ creating OpenPKG instance root directory \"$l_prefix\""
- d=''
- for c in `IFS=/; echo $l_prefix`; do
- d="$d/$c"
- if [ ! -d $d ]; then
- mkdir $d || exit 1
- chmod 755 $d || exit 1
- if [ ".$cusr" = .root ]; then
- chown $musr $d >/dev/null 2>&1 || true
- chgrp $mgrp $d >/dev/null 2>&1 || true
- fi
- fi
- done
- else
- # adjust already existing prefix/root directory
- echo "++ fixating OpenPKG instance root directory \"$l_prefix\""
- ( cd $l_prefix || exit 1
- chmod 755 . || exit 1
- if [ ".$cusr" = .root ]; then
- chown $musr . >/dev/null 2>&1 || true
- chgrp $mgrp . >/dev/null 2>&1 || true
- fi
- ) || exit 1
- fi
- # extract and install binary distribution files
- echo "++ extracting OpenPKG binary distribution"
- dd if=$l_me bs=8192 skip=8 2>/dev/null |\
- (cd $l_prefix; tar xf - 2>/dev/null)
- echo "++ installing OpenPKG binary distribution"
- ( cd $l_prefix || exit 1
- ./openpkg.bzip2 -d -c openpkg.tar.bz2 | ./openpkg.tar xf - 2>/dev/null
- rm -f openpkg.tar openpkg.bzip2 openpkg.tar.bz2 >/dev/null 2>&1 || true
- ) || exit 1
- # fixate installation files
- echo "++ fixating OpenPKG instance filesystem hierarchy"
- ( echo 'fixate () {'
- echo ' chmod "$1" "$4"'
- echo ' chown "$2" "$4"'
- echo ' chgrp "$3" "$4"'
- echo '}'
- $l_prefix/bin/openpkg rpm -qa \
- --qf '[fixate %7.7{FILEMODES:octal} %{FILEUSERNAME:shescape} %{FILEGROUPNAME:shescape} ::%{FILENAMES:shescape}\n]' |\
- grep -v '(none)' | sed 's/^fixate .../fixate /' | sed -e "s; ::\\(.\\)@l_prefix@; \\1$l_prefix;"
- ) | sh 2>/dev/null || true
- # running the embedded %post script
- echo "++ post-processing OpenPKG bootstrap installation"
- prefix="$l_prefix"
- susr='@SUSR@'; sgrp='@SGRP@'
- musr='@MUSR@'; mgrp='@MGRP@'
- rusr='@RUSR@'; rgrp='@RGRP@'
- nusr='@NUSR@'; ngrp='@NGRP@'
- suid='@SUID@'; sgid='@SGID@'
- muid='@MUID@'; mgid='@MGID@'
- ruid='@RUID@'; rgid='@RGID@'
- nuid='@NUID@'; ngid='@NGID@'
- set -- 1 # emulate RPM's $1 when executing scripts
- # ---- BEGIN EMBEDDED %post SCRIPT ----
- @POST@
- # ---- END EMBEDDED %post SCRIPT ----
- # display final information
- ( echo "Congratulations!"
- echo ""
- echo "You have successfully installed an OpenPKG ${l_release} instance"
- echo "under prefix ${l_prefix} on target platform ${l_platform}."
- echo ""
- echo "Details about this installed OpenPKG instance you can easily"
- echo "determine by running the following typical RPM query commands:"
- echo ""
- echo " \$ ${l_prefix}/bin/openpkg rpm -qa"
- echo " \$ ${l_prefix}/bin/openpkg rpm -qi openpkg"
- echo " \$ ${l_prefix}/bin/openpkg rpm -qlv openpkg"
- echo ""
- echo "The integrity of the whole OpenPKG instance you can check at any"
- echo "time by running the RPM verify command:"
- echo ""
- echo " \$ ${l_prefix}/bin/openpkg rpm -Va"
- echo ""
- echo "For installing software packages into this OpenPKG instance, just run"
- echo "the following two RPM build commands for each package:"
- echo ""
- echo " \$ ${l_prefix}/bin/openpkg rpm --rebuild /path/to/foo-*.src.rpm"
- echo " \$ ${l_prefix}/bin/openpkg rpm -Uvh ${l_prefix}/RPM/PKG/foo-*.rpm"
- echo ""
- echo "If you later want to remove a software package, just run:"
- echo ""
- echo " \$ ${l_prefix}/bin/openpkg rpm -e foo"
- echo ""
- echo "For removing the whole OpenPKG instance under prefix ${l_prefix},"
- echo "just remove every package. Once you finally removed the package"
- echo "\"openpkg\", the whole OpenPKG instance will be unlinked from the"
- echo "system and removed, too."
- echo ""
- echo "Thank you for flying OpenPKG..."
- echo " Ralf S. Engelschall"
- echo " The OpenPKG Project"
- echo " openpkg@openpkg.org"
- ) | $l_prefix/lib/openpkg/rpmtool msg -b -t info
- # die explicitly just before the shell would discover
- # that we carry mega-bytes of data with us... ;-)
- exit 0
- # the distribution tarball is appended in raw format directly to the
- # end of this script, just leaded by padding whitespaces which make
- # sure that the tarball data starts at the pre-defined offset of 64KB.
- # This allows us to unpack the tarball by just skipping the leading
- # 64KB (= 8192*8, see above).
|