openpkg/etc.wrapbin.sh

changeset 428
f880f219c566
child 445
43a74e63d4a3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/openpkg/etc.wrapbin.sh	Tue Jul 31 12:23:42 2012 +0200
     1.3 @@ -0,0 +1,267 @@
     1.4 +#!/bin/sh
     1.5 +#![OpenPKG]
     1.6 +##
     1.7 +##  OpenPKG Binary Bootstrap Package (self-extracting shell script)
     1.8 +##  Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/>
     1.9 +##
    1.10 +##  This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
    1.11 +##  All rights reserved. Licenses which grant limited permission to use,
    1.12 +##  copy, modify and distribute this software are available from the
    1.13 +##  OpenPKG GmbH.
    1.14 +##
    1.15 +##  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
    1.16 +##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    1.17 +##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    1.18 +##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
    1.19 +##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.20 +##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.21 +##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    1.22 +##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.23 +##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.24 +##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    1.25 +##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.26 +##  SUCH DAMAGE.
    1.27 +##
    1.28 +
    1.29 +#   configuration
    1.30 +l_me="$0"
    1.31 +o_help=no
    1.32 +o_version=no
    1.33 +o_tar=no
    1.34 +l_prefix='@l_prefix@'
    1.35 +l_musr='@MUSR@'
    1.36 +l_mgrp='@MGRP@'
    1.37 +l_platform="@l_platform@"
    1.38 +l_release="@l_release@"
    1.39 +l_version="@l_version@"
    1.40 +l_unprivileged="@l_unprivileged@"
    1.41 +
    1.42 +#   establish standard environment
    1.43 +PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin"
    1.44 +LC_CTYPE=C
    1.45 +export LC_CTYPE
    1.46 +umask 022
    1.47 +
    1.48 +#   parse command line options
    1.49 +for opt
    1.50 +do
    1.51 +    case $opt in
    1.52 +        -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
    1.53 +           *) arg='' ;;
    1.54 +    esac
    1.55 +    case $opt in
    1.56 +        -h | --help    ) o_help=yes     ;;
    1.57 +        -v | --version ) o_version=yes  ;;
    1.58 +        -t | --tar     ) o_tar=yes      ;;
    1.59 +        --prefix=*     ) l_prefix=$arg  ;;
    1.60 +        *              ) o_help=yes     ;;
    1.61 +    esac
    1.62 +done
    1.63 +if [ ".$o_version" = .no -a ".$l_prefix" = . ]; then
    1.64 +    o_help=yes
    1.65 +fi
    1.66 +if [ ".$o_help" = .yes ]; then
    1.67 +    echo "Usage: sh $l_me" 2>&1
    1.68 +    echo "       [--prefix=<prefix>] [-t|--tar]" 2>&1
    1.69 +    echo "       [-h|--help] [-v|--version]" 2>&1
    1.70 +    exit 1
    1.71 +fi
    1.72 +
    1.73 +#   make sure all essential installation tools are available
    1.74 +for tool in sed mkdir dd tar chown chgrp; do
    1.75 +    found=no
    1.76 +    case $tool in
    1.77 +        /* )
    1.78 +            if [ -f $tool ]; then
    1.79 +                found=yes
    1.80 +            fi
    1.81 +            ;;
    1.82 +        * )
    1.83 +            for p in `IFS=:; echo $PATH`; do
    1.84 +                if [ -f "$p/$tool" ]; then
    1.85 +                    found=yes
    1.86 +                    break
    1.87 +                fi
    1.88 +            done
    1.89 +            ;;
    1.90 +    esac
    1.91 +    if [ ".$found" = .no ]; then
    1.92 +        echo "$l_me:ERROR: unable to find installation tool \"$tool\"" 1>&2
    1.93 +        exit 1
    1.94 +    fi
    1.95 +done
    1.96 +
    1.97 +#   optionally extract the embedded tarball only
    1.98 +if [ ".$o_tar" = .yes ]; then
    1.99 +    tmpdir="${TMPDIR-/tmp}/openpkg.$$"
   1.100 +    ( umask 077 && mkdir $tmpdir) || exit 1
   1.101 +    dd if=$l_me bs=8192 skip=8 2>/dev/null |\
   1.102 +    ( cd $tmpdir || exit 1
   1.103 +      tar xf - 2>/dev/null || exit 1
   1.104 +      ./openpkg.bzip2 -d -c openpkg.tar.bz2
   1.105 +    ) || exit 1
   1.106 +    rm -rf $tmpdir
   1.107 +    exit 0
   1.108 +fi
   1.109 +
   1.110 +#   display version and copyright header
   1.111 +echo "OpenPKG ${l_release} Binary Bootstrap Package, version ${l_version}"
   1.112 +echo "Built for prefix ${l_prefix} on target platform ${l_platform}"
   1.113 +if [ ".$o_version" = .yes ]; then
   1.114 +    exit 0
   1.115 +fi
   1.116 +
   1.117 +#   determine current username
   1.118 +cusr=`(id -un) 2>/dev/null ||\
   1.119 +      (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
   1.120 +      (whoami) 2>/dev/null ||\
   1.121 +      (who am i | cut "-d " -f1) 2>/dev/null ||\
   1.122 +      echo ${LOGNAME-"NN"}`
   1.123 +
   1.124 +#   running the embedded %pre script for hooking into the system environment
   1.125 +echo "++ hooking OpenPKG instance into system environment"
   1.126 +prefix="$l_prefix"
   1.127 +susr='@SUSR@'; sgrp='@SGRP@'
   1.128 +musr='@MUSR@'; mgrp='@MGRP@'
   1.129 +rusr='@RUSR@'; rgrp='@RGRP@'
   1.130 +nusr='@NUSR@'; ngrp='@NGRP@'
   1.131 +suid='@SUID@'; sgid='@SGID@'
   1.132 +muid='@MUID@'; mgid='@MGID@'
   1.133 +ruid='@RUID@'; rgid='@RGID@'
   1.134 +nuid='@NUID@'; ngid='@NGID@'
   1.135 +unprivileged="$l_unprivileged"
   1.136 +set -- 1 # emulate RPM's $1 when executing scripts
   1.137 +#   ---- BEGIN EMBEDDED %pre SCRIPT ----
   1.138 +@PRE@
   1.139 +#   ---- END EMBEDDED %pre SCRIPT ----
   1.140 +
   1.141 +#   make sure prefix/root directory exists
   1.142 +#   and has correct permissions and owner/group
   1.143 +if [ ! -d $l_prefix ]; then
   1.144 +    #   create prefix/root directory from scratch
   1.145 +    echo "++ creating OpenPKG instance root directory \"$l_prefix\""
   1.146 +    d=''
   1.147 +    for c in `IFS=/; echo $l_prefix`; do
   1.148 +        d="$d/$c"
   1.149 +        if [ ! -d $d ]; then
   1.150 +            mkdir $d || exit 1
   1.151 +            chmod 755 $d || exit 1
   1.152 +            if [ ".$cusr" = .root ]; then
   1.153 +                chown $musr $d >/dev/null 2>&1 || true
   1.154 +                chgrp $mgrp $d >/dev/null 2>&1 || true
   1.155 +            fi
   1.156 +        fi
   1.157 +    done
   1.158 +else
   1.159 +    #   adjust already existing prefix/root directory
   1.160 +    echo "++ fixating OpenPKG instance root directory \"$l_prefix\""
   1.161 +    ( cd $l_prefix || exit 1
   1.162 +      chmod 755 . || exit 1
   1.163 +      if [ ".$cusr" = .root ]; then
   1.164 +          chown $musr . >/dev/null 2>&1 || true
   1.165 +          chgrp $mgrp . >/dev/null 2>&1 || true
   1.166 +      fi
   1.167 +    ) || exit 1
   1.168 +fi
   1.169 +
   1.170 +#   extract and install binary distribution files
   1.171 +echo "++ extracting OpenPKG binary distribution"
   1.172 +dd if=$l_me bs=8192 skip=8 2>/dev/null |\
   1.173 +    (cd $l_prefix; tar xf - 2>/dev/null)
   1.174 +echo "++ installing OpenPKG binary distribution"
   1.175 +( cd $l_prefix || exit 1
   1.176 +  ./openpkg.bzip2 -d -c openpkg.tar.bz2 | ./openpkg.tar xf - 2>/dev/null
   1.177 +  rm -f openpkg.tar openpkg.bzip2 openpkg.tar.bz2 >/dev/null 2>&1 || true
   1.178 +) || exit 1
   1.179 +
   1.180 +#   immediately activate BOOT license to let the
   1.181 +#   following early RPM usage already work correctly
   1.182 +echo "BOOT" >$l_prefix/etc/openpkg/license
   1.183 +
   1.184 +#   fixate installation files
   1.185 +#   (ATTENTION: order of chgrp/chown and chmod is important because of "set-UID" bits)
   1.186 +echo "++ fixating OpenPKG instance filesystem hierarchy"
   1.187 +( echo 'fixate () {'
   1.188 +  echo '    chgrp "$3" "$4"'
   1.189 +  echo '    chown "$2" "$4"'
   1.190 +  echo '    chmod "$1" "$4"'
   1.191 +  echo '}'
   1.192 +  cd / && $l_prefix/bin/openpkg --keep-privileges rpm -q openpkg \
   1.193 +      --qf '[fixate %7.7{FILEMODES:octal} %{FILEUSERNAME:shescape} %{FILEGROUPNAME:shescape} ::%{FILENAMES:shescape}\n]' |\
   1.194 +      grep -v '(none)' | sed 's/^fixate .../fixate /' | sed -e "s; ::\\(.\\)@l_prefix@; \\1$l_prefix;"
   1.195 +) | sh 2>/dev/null || true
   1.196 +
   1.197 +#   running the embedded %post script
   1.198 +echo "++ post-processing OpenPKG bootstrap installation"
   1.199 +prefix="$l_prefix"
   1.200 +susr='@SUSR@'; sgrp='@SGRP@'
   1.201 +musr='@MUSR@'; mgrp='@MGRP@'
   1.202 +rusr='@RUSR@'; rgrp='@RGRP@'
   1.203 +nusr='@NUSR@'; ngrp='@NGRP@'
   1.204 +suid='@SUID@'; sgid='@SGID@'
   1.205 +muid='@MUID@'; mgid='@MGID@'
   1.206 +ruid='@RUID@'; rgid='@RGID@'
   1.207 +nuid='@NUID@'; ngid='@NGID@'
   1.208 +unprivileged="$l_unprivileged"
   1.209 +set -- 1 # emulate RPM's $1 when executing scripts
   1.210 +#   ---- BEGIN EMBEDDED %post SCRIPT ----
   1.211 +@POST@
   1.212 +#   ---- END EMBEDDED %post SCRIPT ----
   1.213 +
   1.214 +#   display final information
   1.215 +( echo "Congratulations!"
   1.216 +  echo ""
   1.217 +  echo "You have successfully installed an OpenPKG ${l_release} instance"
   1.218 +  echo "under prefix ${l_prefix} on target platform ${l_platform}."
   1.219 +  echo ""
   1.220 +  echo "For details about this OpenPKG instance, run any of the"
   1.221 +  echo "following typical OpenPKG RPM query commands:"
   1.222 +  echo ""
   1.223 +  echo "    \$ ${l_prefix}/bin/openpkg rpm -qa"
   1.224 +  echo "    \$ ${l_prefix}/bin/openpkg rpm -qi  openpkg"
   1.225 +  echo "    \$ ${l_prefix}/bin/openpkg rpm -qlv openpkg"
   1.226 +  echo ""
   1.227 +  echo "To check the integrity of the entire OpenPKG instance,"
   1.228 +  echo "run the following OpenPKG RPM verify command:"
   1.229 +  echo ""
   1.230 +  echo "    \$ ${l_prefix}/bin/openpkg rpm -Va"
   1.231 +  echo ""
   1.232 +  echo "To install software packages into this OpenPKG instance, run"
   1.233 +  echo "the following two OpenPKG RPM build commands for each package:"
   1.234 +  echo ""
   1.235 +  echo "    \$ ${l_prefix}/bin/openpkg rpm --rebuild /path/to/foo-*.src.rpm"
   1.236 +  echo "    \$ ${l_prefix}/bin/openpkg rpm -Uvh ${l_prefix}/RPM/PKG/foo-*.rpm"
   1.237 +  echo ""
   1.238 +  echo "To leverage from remote indexes on download.openpkg.org and"
   1.239 +  echo "conveniently generate a shell script for all-in-one downloading"
   1.240 +  echo "(openpkg curl), building (openpkg rpm --rebuild) and installing"
   1.241 +  echo "(openpkg rpm -Uvh) one or more OpenPKG RPM packages, including all"
   1.242 +  echo "their transitive dependencies, in topologically correct order:"
   1.243 +  echo ""
   1.244 +  echo "    \$ ${l_prefix}/bin/openpkg build foo bar quux | sh"
   1.245 +  echo ""
   1.246 +  echo "To remove a software package later, just run:"
   1.247 +  echo ""
   1.248 +  echo "    \$ ${l_prefix}/bin/openpkg rpm -e foo"
   1.249 +  echo ""
   1.250 +  echo "To remove the whole OpenPKG instance under prefix ${l_prefix},"
   1.251 +  echo "just remove every package as shown above. As you finally"
   1.252 +  echo "remove the package \"openpkg\", the OpenPKG instance itself"
   1.253 +  echo "will be unlinked from the system and removed as well."
   1.254 +  echo ""
   1.255 +  echo "Thank you for flying OpenPKG..."
   1.256 +  echo "                                        Ralf S. Engelschall"
   1.257 +  echo "                                        OpenPKG GmbH"
   1.258 +  echo "                                        openpkg.com"
   1.259 +) | $l_prefix/lib/openpkg/rpmtool msg -b -t info
   1.260 +
   1.261 +#   die explicitly just before the shell would discover
   1.262 +#   that we carry mega-bytes of data with us... ;-)
   1.263 +exit 0
   1.264 +
   1.265 +#   the distribution tarball is appended in raw format directly to the
   1.266 +#   end of this script, just leaded by padding whitespaces which make
   1.267 +#   sure that the tarball data starts at the pre-defined offset of 64KB.
   1.268 +#   This allows us to unpack the tarball by just skipping the leading
   1.269 +#   64KB (= 8192*8, see above).
   1.270 +

mercurial