You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.8 KiB
56 lines
1.8 KiB
#!/bin/sh -e
|
|
|
|
pkginfodir='/var/log/packages/'
|
|
pkgscriptdir='/var/log/scripts/'
|
|
|
|
if [ "$#" -lt 1 ]; then
|
|
echo "Usage: $0 <package>" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
pkg="$1"
|
|
|
|
temp="$(mktemp -d)"
|
|
trap "rm -rf '$temp'" EXIT
|
|
|
|
tar xf "$pkg" -C "$temp"
|
|
|
|
# Extract all package info
|
|
# See /sbin/installpkg
|
|
pkgbase="$(echo "$pkg" | sed -e 's?.*/??;s/\.t[bglx]z$//')"
|
|
pkgext="$(echo "$pkg" | sed -e 's?.*/??;s/.*\.\(t[bglx]z\)$/\1/')"
|
|
pkgname="$(echo "$pkgbase" | sed -e 's?-[^-]*-[^-]*-[^-]*$??')"
|
|
pkgver="$(echo "$pkgbase" | sed -e 's?.*-\([^-]*\)-[^-]*-[^-]*$?\1?')"
|
|
pkgarch="$(echo "$pkgbase" | sed -e 's?.*-[^-]*-\([^-]*\)-[^-]*$?\1?')"
|
|
pkgbuild="$(echo "$pkgbase" | sed -e 's?.*-[^-]*-[^-]*-\([^-]*\)$?\1?')"
|
|
|
|
pkginfo="$pkginfodir/$pkgname-$pkgver-x86_64-$pkgbuild"
|
|
pkgscript="$pkgscriptdir/$pkgname-$pkgver-x86_64-$pkgbuild"
|
|
if [ ! -f "$pkginfo" ]; then
|
|
echo "Package $pkgname-$pkgver-x86_64-$pkgbuild is not installed. Can't proceed." 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
# See /sbin/removepkg
|
|
if fgrep "./" "$pkginfo" 1> /dev/null 2>&1; then
|
|
TRIGGER="^\.\/"
|
|
else
|
|
TRIGGER="FILE LIST:"
|
|
fi
|
|
|
|
# Remove all files present in the x86_64 package
|
|
sed -n "/$TRIGGER/,/^$/p" "$pkginfo" | fgrep -v "FILE LIST:" | grep -v "^install/" | sort -u | while read -r file; do
|
|
rm -vf "$temp/$file" 2> /dev/null || true
|
|
done
|
|
find "$temp" -mindepth 1 -type d -empty -delete
|
|
|
|
# Remove all symlinks present in the x86_64 package
|
|
# See /sbin/removepkg
|
|
sed -n -e 's,^[ ]*( [ ]*cd[ ]* .* [ ]*; [ ]*\(rm\|ln\) [ ]*-\(rf\|sf\)[ ]* .* [ ]*)[ ]*$,&,p' -e 's,^[ ]*config .*[ ]*,&,p' "$pkgscript" > "$temp/install/doinst"
|
|
fgrep -vxf "$temp/install/doinst" "$temp/install/doinst.sh" > "$temp/install/doinst.sh.new"
|
|
mv "$temp/install/doinst.sh.new" "$temp/install/doinst.sh"
|
|
rm -f "$temp/install/doinst"
|
|
|
|
( cd "$temp"
|
|
makepkg -l y -c n "$OLDPWD/$pkgname-compat32-$pkgver-x86_64-$pkgbuild.$pkgext"
|
|
)
|
|
|