michael@13: #!/bin/sh
michael@13: ##
michael@13: ## OpenPKG Binary 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='@l_prefix@'
michael@13: l_musr='@MUSR@'
michael@13: l_mgrp='@MGRP@'
michael@13: l_platform="@l_platform@"
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: # 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: * ) o_help=yes ;;
michael@13: esac
michael@13: done
michael@13: if [ ".$o_version" = .no -a ".$l_prefix" = . ]; then
michael@13: o_help=yes
michael@13: fi
michael@13: if [ ".$o_help" = .yes ]; then
michael@13: echo "Usage: sh $l_me" 2>&1
michael@13: echo " [--prefix=] [-t|--tar]" 2>&1
michael@13: echo " [-h|--help] [-v|--version]" 2>&1
michael@13: exit 1
michael@13: fi
michael@13:
michael@13: # make sure all essential installation tools are available
michael@13: for tool in sed mkdir dd tar chown chgrp; 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 installation 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: tmpdir="${TMPDIR-/tmp}/openpkg.$$"
michael@13: ( umask 077 && mkdir $tmpdir) || exit 1
michael@13: dd if=$l_me bs=8192 skip=8 2>/dev/null |\
michael@13: ( cd $tmpdir || exit 1
michael@13: tar xf - 2>/dev/null || exit 1
michael@13: ./openpkg.bzip2 -d -c openpkg.tar.bz2
michael@13: ) || exit 1
michael@13: rm -rf $tmpdir
michael@13: exit 0
michael@13: fi
michael@13:
michael@13: # display version and copyright header
michael@13: echo "OpenPKG ${l_release} Binary Bootstrap Package, version ${l_version}"
michael@13: echo "Built for prefix ${l_prefix} on target platform ${l_platform}"
michael@13: if [ ".$o_version" = .yes ]; then
michael@13: exit 0
michael@13: fi
michael@13:
michael@13: # determine current username
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-"NN"}`
michael@13:
michael@13: # running the embedded %pre script for hooking into the system environment
michael@13: echo "++ hooking OpenPKG instance into system environment"
michael@13: prefix="$l_prefix"
michael@13: susr='@SUSR@'; sgrp='@SGRP@'
michael@13: musr='@MUSR@'; mgrp='@MGRP@'
michael@13: rusr='@RUSR@'; rgrp='@RGRP@'
michael@13: nusr='@NUSR@'; ngrp='@NGRP@'
michael@13: suid='@SUID@'; sgid='@SGID@'
michael@13: muid='@MUID@'; mgid='@MGID@'
michael@13: ruid='@RUID@'; rgid='@RGID@'
michael@13: nuid='@NUID@'; ngid='@NGID@'
michael@13: set -- 1 # emulate RPM's $1 when executing scripts
michael@13: # ---- BEGIN EMBEDDED %pre SCRIPT ----
michael@13: @PRE@
michael@13: # ---- END EMBEDDED %pre SCRIPT ----
michael@13:
michael@13: # make sure prefix/root directory exists
michael@13: # and has correct permissions and owner/group
michael@13: if [ ! -d $l_prefix ]; then
michael@13: # create prefix/root directory from scratch
michael@13: echo "++ creating OpenPKG instance root directory \"$l_prefix\""
michael@13: d=''
michael@13: for c in `IFS=/; echo $l_prefix`; do
michael@13: d="$d/$c"
michael@13: if [ ! -d $d ]; then
michael@13: mkdir $d || exit 1
michael@13: chmod 755 $d || exit 1
michael@13: if [ ".$cusr" = .root ]; then
michael@13: chown $musr $d >/dev/null 2>&1 || true
michael@13: chgrp $mgrp $d >/dev/null 2>&1 || true
michael@13: fi
michael@13: fi
michael@13: done
michael@13: else
michael@13: # adjust already existing prefix/root directory
michael@13: echo "++ fixating OpenPKG instance root directory \"$l_prefix\""
michael@13: ( cd $l_prefix || exit 1
michael@13: chmod 755 . || exit 1
michael@13: if [ ".$cusr" = .root ]; then
michael@13: chown $musr . >/dev/null 2>&1 || true
michael@13: chgrp $mgrp . >/dev/null 2>&1 || true
michael@13: fi
michael@13: ) || exit 1
michael@13: fi
michael@13:
michael@13: # extract and install binary distribution files
michael@13: echo "++ extracting OpenPKG binary distribution"
michael@13: dd if=$l_me bs=8192 skip=8 2>/dev/null |\
michael@13: (cd $l_prefix; tar xf - 2>/dev/null)
michael@13: echo "++ installing OpenPKG binary distribution"
michael@13: ( cd $l_prefix || exit 1
michael@13: ./openpkg.bzip2 -d -c openpkg.tar.bz2 | ./openpkg.tar xf - 2>/dev/null
michael@13: rm -f openpkg.tar openpkg.bzip2 openpkg.tar.bz2 >/dev/null 2>&1 || true
michael@13: ) || exit 1
michael@13:
michael@13: # fixate installation files
michael@13: # (ATTENTION: order of chgrp/chown and chmod is important because of "set-UID" bits)
michael@13: echo "++ fixating OpenPKG instance filesystem hierarchy"
michael@13: ( echo 'fixate () {'
michael@13: echo ' chgrp "$3" "$4"'
michael@13: echo ' chown "$2" "$4"'
michael@13: echo ' chmod "$1" "$4"'
michael@13: echo '}'
michael@13: $l_prefix/bin/openpkg --keep-privileges rpm -q openpkg \
michael@13: --qf '[fixate %7.7{FILEMODES:octal} %{FILEUSERNAME:shescape} %{FILEGROUPNAME:shescape} ::%{FILENAMES:shescape}\n]' |\
michael@13: grep -v '(none)' | sed 's/^fixate .../fixate /' | sed -e "s; ::\\(.\\)@l_prefix@; \\1$l_prefix;"
michael@13: ) | sh 2>/dev/null || true
michael@13:
michael@13: # running the embedded %post script
michael@13: echo "++ post-processing OpenPKG bootstrap installation"
michael@13: prefix="$l_prefix"
michael@13: susr='@SUSR@'; sgrp='@SGRP@'
michael@13: musr='@MUSR@'; mgrp='@MGRP@'
michael@13: rusr='@RUSR@'; rgrp='@RGRP@'
michael@13: nusr='@NUSR@'; ngrp='@NGRP@'
michael@13: suid='@SUID@'; sgid='@SGID@'
michael@13: muid='@MUID@'; mgid='@MGID@'
michael@13: ruid='@RUID@'; rgid='@RGID@'
michael@13: nuid='@NUID@'; ngid='@NGID@'
michael@13: set -- 1 # emulate RPM's $1 when executing scripts
michael@13: # ---- BEGIN EMBEDDED %post SCRIPT ----
michael@13: @POST@
michael@13: # ---- END EMBEDDED %post SCRIPT ----
michael@13:
michael@13: # display final information
michael@13: ( echo "Congratulations!"
michael@13: echo ""
michael@13: echo "You have successfully installed an OpenPKG ${l_release} instance"
michael@13: echo "under prefix ${l_prefix} on target platform ${l_platform}."
michael@13: echo ""
michael@13: echo "For details about this OpenPKG instance, run any of the"
michael@13: echo "following typical OpenPKG RPM query commands:"
michael@13: echo ""
michael@13: echo " \$ ${l_prefix}/bin/openpkg rpm -qa"
michael@13: echo " \$ ${l_prefix}/bin/openpkg rpm -qi openpkg"
michael@13: echo " \$ ${l_prefix}/bin/openpkg rpm -qlv openpkg"
michael@13: echo ""
michael@13: echo "To check the integrity of the entire OpenPKG instance,"
michael@13: echo "run the following OpenPKG RPM verify command:"
michael@13: echo ""
michael@13: echo " \$ ${l_prefix}/bin/openpkg rpm -Va"
michael@13: echo ""
michael@13: echo "To install software packages into this OpenPKG instance, run"
michael@13: echo "the following two OpenPKG RPM build commands for each package:"
michael@13: echo ""
michael@13: echo " \$ ${l_prefix}/bin/openpkg rpm --rebuild /path/to/foo-*.src.rpm"
michael@13: echo " \$ ${l_prefix}/bin/openpkg rpm -Uvh ${l_prefix}/RPM/PKG/foo-*.rpm"
michael@13: echo ""
michael@13: echo "To remove a software package later, just run:"
michael@13: echo ""
michael@13: echo " \$ ${l_prefix}/bin/openpkg rpm -e foo"
michael@13: echo ""
michael@13: echo "To remove the whole OpenPKG instance under prefix ${l_prefix},"
michael@13: echo "just remove every package as shown above. As you finally"
michael@13: echo "remove the package \"openpkg\", the OpenPKG instance itself"
michael@13: echo "will be unlinked from the system and removed as well."
michael@13: echo ""
michael@13: echo "Thank you for flying OpenPKG..."
michael@13: echo " Ralf S. Engelschall"
michael@13: echo " The OpenPKG Project"
michael@13: echo " openpkg@openpkg.org"
michael@13: ) | $l_prefix/lib/openpkg/rpmtool msg -b -t info
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: