summaryrefslogtreecommitdiffstats
path: root/slackware64-current/source/a/pkgtools/scripts/removepkg
diff options
context:
space:
mode:
Diffstat (limited to 'slackware64-current/source/a/pkgtools/scripts/removepkg')
-rw-r--r--slackware64-current/source/a/pkgtools/scripts/removepkg101
1 files changed, 53 insertions, 48 deletions
diff --git a/slackware64-current/source/a/pkgtools/scripts/removepkg b/slackware64-current/source/a/pkgtools/scripts/removepkg
index 2813fc3c5..f6b3bc4ea 100644
--- a/slackware64-current/source/a/pkgtools/scripts/removepkg
+++ b/slackware64-current/source/a/pkgtools/scripts/removepkg
@@ -1,6 +1,43 @@
#!/bin/sh
# Slackware remove package script
#
+# Copyright 1994, 1995, 1998 Patrick Volkerding, Moorhead, Minnesota USA
+# Copyright 2001, Slackware Linux, Inc., Concord, CA USA
+# Copyright 2009, 2015, 2016 Patrick J. Volkerding, Sebeka, MN, USA
+# All rights reserved.
+#
+# Redistribution and use of this script, with or without modification, is
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of this script must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+# Thu Sep 15 17:46:28 UTC 2016 <volkerdi>
+# If removepkg is called with a short package name (no -$VERSION-$ARCH-$BUILD),
+# remove the most recently installed matching package, not the oldest one.
+#
+# Thu Sep 15 08:09:01 BST 2016 <mozes>
+# - Handle finding >1 match for a package. Thanks to SeB on LQ for the feedback.
+#
+# Wed Sep 14 20:44:00 BST 2016 <mozes>
+# - Modify package_name function to cater for package file names that contain
+# >=4 hyphens.
+# Thanks to coralfang on LQ for the report and to Jim Hawkins for the patch.
+# - Modified to handle packages that contain file names with backslashes
+# Thanks to aaazen on LQ for the report and the patch.
+#
# Thu Sep 24 03:31:58 UTC 2015 <alphageek>
# extract_links() sed adjusted to handle symlinks with spaces.
#
@@ -76,28 +113,8 @@
# Original Version from Slackware 3.0
#
-# Copyright 1994, 1995, 1998 Patrick Volkerding, Moorhead, Minnesota USA
-# Copyright 2001, Slackware Linux, Inc., Concord, CA USA
-# Copyright 2009, 2015 Patrick J. Volkerding, Sebeka, MN, USA
-# All rights reserved.
-#
-# Redistribution and use of this script, with or without modification, is
-# permitted provided that the following conditions are met:
-#
-# 1. Redistributions of this script must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
+# Needed to find package names within the 'remove_packages' function:
+shopt -s extglob
# Return a package name that has been stripped of the dirname portion
# and any of the valid extensions (only):
@@ -190,7 +207,9 @@ keep_links() {
}
delete_files() {
- while read FILE ; do
+ local unset LC_ALL # Locally (within this delete_files function) allow handling of backslashes
+ while read -r AFILE ; do # do not expand backslashes on read
+ FILE=$(printf "$AFILE") # unescape octal characters
if [ ! -d "$ROOT/$FILE" ]; then
if [ -r "$ROOT/$FILE" ]; then
if [ "$ROOT/$FILE" -nt "$ADM_DIR/packages/$PKGNAME" ]; then
@@ -259,21 +278,10 @@ delete_cats() {
done
}
-package_name() {
- STRING=$(pkgbase $1 | sed 's?-[^-]*-[^-]*-[^-]*$??')
- # If we don't do this, commands run later will take the '-' to be an option
- # and will destroy the package database. Packages should not contain spaces
- # in them. Normally this type of problem results from a command line typo.
- if [ "$(echo $STRING | cut -b 1)" = "-" ]; then
- STRING="malformed-package-name-detected"
- fi
- echo $STRING
-}
-
# Conversion to 'comm' utility by Mark Wisdom.
# is pretty nifty! :^)
remove_packages() {
- for PKGLIST in $*
+ for PKGLIST in $*
do
PKGNAME=$(pkgbase $PKGLIST)
echo
@@ -285,19 +293,17 @@ remove_packages() {
# be removed. If you want to remove them all, you'll need to run
# removepkg again until it removes all the same-named packages.
if [ ! -e $ADM_DIR/packages/$PKGNAME ]; then
- SHORT="$(package_name $PKGNAME)"
- for long_package in $ADM_DIR/packages/${PKGNAME}* ; do
- if [ "$SHORT" = "$(package_name $long_package)" ]; then
- PKGNAME="$(basename $long_package)"
- fi
- done
- fi
-
- if [ ! -e $ADM_DIR/packages/$PKGNAME ]; then
- long_package=$(ls -1 $ADM_DIR/packages/${PKGNAME}* | grep -m 1 "^${PKGNAME}-[^-]*-[^-]*-[^-]*$")
- if [ -e "$long_package" ]; then
- PKGNAME=$(basename $long_package)
+ # Short name not found - finally try looking for full name - e.g. foo-1.0-arm-1
+ pushd $ADM_DIR/packages > /dev/null
+ # Don't set PKGNAME if there are no matches:
+ if [ ! "$( ls -1 $PKGNAME-+([^-])-+([^-])-+([^-]) 2>/dev/null | wc -l )" = "0" ]; then
+ # If there is more than one package with the same name, set PKGNAME to the
+ # most recently installed version. This does not affect the behavior of
+ # upgradepkg, which always removes all other existing versions of the
+ # same package.
+ PKGNAME=$( ls -1t $PKGNAME-+([^-])-+([^-])-+([^-]) 2> /dev/null | head -n1 )
fi
+ popd > /dev/null
fi
if [ -r $ADM_DIR/packages/$PKGNAME ]; then
@@ -392,4 +398,3 @@ else
fi
remove_packages $*
-