From b292fd982a1ce0e37b192709626fbfb7d7221599 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Sat, 14 Jan 2017 21:03:51 +0100 Subject: [PATCH] Add script to convert i?86 packages to compat32 --- convert32pkg.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 convert32pkg.sh diff --git a/convert32pkg.sh b/convert32pkg.sh new file mode 100755 index 0000000..db9fa67 --- /dev/null +++ b/convert32pkg.sh @@ -0,0 +1,56 @@ +#!/bin/sh -e + +pkginfodir='/var/log/packages/' +pkgscriptdir='/var/log/scripts/' + +if [ "$#" -lt 1 ]; then + echo "Usage: $0 " 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" +)