Sigh, the bugs always appear just /after/ you've sent things.  The
removal method was halfway between the two approaches I'd tried.  The
attached version of the patch should actually work.


-- 
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         ehem+sig...@m5p.com  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445


>From bfd679cbe47b705e0c0b0a7d3034d65906a94460 Mon Sep 17 00:00:00 2001
From: Elliott Mitchell <ehem+deb...@drgnwing.com>
Date: Thu, 31 Mar 2016 17:33:23 -0700
Subject: [PATCH 01/10] Implement catalog of firmware files installed

This allows for targeted removal of downloaded firmware files, instead of
needing to remove the whole directory.  Also pass paths to be removed
through `dpkg-query -S`, increasing safety of removals.  This is much
safer and allows for other features.
---
 debian/firmware-b43-installer.postinst |   33 +++++++++++++++++++++++++-------
 debian/firmware-b43-installer.postrm   |   15 ---------------
 debian/firmware-b43-installer.prerm    |   28 +++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 22 deletions(-)
 delete mode 100644 debian/firmware-b43-installer.postrm
 create mode 100644 debian/firmware-b43-installer.prerm

diff --git a/debian/firmware-b43-installer.postinst b/debian/firmware-b43-installer.postinst
index 0d9c0e1..ed95591 100644
--- a/debian/firmware-b43-installer.postinst
+++ b/debian/firmware-b43-installer.postinst
@@ -25,16 +25,35 @@ fi
 if ! wget --timeout=60 http://www.lwfinger.com/b43-firmware/broadcom-wl-5.100.138.tar.bz2 ; then
 	echo "Some problem occurred during the firmware download. Please check your internet connection." 
 	exit 0
-    else
-	if [ -d /lib/firmware/b43 ]; then
-	   echo "Deleting old extracted firmware..."
-	   rm -rf /lib/firmware/b43
-	fi
 fi
 tar xvjf broadcom-wl-5.100.138.tar.bz2
 cd broadcom-wl-5.100.138/linux
-b43-fwcutter -w "$FIRMWARE_INSTALL_DIR" wl_apsta.o
+if [ -d "${FIRMWARE_INSTALL_DIR}/b43" ]; then
+	echo "Deleting old extracted firmware..."
+	xargs -r -0 -a "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog" dpkg-query -S 2>&1 1>/dev/null | sed -es',[^/]\+,,' | xargs -r rm --
+	rm "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog"
+fi
+mkdir "${FIRMWARE_INSTALL_DIR}/b43" || true
+catalog="${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog"
+retcode=0
+b43-fwcutter -w "${FIRMWARE_INSTALL_DIR}" wl_apsta.o | while read line
+do	echo "${line}"
+	file="${line#Extracting }"
+	if [ "${file}" != "${line}" ]
+	then	if [ "${retcode}" -ne 0 ]
+		then	rm "${FIRMWARE_INSTALL_DIR}/${file}"
+
+		elif [ -z "${FIRMWARE_INSTALL_DIR}/${file}" ] || \
+		! printf %s/%s\\x00 "${FIRMWARE_INSTALL_DIR}" "${file}" >> "${catalog}"
+		then	echo "$0: Failed during extraction of ${file} from ${WL_APSTA}" 1>&2
+			echo "$0: Warning, manual removal/cleaning of ${FIRMWARE_INSTALL_DIR}/b43 may be needed!" 1>&2
+			rm "${FIRMWARE_INSTALL_DIR}/${file}"
+			retcode=1
+		fi
+	fi
+done
 rm -rf $tmp
+[ ${retcode} -eq 0 ] || exit ${retcode}
 }
 
 # check environment
@@ -48,7 +67,7 @@ if [ "$(stat -c %d/%i /)" != "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ];
     echo "No chroot environment found. Starting normal installation"
 fi
      
-     
+
 
 
 # check kernel version
diff --git a/debian/firmware-b43-installer.postrm b/debian/firmware-b43-installer.postrm
deleted file mode 100644
index 339d140..0000000
--- a/debian/firmware-b43-installer.postrm
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-set -e
-
-if [ "$1" = purge ] || [ "$1" = remove ]; then
-
-	if [ -d /lib/firmware/b43 ]; then
-		echo "Deleting old extracted firmware..."
-		rm -rf /lib/firmware/b43/*
-	fi
-fi
-
-#DEBHELPER#
-
-exit 0 
diff --git a/debian/firmware-b43-installer.prerm b/debian/firmware-b43-installer.prerm
new file mode 100644
index 0000000..e60601f
--- /dev/null
+++ b/debian/firmware-b43-installer.prerm
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+#########################################################################
+#$Id$	#
+#########################################################################
+
+FIRMWARE_INSTALL_DIR="/lib/firmware"
+
+#########################################################################
+# stable sections below, not updated for firmware updates		#
+#########################################################################
+
+
+set -e
+
+if [ "$1" = purge ] || [ "$1" = remove ]; then
+	if [ -s "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog" ]; then
+		echo "$0: Deleting installed firmware..." 1>&2
+		xargs -r -0 -a "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog" dpkg-query -S 2>&1 1>/dev/null | sed -es',[^/]\+,,' | xargs -r rm --
+		rm "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43.catalog"
+		rmdir "${FIRMWARE_INSTALL_DIR}/b43" || exit 0
+	fi
+fi
+
+#DEBHELPER#
+
+exit 0
+
-- 
1.7.10.4

Reply via email to