You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.4 KiB
145 lines
4.4 KiB
8 years ago
|
#!/bin/sh -e
|
||
|
|
||
|
pkginfodir='/var/log/packages/'
|
||
|
pkgscriptdir='/var/log/scripts/'
|
||
|
|
||
|
if [ "$#" -lt 1 ]; then
|
||
8 years ago
|
echo "Usage: $0 <package32> [package64]" 1>&2
|
||
8 years ago
|
exit 1
|
||
|
fi
|
||
|
|
||
8 years ago
|
pkg32="$(realpath "$1")"
|
||
|
unset pkg64
|
||
|
[ "$2" ] && pkg64="$(realpath "$2")"
|
||
8 years ago
|
|
||
|
# Extract all package info
|
||
|
# See /sbin/installpkg
|
||
8 years ago
|
pkgbase="$(echo "$pkg32" | sed -e 's?.*/??;s/\.t[bglx]z$//')"
|
||
|
pkgext="$(echo "$pkg32" | sed -e 's?.*/??;s/.*\.\(t[bglx]z\)$/\1/')"
|
||
8 years ago
|
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?')"
|
||
|
|
||
8 years ago
|
case "$pkgarch" in
|
||
|
i?86) pkgarch=x86_64 ;;
|
||
|
*)
|
||
8 years ago
|
echo "Unsupported package architecture '$pkgarch'. Can't proceed." 1>&2
|
||
8 years ago
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
pkginfo="$pkginfodir/$pkgname-$pkgver-$pkgarch-$pkgbuild"
|
||
|
pkgscript="$pkgscriptdir/$pkgname-$pkgver-$pkgarch-$pkgbuild"
|
||
8 years ago
|
|
||
8 years ago
|
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"
|
||
|
|
||
8 years ago
|
# Remove all files present in the 64bit package
|
||
8 years ago
|
if [ "$pkg64" ]; then
|
||
8 years ago
|
echo
|
||
|
echo "Removing files:"
|
||
8 years ago
|
$tool -cd "$pkg64" | tar-1.13 t | grep -v '^install/' | while read -r file; do
|
||
|
echo "./$file"
|
||
|
rm -f "./$file" 2> /dev/null || true
|
||
8 years ago
|
done
|
||
8 years ago
|
else
|
||
8 years ago
|
if [ ! -f "$pkginfo" ]; then
|
||
8 years ago
|
echo "Package '$pkgname-$pkgver-$pkgarch-$pkgbuild' is not installed. Can't proceed." 1>&2
|
||
8 years ago
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# See /sbin/removepkg
|
||
8 years ago
|
if fgrep './' "$pkginfo" 1> /dev/null 2>&1; then
|
||
|
TRIGGER='^\.\/'
|
||
8 years ago
|
else
|
||
8 years ago
|
TRIGGER='FILE LIST:'
|
||
8 years ago
|
fi
|
||
8 years ago
|
|
||
|
echo
|
||
8 years ago
|
echo 'Removing files:'
|
||
|
sed -n "/$TRIGGER/,/^$/p" "$pkginfo" | fgrep -v 'FILE LIST:' | grep -v '^install/' | while read -r file; do
|
||
|
echo "./$file"
|
||
|
rm -f "./$file" 2> /dev/null || true
|
||
8 years ago
|
done
|
||
8 years ago
|
fi
|
||
|
|
||
8 years ago
|
# Clean empty directories
|
||
8 years ago
|
echo
|
||
8 years ago
|
echo 'Empty directories:'
|
||
|
find . -type d -empty -print -delete
|
||
8 years ago
|
|
||
8 years ago
|
# Remove all symlinks present in the 64bit package
|
||
8 years ago
|
if [ -f install/doinst.sh ]; then
|
||
|
if [ "$pkg64" ]; then
|
||
|
if ! $tool -cd "$pkg64" | tar-1.13 xO install/doinst.sh > install/doinst.64; then
|
||
8 years ago
|
echo "Failed to extract install/doinst.sh from '$pkg64'. Can't proceed." 1>&2
|
||
8 years ago
|
exit 1
|
||
|
fi
|
||
|
else
|
||
|
if [ ! -f "$pkgscript" ]; then
|
||
8 years ago
|
echo "Package '$pkgname-$pkgver-$pkgarch-$pkgbuild' is installed but has no installation script. Can't proceed." 1>&2
|
||
8 years ago
|
exit 1
|
||
|
fi
|
||
|
cp "$pkgscript" install/doinst.64
|
||
|
fi
|
||
|
|
||
8 years ago
|
# There's some packages that need special treatment
|
||
|
if [ "$pkgname" = 'glib2' -o "$pkgname" = 'cups' -o "$pkgname" = 'sane' ]; then
|
||
|
sed -i -e '/^for file in/,/^done/d' install/doinst.sh
|
||
|
fi
|
||
|
if [ "$pkgname" = 'cups' ]; then
|
||
|
sed -i -e '/^if \[ -e etc\/rc.d\/rc.cups \]; then/,/^fi/d' install/doinst.sh
|
||
|
fi
|
||
|
if [ "$pkgname" = 'eudev' ]; then
|
||
|
sed -i -e '/^if \[ \(-e etc\/rc.d\/rc.udev\|-r etc\/rc.d\/rc.udev.new\) \]; then/,/^fi/d' install/doinst.sh
|
||
|
fi
|
||
|
if [ "$pkgname" = 'dbus' ]; then
|
||
|
sed -i -e '/^if \[ \(-e etc\/rc.d\/rc.messagebus\|-r etc\/rc.d\/rc.messagebus.new\) \]; then/,/^fi/d' install/doinst.sh
|
||
|
fi
|
||
|
|
||
7 years ago
|
# Extract all lines treating with symlinks or config files. See /sbin/removepkg
|
||
|
sed -n -e 's,^[ ]*( [ ]*cd[ ]* .* [ ]*; [ ]*\(rm\|ln\) [ ]*-\(rf\|sf\)[ ]* .* [ ]*)[ ]*$,&,p' \
|
||
|
-e 's,^[ ]*config .*[ ]*$,&,p' install/doinst.64 > install/doinst
|
||
8 years ago
|
rm install/doinst.64
|
||
8 years ago
|
|
||
8 years ago
|
echo
|
||
8 years ago
|
echo 'Removed lines in doinst.sh:'
|
||
|
if [ -s install/doinst ]; then
|
||
|
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
|
||
8 years ago
|
|
||
8 years ago
|
# If the resulting doinst.sh is empty, remove it.
|
||
|
if [ ! -s install/doinst.sh ]; then
|
||
|
rm install/doinst.sh
|
||
|
fi
|
||
|
fi
|
||
|
rm install/doinst
|
||
8 years ago
|
fi
|
||
|
|
||
8 years ago
|
# 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
|
||
8 years ago
|
echo 'Package is empty. Not running makepkg.' 1>&2
|
||
8 years ago
|
exit 0
|
||
|
fi
|
||
|
|
||
|
makepkg -l n -c n "$OLDPWD/convert32-$pkgname-$pkgver-$pkgarch-$pkgbuild.$pkgext"
|