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