diff --git a/convert32pkg.sh b/convert32pkg.sh index 622f909..0431953 100755 --- a/convert32pkg.sh +++ b/convert32pkg.sh @@ -21,8 +21,16 @@ 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 "$pkgarch" in + i?86) pkgarch=x86_64 ;; + *) + echo "Unknown package architecture '$pkgarch'. Can't proceed." 1>&2 + exit 1 + ;; +esac + +pkginfo="$pkginfodir/$pkgname-$pkgver-$pkgarch-$pkgbuild" +pkgscript="$pkgscriptdir/$pkgname-$pkgver-$pkgarch-$pkgbuild" case "$pkgext" in tgz) tool=gzip ;; @@ -37,14 +45,16 @@ trap "rm -rf '$temp'" EXIT cd "$temp" explodepkg "$pkg32" -# Remove all files present in the x86_64 package +# Remove all files present in the 64bit package if [ "$pkg64" ]; then + echo + echo "Removing files:" $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 + echo "Package '$pkgname-$pkgver-$pkgarch-$pkgbuild' is not installed. Can't proceed." 1>&2 exit 1 fi @@ -54,24 +64,29 @@ else else TRIGGER="FILE LIST:" fi + + echo + echo "Removing files:" 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 +echo +echo "Empty directories:" +find . -mindepth 1 -type d -empty -print -delete -# Remove all symlinks present in the x86_64 package +# Remove all symlinks present in the 64bit 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 + echo "Failed to extract install/doinst.sh from '$pkg64'. Can't proceed." 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 + echo "Package '$pkgname-$pkgver-$pkgarch-$pkgbuild' is installed but has no installation script. Can't proceed." 1>&2 exit 1 fi cp "$pkgscript" install/doinst.64 @@ -80,10 +95,25 @@ if [ -f install/doinst.sh ]; then # 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 + echo + echo "Removed lines in doinst.sh:" + fgrep -xf install/doinst install/doinst.sh || true + + # Remove all symlinks present in the 64bit package + fgrep -vxf install/doinst install/doinst.sh > install/doinst.sh.new || true 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" +# Rename package in slack-desc +if [ -f install/slack-desc ]; then + sed -i -e '/^\$\|#\| *|/!s/^[^:]*:/convert32-&/' install/slack-desc +fi + +if ! find . | grep -v '^.$\|^./install' > /dev/null; then + echo + echo "Package is empty. Not running makepkg." 1>&2 + exit 0 +fi + +makepkg -l n -c n "$OLDPWD/convert32-$pkgname-$pkgver-$pkgarch-$pkgbuild.$pkgext" diff --git a/massconvert32.sh b/massconvert32.sh new file mode 100755 index 0000000..710be93 --- /dev/null +++ b/massconvert32.sh @@ -0,0 +1,49 @@ +#!/bin/sh -e + +# DISCLAIMER +# Don't ever think of installing every single package generated with this script. +# While it *should* not cause any problems, doing so is simply overkill, and not recommended in the least. + +if [ "$#" -lt 2 ]; then + echo "Usage: $0 " 1>&2 + exit 1 +fi + +scriptdir="$(realpath "$(dirname "$0")")" + +slackware="$1" +slackware64="$2" + +find "$slackware" -type f -name "*.t?z" -printf '%P\n' | sort | while read -r pkg; do + # 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?')" + + case "$pkgarch" in + i?86) pkgarch=x86_64 ;; + *) continue ;; + esac + + pkg64="$(dirname "$pkg")/$pkgname-$pkgver-$pkgarch-$pkgbuild.$pkgext" + + if [ ! -f "$slackware64/$pkg64" ]; then + continue + fi + + rpkg="$(realpath "$slackware/$pkg")" + rpkg64="$(realpath "$slackware64/$pkg64")" + + mkdir -p "$(dirname "$pkg")" + + ( cd "$(dirname "$pkg")" + "$scriptdir/convert32pkg.sh" "$rpkg" "$rpkg64" + ) +done + +# if [ ! "$(tar tf "convert32-$pkgname-$pkgver-$pkgarch-$pkgbuild.$pkgext" | grep -v '^./\|^install/')" ]; then +# rm -f "convert32-$pkgname-$pkgver-$pkgarch-$pkgbuild.$pkgext" +# fi