Browse Source

Allow usage of packages instead of installed info in /var/log for convert32pkg.sh

master
mid-kid 8 years ago
parent
commit
8f1f7dabfd
  1. 95
      convert32pkg.sh

95
convert32pkg.sh

@ -4,21 +4,18 @@ pkginfodir='/var/log/packages/'
pkgscriptdir='/var/log/scripts/' pkgscriptdir='/var/log/scripts/'
if [ "$#" -lt 1 ]; then if [ "$#" -lt 1 ]; then
echo "Usage: $0 <package>" 1>&2 echo "Usage: $0 <package32> [package64]" 1>&2
exit 1 exit 1
fi fi
pkg="$1" pkg32="$(realpath "$1")"
unset pkg64
temp="$(mktemp -d)" [ "$2" ] && pkg64="$(realpath "$2")"
trap "rm -rf '$temp'" EXIT
tar xf "$pkg" -C "$temp"
# Extract all package info # Extract all package info
# See /sbin/installpkg # See /sbin/installpkg
pkgbase="$(echo "$pkg" | sed -e 's?.*/??;s/\.t[bglx]z$//')" pkgbase="$(echo "$pkg32" | sed -e 's?.*/??;s/\.t[bglx]z$//')"
pkgext="$(echo "$pkg" | sed -e 's?.*/??;s/.*\.\(t[bglx]z\)$/\1/')" pkgext="$(echo "$pkg32" | sed -e 's?.*/??;s/.*\.\(t[bglx]z\)$/\1/')"
pkgname="$(echo "$pkgbase" | sed -e 's?-[^-]*-[^-]*-[^-]*$??')" pkgname="$(echo "$pkgbase" | sed -e 's?-[^-]*-[^-]*-[^-]*$??')"
pkgver="$(echo "$pkgbase" | sed -e 's?.*-\([^-]*\)-[^-]*-[^-]*$?\1?')" pkgver="$(echo "$pkgbase" | sed -e 's?.*-\([^-]*\)-[^-]*-[^-]*$?\1?')"
pkgarch="$(echo "$pkgbase" | sed -e 's?.*-[^-]*-\([^-]*\)-[^-]*$?\1?')" pkgarch="$(echo "$pkgbase" | sed -e 's?.*-[^-]*-\([^-]*\)-[^-]*$?\1?')"
@ -26,31 +23,67 @@ pkgbuild="$(echo "$pkgbase" | sed -e 's?.*-[^-]*-[^-]*-\([^-]*\)$?\1?')"
pkginfo="$pkginfodir/$pkgname-$pkgver-x86_64-$pkgbuild" pkginfo="$pkginfodir/$pkgname-$pkgver-x86_64-$pkgbuild"
pkgscript="$pkgscriptdir/$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 case "$pkgext" in
if fgrep "./" "$pkginfo" 1> /dev/null 2>&1; then tgz) tool=gzip ;;
TRIGGER="^\.\/" 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 else
TRIGGER="FILE LIST:" 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 fi
# Remove all files present in the x86_64 package # Clean empty directories
sed -n "/$TRIGGER/,/^$/p" "$pkginfo" | fgrep -v "FILE LIST:" | grep -v "^install/" | sort -u | while read -r file; do find . -mindepth 1 -type d -empty -delete
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 # Remove all symlinks present in the x86_64 package
# See /sbin/removepkg if [ -f install/doinst.sh ]; then
sed -n -e 's,^[ ]*( [ ]*cd[ ]* .* [ ]*; [ ]*\(rm\|ln\) [ ]*-\(rf\|sf\)[ ]* .* [ ]*)[ ]*$,&,p' -e 's,^[ ]*config .*[ ]*,&,p' "$pkgscript" > "$temp/install/doinst" if [ "$pkg64" ]; then
fgrep -vxf "$temp/install/doinst" "$temp/install/doinst.sh" > "$temp/install/doinst.sh.new" if ! $tool -cd "$pkg64" | tar-1.13 xO install/doinst.sh > install/doinst.64; then
mv "$temp/install/doinst.sh.new" "$temp/install/doinst.sh" echo "Failed to extract install/doinst.sh from '$pkg64'. Aborting." 1>&2
rm -f "$temp/install/doinst" exit 1
fi
( cd "$temp" else
makepkg -l y -c n "$OLDPWD/$pkgname-compat32-$pkgver-x86_64-$pkgbuild.$pkgext" 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"

Loading…
Cancel
Save