mirror of
https://github.com/moparisthebest/pacman
synced 2024-10-31 15:45:03 -04:00
contrib/wget-xdelta.sh: Replaced with an improved version.
Signed-off-by: Andrew Fyfe <andrew@neptune-one.net>
This commit is contained in:
parent
b757cc9414
commit
a78ad0d38d
@ -1,47 +1,70 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
o=$(basename $1)
|
|
||||||
u=$2
|
if [ -r "/etc/makepkg.conf" ]; then
|
||||||
CARCH="i686" # Hmmm where to get this from? /etc/makepkg.conf?
|
source /etc/makepkg.conf
|
||||||
cached_file=""
|
else
|
||||||
# Only check for pkg.tar.gz files in the cache, we download db.tar.gz as well
|
echo "wget-xdelta: Unable to find makepkg.conf"
|
||||||
if [[ "$o" =~ "pkg.tar.gz" ]] # if $o contains pkg.tar.gz
|
exit 1
|
||||||
then
|
fi
|
||||||
pkgname=${o%-*-[0-9]-${CARCH}.pkg.tar.gz.part} # Parse out the package name
|
|
||||||
newend=${o##$pkgname-} # Parse out everything following pkgname
|
if [ -r ~/.makepkg.conf ]; then
|
||||||
new_version=${newend%-${CARCH}.pkg.tar.gz.part} # Strip off .pkg.tar.gz.part leaving version
|
source ~/.makepkg.conf
|
||||||
url=${u%/*}
|
fi
|
||||||
for cached_file in $(ls -r /var/cache/pacman/pkg/${pkgname}-*-${CARCH}.pkg.tar.gz 2>/dev/null); do
|
|
||||||
# just take the first one, by name. I suppose we could take the latest by date...
|
out_file=$(basename $1)
|
||||||
oldend=${cached_file##*/$pkgname-}
|
file_url=$2
|
||||||
old_version=${oldend%-${CARCH}.pkg.tar.gz}
|
|
||||||
if [ "$old_version" = "$new_version" ]; then
|
if ! [[ "$out_file" =~ "pkg.tar.gz" ]]; then
|
||||||
# We already have the new version in the cache! Just continue the download.
|
# If it's not a package file download as normal and exit.
|
||||||
cached_file=""
|
#wget --passive-ftp -c -O "$out_file" "$file_url"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# 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
|
||||||
|
for file in $(ls -r /var/cache/pacman/pkg/${pkgname}-*-*{,-$CARCH}$PKGEXT 2>/dev/null); do
|
||||||
|
[[ "$file" =~ "$CARCH" ]] && arch="-$CARCH" || arch=""
|
||||||
|
check_version=$(echo $file | \
|
||||||
|
sed "s|^.*/${pkgname}-\([[:alnum:]_\.]*-[[:alnum:]_\.]*\)${arch}$PKGEXT$|\1|" | \
|
||||||
|
grep -v "^/var/cache/pacman/pkg")
|
||||||
|
|
||||||
|
[ "$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
|
fi
|
||||||
break
|
|
||||||
done
|
done
|
||||||
fi
|
|
||||||
if [ "$cached_file" != "" ]; then
|
if [ "$old_version" != "" -a "$old_version" != "$new_version" ]; then
|
||||||
# Great, we have a cached file, now calculate a patch name from it
|
# Great, we have a cached file, now calculate a patch name from it
|
||||||
delta_name=$pkgname-${old_version}_to_${new_version}-${CARCH}.delta
|
delta_name="$pkgname-${old_version}_to_${new_version}-${CARCH}.delta"
|
||||||
# try to download the delta
|
|
||||||
if wget --passive-ftp -c $url/$delta_name; then
|
echo "wget-xdelta: Attempting to download delta $delta_name..." >&2
|
||||||
# Now apply the delta to the cached file to produce the new file
|
if wget --passive-ftp -c "$base_url/$delta_name"; then
|
||||||
echo Applying delta...
|
echo "wget-xdelta: Applying delta..."
|
||||||
if xdelta patch $delta_name $cached_file $o; then
|
if xdelta patch "$delta_name" "$old_file" "$out_file"; then
|
||||||
# Remove the delta now that we are finished with it
|
echo "wget-xdelta: Delta applied successfully!"
|
||||||
|
rm "$delta_name"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "wget-xdelta: Failed to apply delta!"
|
||||||
rm $delta_name
|
rm $delta_name
|
||||||
else
|
|
||||||
# Hmmm. xdelta failed for some reason
|
|
||||||
rm $delta_name
|
|
||||||
# just download the file
|
|
||||||
wget --passive-ftp -c -O $o $u
|
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# just download the file
|
|
||||||
wget --passive-ftp -c -O $o $u
|
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# just download the file
|
|
||||||
wget --passive-ftp -c -O $o $u
|
|
||||||
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user