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. 91
      convert32pkg.sh

91
convert32pkg.sh

@ -4,21 +4,18 @@ pkginfodir='/var/log/packages/'
pkgscriptdir='/var/log/scripts/'
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <package>" 1>&2
echo "Usage: $0 <package32> [package64]" 1>&2
exit 1
fi
pkg="$1"
temp="$(mktemp -d)"
trap "rm -rf '$temp'" EXIT
tar xf "$pkg" -C "$temp"
pkg32="$(realpath "$1")"
unset pkg64
[ "$2" ] && pkg64="$(realpath "$2")"
# 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/')"
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?')"
@ -26,31 +23,67 @@ 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
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
fi
# See /sbin/removepkg
if fgrep "./" "$pkginfo" 1> /dev/null 2>&1; then
# See /sbin/removepkg
if fgrep "./" "$pkginfo" 1> /dev/null 2>&1; then
TRIGGER="^\.\/"
else
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
# 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
# Clean empty directories
find . -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"
)
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"

Loading…
Cancel
Save