|
|
|
#!/bin/sh -e
|
|
|
|
|
|
|
|
pkginfodir='/var/log/packages/'
|
|
|
|
pkgscriptdir='/var/log/scripts/'
|
|
|
|
|
|
|
|
if [ "$#" -lt 1 ]; then
|
|
|
|
echo "Usage: $0 <package32> [package64]" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
pkg32="$(realpath "$1")"
|
|
|
|
unset pkg64
|
|
|
|
[ "$2" ] && pkg64="$(realpath "$2")"
|
|
|
|
|
|
|
|
# Extract all package info
|
|
|
|
# See /sbin/installpkg
|
|
|
|
pkgbase="$(echo "$pkg32" | sed -e 's?.*/??;s/\.t[bglx]z$//')"
|
|
|
|
pkgext="$(echo "$pkg32" | 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"
|
|
|
|
|
|
|
|
case "$pkgext" in
|
|
|
|
tgz) tool=gzip ;;
|
|
|
|
tbz) tool=bzip2 ;;
|
|
|
|
tlz) tool=lzma ;;
|
|
|
|
txz) tool=xz ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
temp="$(mktemp -d)"
|
|
|
|
trap "rm -rf '$temp'" EXIT
|
|
|
|
|
|
|
|
cd "$temp"
|
|
|
|
explodepkg "$pkg32"
|
|
|
|
|
|
|
|
# Remove all files present in the x86_64 package
|
|
|
|
if [ "$pkg64" ]; then
|
|
|
|
$tool -cd "$pkg64" | tar-1.13 t | grep -v "^install/" | while read -r file; do
|
|
|
|
rm -vf "./$file" 2> /dev/null || true
|
|
|
|
done
|
|
|
|
else
|
|
|
|
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
|
|
|
|
sed -n "/$TRIGGER/,/^$/p" "$pkginfo" | fgrep -v "FILE LIST:" | grep -v "^install/" | while read -r file; do
|
|
|
|
rm -vf "./$file" 2> /dev/null || true
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Clean empty directories
|
|
|
|
find . -mindepth 1 -type d -empty -delete
|
|
|
|
|
|
|
|
# Remove all symlinks present in the x86_64 package
|
|
|
|
if [ -f install/doinst.sh ]; then
|
|
|
|
if [ "$pkg64" ]; then
|
|
|
|
if ! $tool -cd "$pkg64" | tar-1.13 xO install/doinst.sh > install/doinst.64; then
|
|
|
|
echo "Failed to extract install/doinst.sh from '$pkg64'. Aborting." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ ! -f "$pkgscript" ]; then
|
|
|
|
echo "Package '$pkgname-$pkgver-x86_64-$pkgbuild' is installed but has no installation script. Can't proceed." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cp "$pkgscript" install/doinst.64
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract all lines treating with symlinks. See /sbin/removepkg
|
|
|
|
sed -n -e 's,^[ ]*( [ ]*cd[ ]* .* [ ]*; [ ]*\(rm\|ln\) [ ]*-\(rf\|sf\)[ ]* .* [ ]*)[ ]*$,&,p' -e 's,^[ ]*config .*[ ]*,&,p' install/doinst.64 > install/doinst
|
|
|
|
|
|
|
|
# Remove all symlinks present in the x86_64 package
|
|
|
|
fgrep -vxf install/doinst install/doinst.sh > install/doinst.sh.new
|
|
|
|
mv install/doinst.sh.new install/doinst.sh
|
|
|
|
rm -f install/doinst install/doinst.64
|
|
|
|
fi
|
|
|
|
|
|
|
|
makepkg -l y -c n "$OLDPWD/convert32-$pkgname-$pkgver-x86_64-$pkgbuild.$pkgext"
|