openpkg/aux.wrapbin.sh

Thu, 05 Nov 2009 13:42:13 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 05 Nov 2009 13:42:13 +0100
changeset 237
76b4896bea63
permissions
-rw-r--r--

Resynchronize with upstream package maintainer version.
This is needed due to large changeset after upgrade of vendor
distribution from version 1.1.* to 1.2.*.

     1 #!/bin/sh
     2 ##
     3 ##  OpenPKG Binary Bootstrap Package (self-extracting shell script)
     4 ##  Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
     5 ##  Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
     6 ##
     7 ##  Permission to use, copy, modify, and distribute this software for
     8 ##  any purpose with or without fee is hereby granted, provided that
     9 ##  the above copyright notice and this permission notice appear in all
    10 ##  copies.
    11 ##
    12 ##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    13 ##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    14 ##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    15 ##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
    16 ##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    17 ##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    18 ##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    19 ##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    20 ##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    21 ##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    22 ##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    23 ##  SUCH DAMAGE.
    24 ##
    26 #   configuration
    27 l_me="$0"
    28 o_help=no
    29 o_version=no
    30 o_tar=no
    31 l_prefix='@l_prefix@'
    32 l_musr='@MUSR@'
    33 l_mgrp='@MGRP@'
    34 l_platform="@l_platform@"
    35 l_release="@l_release@"
    36 l_version="@l_version@"
    38 #   establish standard environment
    39 PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin"
    40 LC_CTYPE=C
    41 export LC_CTYPE
    42 umask 022
    44 #   parse command line options
    45 for opt
    46 do
    47     case $opt in
    48         -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
    49            *) arg='' ;;
    50     esac
    51     case $opt in
    52         -h | --help    ) o_help=yes     ;;
    53         -v | --version ) o_version=yes  ;;
    54         -t | --tar     ) o_tar=yes      ;;
    55         --prefix=*     ) l_prefix=$arg  ;;
    56         *              ) o_help=yes     ;;
    57     esac
    58 done
    59 if [ ".$o_version" = .no -a ".$l_prefix" = . ]; then
    60     o_help=yes
    61 fi
    62 if [ ".$o_help" = .yes ]; then
    63     echo "Usage: sh $l_me" 2>&1
    64     echo "       [--prefix=<prefix>] [-t|--tar]" 2>&1
    65     echo "       [-h|--help] [-v|--version]" 2>&1
    66     exit 1
    67 fi
    69 #   make sure all essential installation tools are available
    70 for tool in sed mkdir dd tar chown chgrp; do
    71     found=no
    72     case $tool in
    73         /* )
    74             if [ -f $tool ]; then
    75                 found=yes
    76             fi
    77             ;;
    78         * )
    79             for p in `IFS=:; echo $PATH`; do
    80                 if [ -f "$p/$tool" ]; then
    81                     found=yes
    82                     break
    83                 fi
    84             done
    85             ;;
    86     esac
    87     if [ ".$found" = .no ]; then
    88         echo "$l_me:ERROR: unable to find installation tool \"$tool\"" 1>&2
    89         exit 1
    90     fi
    91 done
    93 #   optionally extract the embedded tarball only
    94 if [ ".$o_tar" = .yes ]; then
    95     tmpdir="${TMPDIR-/tmp}/openpkg.$$"
    96     ( umask 077 && mkdir $tmpdir) || exit 1
    97     dd if=$l_me bs=8192 skip=8 2>/dev/null |\
    98     ( cd $tmpdir || exit 1
    99       tar xf - 2>/dev/null || exit 1
   100       ./openpkg.bzip2 -d -c openpkg.tar.bz2
   101     ) || exit 1
   102     rm -rf $tmpdir
   103     exit 0
   104 fi
   106 #   display version and copyright header
   107 echo "OpenPKG ${l_release} Binary Bootstrap Package, version ${l_version}"
   108 echo "Built for prefix ${l_prefix} on target platform ${l_platform}"
   109 if [ ".$o_version" = .yes ]; then
   110     exit 0
   111 fi
   113 #   determine current username
   114 cusr=`(id -un) 2>/dev/null ||\
   115       (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
   116       (whoami) 2>/dev/null ||\
   117       (who am i | cut "-d " -f1) 2>/dev/null ||\
   118       echo ${LOGNAME-"NN"}`
   120 #   running the embedded %pre script for hooking into the system environment
   121 echo "++ hooking OpenPKG instance into system environment"
   122 prefix="$l_prefix"
   123 susr='@SUSR@'; sgrp='@SGRP@'
   124 musr='@MUSR@'; mgrp='@MGRP@'
   125 rusr='@RUSR@'; rgrp='@RGRP@'
   126 nusr='@NUSR@'; ngrp='@NGRP@'
   127 suid='@SUID@'; sgid='@SGID@'
   128 muid='@MUID@'; mgid='@MGID@'
   129 ruid='@RUID@'; rgid='@RGID@'
   130 nuid='@NUID@'; ngid='@NGID@'
   131 set -- 1 # emulate RPM's $1 when executing scripts
   132 #   ---- BEGIN EMBEDDED %pre SCRIPT ----
   133 @PRE@
   134 #   ---- END EMBEDDED %pre SCRIPT ----
   136 #   make sure prefix/root directory exists
   137 #   and has correct permissions and owner/group
   138 if [ ! -d $l_prefix ]; then
   139     #   create prefix/root directory from scratch
   140     echo "++ creating OpenPKG instance root directory \"$l_prefix\""
   141     d=''
   142     for c in `IFS=/; echo $l_prefix`; do
   143         d="$d/$c"
   144         if [ ! -d $d ]; then
   145             mkdir $d || exit 1
   146             chmod 755 $d || exit 1
   147             if [ ".$cusr" = .root ]; then
   148                 chown $musr $d >/dev/null 2>&1 || true
   149                 chgrp $mgrp $d >/dev/null 2>&1 || true
   150             fi
   151         fi
   152     done
   153 else
   154     #   adjust already existing prefix/root directory
   155     echo "++ fixating OpenPKG instance root directory \"$l_prefix\""
   156     ( cd $l_prefix || exit 1
   157       chmod 755 . || exit 1
   158       if [ ".$cusr" = .root ]; then
   159           chown $musr . >/dev/null 2>&1 || true
   160           chgrp $mgrp . >/dev/null 2>&1 || true
   161       fi
   162     ) || exit 1
   163 fi
   165 #   extract and install binary distribution files
   166 echo "++ extracting OpenPKG binary distribution"
   167 dd if=$l_me bs=8192 skip=8 2>/dev/null |\
   168     (cd $l_prefix; tar xf - 2>/dev/null)
   169 echo "++ installing OpenPKG binary distribution"
   170 ( cd $l_prefix || exit 1
   171   ./openpkg.bzip2 -d -c openpkg.tar.bz2 | ./openpkg.tar xf - 2>/dev/null
   172   rm -f openpkg.tar openpkg.bzip2 openpkg.tar.bz2 >/dev/null 2>&1 || true
   173 ) || exit 1
   175 #   fixate installation files
   176 #   (ATTENTION: order of chgrp/chown and chmod is important because of "set-UID" bits)
   177 echo "++ fixating OpenPKG instance filesystem hierarchy"
   178 ( echo 'fixate () {'
   179   echo '    chgrp "$3" "$4"'
   180   echo '    chown "$2" "$4"'
   181   echo '    chmod "$1" "$4"'
   182   echo '}'
   183   $l_prefix/bin/openpkg --keep-privileges rpm -q openpkg \
   184       --qf '[fixate %7.7{FILEMODES:octal} %{FILEUSERNAME:shescape} %{FILEGROUPNAME:shescape} ::%{FILENAMES:shescape}\n]' |\
   185       grep -v '(none)' | sed 's/^fixate .../fixate /' | sed -e "s; ::\\(.\\)@l_prefix@; \\1$l_prefix;"
   186 ) | sh 2>/dev/null || true
   188 #   running the embedded %post script
   189 echo "++ post-processing OpenPKG bootstrap installation"
   190 prefix="$l_prefix"
   191 susr='@SUSR@'; sgrp='@SGRP@'
   192 musr='@MUSR@'; mgrp='@MGRP@'
   193 rusr='@RUSR@'; rgrp='@RGRP@'
   194 nusr='@NUSR@'; ngrp='@NGRP@'
   195 suid='@SUID@'; sgid='@SGID@'
   196 muid='@MUID@'; mgid='@MGID@'
   197 ruid='@RUID@'; rgid='@RGID@'
   198 nuid='@NUID@'; ngid='@NGID@'
   199 set -- 1 # emulate RPM's $1 when executing scripts
   200 #   ---- BEGIN EMBEDDED %post SCRIPT ----
   201 @POST@
   202 #   ---- END EMBEDDED %post SCRIPT ----
   204 #   display final information
   205 ( echo "Congratulations!"
   206   echo ""
   207   echo "You have successfully installed an OpenPKG ${l_release} instance"
   208   echo "under prefix ${l_prefix} on target platform ${l_platform}."
   209   echo ""
   210   echo "For details about this OpenPKG instance, run any of the"
   211   echo "following typical OpenPKG RPM query commands:"
   212   echo ""
   213   echo "    \$ ${l_prefix}/bin/openpkg rpm -qa"
   214   echo "    \$ ${l_prefix}/bin/openpkg rpm -qi  openpkg"
   215   echo "    \$ ${l_prefix}/bin/openpkg rpm -qlv openpkg"
   216   echo ""
   217   echo "To check the integrity of the entire OpenPKG instance,"
   218   echo "run the following OpenPKG RPM verify command:"
   219   echo ""
   220   echo "    \$ ${l_prefix}/bin/openpkg rpm -Va"
   221   echo ""
   222   echo "To install software packages into this OpenPKG instance, run"
   223   echo "the following two OpenPKG RPM build commands for each package:"
   224   echo ""
   225   echo "    \$ ${l_prefix}/bin/openpkg rpm --rebuild /path/to/foo-*.src.rpm"
   226   echo "    \$ ${l_prefix}/bin/openpkg rpm -Uvh ${l_prefix}/RPM/PKG/foo-*.rpm"
   227   echo ""
   228   echo "To remove a software package later, just run:"
   229   echo ""
   230   echo "    \$ ${l_prefix}/bin/openpkg rpm -e foo"
   231   echo ""
   232   echo "To remove the whole OpenPKG instance under prefix ${l_prefix},"
   233   echo "just remove every package as shown above. As you finally"
   234   echo "remove the package \"openpkg\", the OpenPKG instance itself"
   235   echo "will be unlinked from the system and removed as well."
   236   echo ""
   237   echo "Thank you for flying OpenPKG..."
   238   echo "                                        Ralf S. Engelschall"
   239   echo "                                        The OpenPKG Project"
   240   echo "                                        openpkg@openpkg.org"
   241 ) | $l_prefix/lib/openpkg/rpmtool msg -b -t info
   243 #   die explicitly just before the shell would discover
   244 #   that we carry mega-bytes of data with us... ;-)
   245 exit 0
   247 #   the distribution tarball is appended in raw format directly to the
   248 #   end of this script, just leaded by padding whitespaces which make
   249 #   sure that the tarball data starts at the pre-defined offset of 64KB.
   250 #   This allows us to unpack the tarball by just skipping the leading
   251 #   64KB (= 8192*8, see above).

mercurial