Browse Source

Add script to convert i?86 packages to compat32

master
mid-kid 8 years ago
parent
commit
b292fd982a
  1. 56
      convert32pkg.sh

56
convert32pkg.sh

@ -0,0 +1,56 @@
#!/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"
)
Loading…
Cancel
Save