#!/bin/sh -e pkginfodir='/var/log/packages/' pkgscriptdir='/var/log/scripts/' if [ "$#" -lt 1 ]; then echo "Usage: $0 [package64]" 1>&2 exit 1 fi pkg32="$(realpath "$1")" unset pkg64 [ "$2" ] && pkg64="$(realpath "$2")" # Extract all package info # See /sbin/installpkg 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?')" pkgbuild="$(echo "$pkgbase" | sed -e 's?.*-[^-]*-[^-]*-\([^-]*\)$?\1?')" 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 ;; 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 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-$pkgarch-$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 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 echo echo "Empty directories:" find . -mindepth 1 -type d -empty -print -delete # 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'. Can't proceed." 1>&2 exit 1 fi else if [ ! -f "$pkgscript" ]; then 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 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 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 # 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"