#!/bin/bash
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: bin/sde-check-package
|
|
# Copyright (C) 2009 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
#Description: Checks for possible updates of a list of packages
|
|
#Alias: pkg ver version
|
|
|
|
[ -n "$SDEROOT" ] ||
|
|
export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
|
|
|
|
. "$SDEROOT/lib/libsde.in"
|
|
. "$SDEROOT/lib/sde-package.in"
|
|
|
|
cachedir="$SDEROOT/tmp/checkver"
|
|
|
|
check_usage() {
|
|
local progname=$(echo ${0##*/} | tr '-' ' ')
|
|
|
|
[ $# -eq 0 ] || echo_error "$@"
|
|
cat <<-EOT
|
|
Usage: $progname <pkg>*
|
|
EOT
|
|
|
|
exit 1
|
|
}
|
|
|
|
# parse arguments
|
|
shortopts='?'
|
|
longopts='help'
|
|
options=$(getopt -o "$shortopts" -l "$longopts" -- "$@")
|
|
[ $? -eq 0 ] || check_usage
|
|
|
|
eval set -- "$options"
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--help)
|
|
check_usage
|
|
;;
|
|
--)
|
|
shift; break
|
|
;;
|
|
-*)
|
|
check_usage "$1: Not implemented"
|
|
;;
|
|
*)
|
|
break
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# extract packages list
|
|
#
|
|
pkgs=
|
|
while [ $# -gt 0 ]; do
|
|
x=$(package_parse "$1" | tr '\n' ' ')
|
|
if [ -n "$x" ]; then
|
|
pkgs="$pkgs $x"
|
|
else
|
|
check_usage "$1: Invalid package"
|
|
fi
|
|
shift
|
|
done
|
|
|
|
[ -n "$pkgs" ] || check_usage
|
|
|
|
check_package_update() {
|
|
local pkg="$1" ver="$2" file="$3" dump="$4"
|
|
local prefix= suffix= matches= found=
|
|
|
|
# case 1, version is obvious part of the name
|
|
if expr "$file" : ".*${ver//\./\\.}" > /dev/null; then
|
|
prefix="${file%$ver*}"
|
|
suffix="${file#$prefix$ver}"
|
|
fi
|
|
|
|
# case 2, known suffix and a dash separating prefix and version
|
|
if [ -z "$prefix$suffix" ]; then
|
|
suffix='\.tar\.\(gz\|bz2\)'
|
|
prefix=$(echo "$file" | sed -n -e "s,^\(.*-\)\([0-9].*\)$suffix\$,\1,p")
|
|
|
|
[ -n "$prefix" ] || suffix=
|
|
fi
|
|
|
|
if [ -n "$prefix$suffix" ]; then
|
|
# if we have a prefix or suffix at this point
|
|
found=$(sed -n -e "s,^$prefix\([0-9].*\)$suffix\$,\1,p" "$dump" | sort -u)
|
|
else
|
|
found=
|
|
fi
|
|
|
|
if [ -n "$found" ]; then
|
|
found=$("$versionsort" $found | tac | sed -e "s|^${ver//./\.}\$|*$ver*|" | tr '\n' ' ')
|
|
echo "$pkg ($ver) $file ($url) $found"
|
|
else
|
|
echo_warning "$pkg ($ver) $file ($url) nothing found."
|
|
fi
|
|
}
|
|
|
|
download_url_dump() {
|
|
lock "$dump"
|
|
[ -e "$dump" ] ||
|
|
"$SDEROOT/lib/sde-download/dump-tokenized.sh" "$url" > "$dump" 2> "$dump.stderr"
|
|
unlock "$dump"
|
|
}
|
|
|
|
check_package() {
|
|
local repo="${1%/*}" pkg="${1#*/}"
|
|
local desc="$SDEROOT/package/$repo/$pkg/$pkg.desc"
|
|
|
|
local cvurl=$(package_desc_extract "$desc" CV-URL)
|
|
local ver=$(package_desc_extract "$desc" V)
|
|
|
|
local x= y= file= url= protocol= dump=
|
|
|
|
while read x file url; do
|
|
case "$url" in
|
|
-!*|!*)
|
|
file="${url##*/}"
|
|
url=$(echo "$url" | sed -e 's,^-\?!,,' -e 's,/[^/]*$,/,')
|
|
;;
|
|
-*)
|
|
url="${url#-}"
|
|
;;
|
|
esac
|
|
|
|
if [ -n "$cvurl" ]; then
|
|
url="$cvurl"
|
|
elif [ -s "$SDEROOT/etc/check_package.sed" ]; then
|
|
# translate
|
|
url=$(echo "$url" | sed -f "$SDEROOT/etc/check_package.sed")
|
|
fi
|
|
|
|
protocol="${url%%:*}"
|
|
dump=$(echo "$url.out" | tr '?&:/ ' '_____')
|
|
dump="$cachedir/$dump"
|
|
|
|
case "$protocol" in
|
|
http|https|ftp)
|
|
download_url_dump
|
|
;;
|
|
sourceforge)
|
|
url="http://sourceforge.net/projects/${url#sourceforge://}files/"
|
|
download_url_dump
|
|
;;
|
|
*)
|
|
echo_warning "$pkg: $protocol not supported."
|
|
continue
|
|
;;
|
|
esac
|
|
|
|
if [ -s "$dump" ]; then
|
|
check_package_update "$pkg" "$ver" "$file" "$dump"
|
|
else
|
|
echo_warning "$pkg ($ver) $file ($url) empty output."
|
|
fi
|
|
done < <(package_desc_extract "$desc" D)
|
|
}
|
|
|
|
mkdir -p "$cachedir" || exit $?
|
|
|
|
# compile vsersionsort is missing
|
|
#
|
|
versionsort="$SDEROOT/bin/versionsort"
|
|
versionsort_c="$SDEROOT/src/tools-source/versionsort.c"
|
|
if [ "$versionsort_c" -nt "$versionsort" ]; then
|
|
gcc -o "$versionsort" -Os -W -Wall "$versionsort_c" || exit $?
|
|
fi
|
|
|
|
trap ':' 'INT'
|
|
|
|
for x in $pkgs; do
|
|
check_package "$x" &
|
|
done < /dev/null
|
|
wait
|