sbotools2

Maintenance fork of the original sbotools version 2
git clone git://git.server.ky/slackcoder/sbotools2
Log | Files | Refs | README

upgradepkg (3489B)


      1 #!/bin/bash
      2 
      3 # Stripped down and useless version of this script merely used for testing.
      4 # But some bits taken from the original, so here's the original copyright
      5 # notice.
      6 
      7 # Copyright 1999  Patrick Volkerding, Moorhead, Minnesota, USA
      8 # Copyright 2001, 2002, 2003  Slackware Linux, Inc., Concord, California, USA
      9 # Copyright 2009, 2015  Patrick J. Volkerding, Sebeka, MN, USA
     10 # Copyright 2015  Michal Nazarewicz <mina86@mina86.com>
     11 # All rights reserved.
     12 #
     13 # Redistribution and use of this script, with or without modification, is
     14 # permitted provided that the following conditions are met:
     15 #
     16 # 1. Redistributions of this script must retain the above copyright
     17 #    notice, this list of conditions and the following disclaimer.
     18 #
     19 #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     20 #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     21 #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
     22 #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     24 #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     25 #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     26 #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     27 #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     28 #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 #
     30 # Modified to handle either old 8.3 or new package-version-arch-build.tgz
     31 # packages, Sat Nov 17 14:25:58 PST 2001 volkerdi
     32 #
     33 # Rewritten to clean out _all_ old packages of a given basename, not just
     34 # the first one found, Thu Apr  4 01:01:05 PST 2002 volkerdi
     35 #
     36 # Added --install-new and --reinstall, Fri May 31 14:11:14 PDT 2002 volkerdi
     37 # Added --dry-run, Sat Apr 26 18:13:29 PDT 2003
     38 #
     39 # Sat Apr 25 21:18:53 UTC 2009
     40 # Support new compression types and package extensions.
     41 # Converted to use new pkgbase() function to remove pathname and
     42 # valid package extensions.
     43 #
     44 # Sat 17 Jan 16:21:32 UTC 2015  mina86
     45 # Various optimisation mostly resolving around avoiding having to fork
     46 # and call cut, basename and other helper commands.  Slight
     47 # refactoring of code calling removepkg.
     48 
     49 
     50 while [[ $# > 1 ]]
     51 do
     52 key="$1"
     53 
     54 case $key in
     55 	--dryrun)
     56 		DRYRUN=1
     57 		;;
     58 	--install-new)
     59 		NEW=1
     60 		;;
     61 	--reinstall)
     62 		REINSTALL=1
     63 		;;
     64 	--verbose)
     65 		VERBOSE=1
     66 		;;
     67 esac
     68 shift
     69 done
     70 
     71 PACKAGE="$1"
     72 
     73 pkgbase() {
     74   PKGRETURN=${1##*/}
     75   case "$PKGRETURN" in *.t[gblx]z)
     76     PKGRETURN=${PKGRETURN%.*}
     77   esac
     78   echo "$PKGRETURN"
     79 }
     80 
     81 package_name() {
     82   STRING=$(pkgbase "$1")
     83   case "$STRING" in
     84   *-*-*-*)
     85     # At least four segments, strip version arch and build and return name:
     86     echo "${STRING%-*-*-*}"
     87     ;;
     88   *)
     89     # Old style package name with one segment or we don't have four
     90     # segments: return the old-style (or out of spec) package name.
     91     echo $STRING
     92   esac
     93 }
     94 
     95 for ARG; do
     96   OLD=${ARG%'%'*}
     97   NEW=${ARG#*'%'}
     98 
     99   INCOMINGDIR=$(dirname $NEW)
    100   NNAME=${NEW##*/}
    101   ONAME=${OLD##*/}
    102   NEW=$(pkgbase $NEW)
    103   OLD=$(pkgbase $OLD)
    104 
    105   SHORT="$(package_name $OLD)"
    106   if [ ! -r /var/log/packages/$OLD ]; then
    107 	  if ls /var/log/packages/$SHORT* &>/dev/null ; then
    108 		  for installed_package in /var/log/packages/$SHORT* ; do
    109 			  if [ "$(package_name $installed_package)" = "$SHORT" ]; then
    110 				  OLD="${installed_package##*/}"
    111 				  break
    112 			  fi
    113 		  done
    114 	  fi
    115   fi
    116 
    117   /sbin/removepkg $OLD
    118   /sbin/installpkg $INCOMINGDIR/$NNAME
    119 done