2010-10-11 19:23:16 -04:00
|
|
|
#!@BASH@
|
2007-06-03 14:14:14 -04:00
|
|
|
|
2010-10-11 19:23:16 -04:00
|
|
|
if [ -r "@sysconfdir@/makepkg.conf" ]; then
|
|
|
|
source @sysconfdir@/makepkg.conf
|
2007-05-30 06:48:18 -04:00
|
|
|
else
|
2007-06-03 14:14:14 -04:00
|
|
|
echo "wget-xdelta: Unable to find makepkg.conf"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -r ~/.makepkg.conf ]; then
|
|
|
|
source ~/.makepkg.conf
|
|
|
|
fi
|
|
|
|
|
|
|
|
out_file=$(basename $1)
|
|
|
|
file_url=$2
|
|
|
|
|
|
|
|
if ! [[ "$out_file" =~ "pkg.tar.gz" ]]; then
|
|
|
|
# If it's not a package file download as normal and exit.
|
|
|
|
#wget --passive-ftp -c -O "$out_file" "$file_url"
|
|
|
|
exit $?
|
2007-05-30 06:48:18 -04:00
|
|
|
fi
|
2007-06-03 14:14:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Get the package name and version
|
|
|
|
[[ "$out_file" =~ "$CARCH" ]] && arch="-$CARCH" || arch=""
|
|
|
|
pkg_data=$(echo $out_file | \
|
|
|
|
sed "s|^\(.*\)-\([[:alnum:]_\.]*-[[:alnum:]_\.]*\)${arch}${PKGEXT}.part|\1 \2|")
|
|
|
|
pkgname=$(echo $pkg_data | cut -d ' ' -f 1)
|
|
|
|
new_version=$(echo $pkg_data | cut -d ' ' -f 2)
|
|
|
|
base_url=${file_url%/*}
|
|
|
|
|
|
|
|
# Look for the last version
|
2010-10-11 19:23:16 -04:00
|
|
|
for file in $(ls -r @localstatedir@/cache/pacman/pkg/${pkgname}-*-*{,-$CARCH}$PKGEXT 2>/dev/null); do
|
2007-06-03 14:14:14 -04:00
|
|
|
[[ "$file" =~ "$CARCH" ]] && arch="-$CARCH" || arch=""
|
|
|
|
check_version=$(echo $file | \
|
|
|
|
sed "s|^.*/${pkgname}-\([[:alnum:]_\.]*-[[:alnum:]_\.]*\)${arch}$PKGEXT$|\1|" | \
|
2010-10-11 19:23:16 -04:00
|
|
|
grep -v "^@localstatedir@/cache/pacman/pkg")
|
2007-06-03 14:14:14 -04:00
|
|
|
|
|
|
|
[ "$check_version" = "" ] && continue
|
|
|
|
|
|
|
|
vercmp=$(vercmp "$check_version" "$old_version")
|
|
|
|
if [ "$check_version" != "$new_version" -a $vercmp -gt 0 ]; then
|
|
|
|
old_version=$check_version
|
|
|
|
old_file=$file
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$old_version" != "" -a "$old_version" != "$new_version" ]; then
|
|
|
|
# Great, we have a cached file, now calculate a patch name from it
|
|
|
|
delta_name="$pkgname-${old_version}_to_${new_version}-${CARCH}.delta"
|
|
|
|
|
|
|
|
echo "wget-xdelta: Attempting to download delta $delta_name..." >&2
|
|
|
|
if wget --passive-ftp -c "$base_url/$delta_name"; then
|
|
|
|
echo "wget-xdelta: Applying delta..."
|
|
|
|
if xdelta patch "$delta_name" "$old_file" "$out_file"; then
|
|
|
|
echo "wget-xdelta: Delta applied successfully!"
|
|
|
|
rm "$delta_name"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "wget-xdelta: Failed to apply delta!"
|
|
|
|
rm $delta_name
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "wget-xdelta: Downloading new package..."
|
|
|
|
wget --passive-ftp -c -O "$out_file" "$file_url"
|
|
|
|
exit $?
|
|
|
|
|
|
|
|
# vim:set ts=4 sw=4 noet:
|