Browse Source

* improved `sde pkg up` to accept --md5 <url> with an md5sum remote file, which

is used to update the whole set of packages, and assuming that download location
	  for all of them. patch creation reworked using an awk file - needs improvements.


git-svn-id: svn://svn.opensde.net/opensde/opensde/trunk@20674 10447126-35f2-4685-b0cf-6dd780d3921f
misl/sde-wrapper
Alejandro Mery 19 years ago
parent
commit
043618ec06
5 changed files with 110 additions and 178 deletions
  1. +2
    -0
      lib/sde-package.in
  2. +36
    -0
      lib/sde-package/package-update.awk
  3. +0
    -91
      lib/sde-package/patch-update.sh
  4. +72
    -4
      lib/sde-package/update.in
  5. +0
    -83
      lib/sde-package/update.sh

+ 2
- 0
lib/sde-package.in

@ -21,6 +21,8 @@ Usage: sde package (Alias: pkg)
update [<package>] [<version>] (Alias: up)
Updates a package (which is autodetected if you are on it) to a
given version, or simply download and regenerate checksums.
update --md5 <url> (Alias: up)
Updates a set of packages based on a remote .md5 file
new [<repository>/]<package> <download> [...]
Creates a new package based on a template and the given download

+ 36
- 0
lib/sde-package/package-update.awk

@ -0,0 +1,36 @@
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: lib/sde-package/package-update.awk
# Copyright (C) 2007 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 ---
{
if ( $0 ~ /^\[V\]/ ) {
oldver = $2;
gsub( /\./, "\\.", oldver )
$2 = ver
}
else if ( $0 ~ /^\[D\]/ && $3 ~ ".*" oldver ".*" ) {
filename = $3;
gsub( oldver, ver, filename );
if ( filename != $3 ) {
$2 = 0;
$3 = filename;
if ( location == "" )
gsub( oldver, ver, $4 );
else
$4 = location;
}
}
print $0;
}

+ 0
- 91
lib/sde-package/patch-update.sh

@ -1,91 +0,0 @@
#!/bin/bash
#
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: lib/sde-package/patch-update.sh
# Copyright (C) 2006 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE 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 ---
pkg="$1" ; shift
ver="$1" ; shift
if [ -z "$ver" ]; then
ver=${pkg/*-/}
pkg=${pkg%-$ver}
fi
if [ -z "$pkg" -o -z "$ver" ]; then
echo "Usage: $0 pkg ver"
echo " or: $0 pkg-ver"
exit
fi
pkg=`echo $pkg | tr A-Z a-z`
echo "[ $pkg ]" >&2
pkgdir=`echo package/*/$pkg`
if [ ! -d "$pkgdir" ] ; then
echo "Can't find package for '$x'!" >&2
else
oldver="`egrep "^\[(V|VER|VERSION)\] " $pkgdir/$pkg.desc |
tr '\t' ' ' | tr -s ' ' | cut -f2 -d' '`"
tmpfile=`mktemp` ; tmpfile2=`mktemp`
echo "Update patch for $pkg ($pkgdir): $oldver -> $ver"
# [V]
expression="-e 's,^\[\(V\|VER\|VERSION\)\].*,[\1] $ver,'"
# file at [D]
expression="$expression -e '/^\[\(D\|DOWN\|DOWNLOAD\)\]/ s,${oldver//./\\.},$ver,g;'"
# detect download location structure
sed -n -e 's,^\[\(D\|DOWN\|DOWNLOAD\)\].*[ \t]\([^ \t]*\)[ \t]*$,\2,p' $pkgdir/$pkg.desc > $tmpfile
if grep -q "/$oldver/$" $tmpfile; then
# $ver -> /$ver/
oldver="${oldver//./\\.}"
expression="$expression -e '/^\[\(D\|DOWN\|DOWNLOAD\)\]/ s,/$oldver/[ \t]*\$,/$ver/,g;'"
elif [ "$oldver" != "${oldver//-/}" ] && grep -q "/${oldver//-/}/\$" $tmpfile; then
# $ver-$extra -> /$ver/
oldver="${oldver%%-*}"; oldver="${oldver//./\\.}"
ver="${ver%%-*}"
expression="$expression -e '/^\[\(D\|DOWN\|DOWNLOAD\)\]/ s,/$oldver/[ \t]*\$,/$ver/,g;'"
else
# $ver.$extra -> /$ver/
oldver="${oldver%%-*}"
ver="${ver%%-*}"
oldauxver=
auxver=
pattern="[^\.]*"
while [ "${oldver#$oldauxver}" ]; do
eval $( echo "$oldver $ver" | sed -e "s,\($pattern\).* \($pattern\).*,oldauxver=\1 auxver=\2," )
if grep -q "/$oldauxver/\$" $tmpfile; then
oldver="${oldauxver%%-*}"; oldauxver="${oldauxver//./\\.}"
ver="${auxver%%-*}"
expression="$expression -e '/^\[\(D\|DOWN\|DOWNLOAD\)\]/ s,/$oldver/[ \t]*\$,/$ver/,g;'"
break
fi
pattern="$pattern\.\?[^\.]*"
done
fi
# checksum at [D]
expression="$expression -e 's,^\[\(D\|DOWN\|DOWNLOAD\)\] [0-9]\+,[\1] 0,'"
eval "sed $expression $pkgdir/$pkg.desc" > $tmpfile
diff -u ./$pkgdir/$pkg.desc $tmpfile | tee $tmpfile2
[ -s $tmpfile2 ] || echo "Patch for '$x' is empty!" >&2
rm -f $tmpfile $tmpfile2
fi
echo

+ 72
- 4
lib/sde-package/update.in

@ -2,7 +2,7 @@
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: lib/sde-package/update.in
# Copyright (C) 2006 The OpenSDE Project
# Copyright (C) 2006 - 2007 The OpenSDE Project
#
# More information can be found in the files COPYING and README.
#
@ -12,16 +12,84 @@
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---
package_patch_update() {
local descfile="$1" ver="$2" location="$3"
local oldver= sedopt=
local tmpfile=$( mktemp )
oldver=$( sed -n -e 's,^\[V\][ \t]\+\([^ \t]\+\)[ \t]*,\1,p' "$descfile" | head -n 1 )
echo_info "$pkg ($oldver -> $ver)"
awk -f $SDEROOT/lib/sde-package/package-update.awk -v "ver=$ver" -v "location=${location%/*}/" "$descfile" > $tmpfile
if diff -u $descfile $tmpfile; then
echo_warning "No change detected."
else
cp $tmpfile "$descfile"
fi
rm -f $tmpfile
}
package_do_update() {
local pkg="$1" ver="$2" location="$3"
local confdir=$( ls -1d "$SDEROOT/package/"*"/$pkg" 2> /dev/null )
local descfile="${confdir}/${pkg}.desc"
local oldver=
if [ -z "$confdir" -o ! -f "$descfile" ]; then
echo_error "Package '$pkg' doesn't exist."
return 1
elif [ -z "$ver" ]; then
echo_info "Updating checksum for $pkg."
else
package_patch_update "$descfile" "$ver" "$location"
fi
cd "$SDEROOT"
echo_info "Updating '$1' ${2:+to version $2.}"
$SDEROOT/lib/sde-package/update.sh "$1" "${2:-refresh}"
./scripts/Download "$pkg" && ./lib/sde-package/patch-cksum.sh "$pkg" | patch -p0
}
package_update_md5() {
local md5="$1" baseurl=
echo_info "Loading MD5 file from '$md5'"
baseurl="${md5%/*}"
curl "$md5" | while read md5sum file; do
pkg=$( echo "$file" | sed -e 's,-[0-9].*,,' | tr [A-Z] [a-z] )
if [ -z "$pkg" ]; then
echo_arror "Failed to detect package name for '$file'."
continue
fi
case "$pkg" in
exo)
pkg=lib${pkg} ;;
gtk-xfce-engine)
pkg=${pkg}2 ;;
terminal)
pkg=xfce4-terminal ;;
esac
confdir=$( ls -1d $SDEROOT/package/*/$pkg 2> /dev/null || true )
if [ -z "$confdir" -o ! -f "$confdir/$pkg.desc" ]; then
echo_error "Failed to detect package name for '$file'."
continue
fi
ver=$( echo "$file" | sed -n -e 's,.*-\([0-9].*\)\.tar\.bz2,\1,p' )
if [ -z "$ver" ]; then
echo_error "Failed to detect new version for $pkg ($file)."
continue
fi
package_do_update "$pkg" "$ver" "$baseurl/$file"
done
}
package_update() {
local pkg= ver=
if [ $# -eq 2 ]; then
if [ "$1" == "--md5" ]; then
package_update_md5 "$2"
return $?
elif [ $# -eq 2 ]; then
# package and version
pkg="$1"
ver="$2"

+ 0
- 83
lib/sde-package/update.sh

@ -1,83 +0,0 @@
#!/bin/bash
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: lib/sde-package/update.sh
# Copyright (C) 2006 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE 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 ---
# Extract packagename and version number from the script arguments.
pkg="$1" ; shift
ver="$1" ; shift
# The script also supports the package name and version separated by a '-'
# dash. In this case they have to be separated from each other.
if [ -z "$ver" ]; then
ver=${pkg/*-/}
pkg=${pkg%-$ver}
fi
# Check if both package name and version have been extracted from the
# commandline arguments. If not the script was called with invalid
# arguments, show the usage.
if [ -z "$pkg" -o -z "$ver" -o $pkg == $ver ]; then
echo "Usage: $0 pkg ver"
echo " or: $0 pkg-ver"
echo ""
echo "Updating a package to a new versions."
echo ""
echo " pkg Packagename to be updated"
echo " ver New version number for the package"
echo " ver=refresh makes it just add checksums"
echo ""
echo "For detailed information on how to update packages"
echo "to new versions, please have a look at the online"
echo "T2 documentaion."
exit
fi
# Make sure any diff files from previous runs are removed.
rm -f $$.diff
# Only package names in lowercase are supported. As an additional
# service any package names supplied in capitols will be converted
# to lowercase.
pkg=`echo $pkg | tr A-Z a-z`
# Of course we can only update packages we know about.
if [ -d package/*/$pkg ]; then
if [ "$ver" != "refresh" ]; then
# The package exists so now update the package descriptor
# for the given package to the new version. Luckily we have
# a script for that too :-)
$SDEROOT/lib/sde-package/patch-update.sh $pkg $ver | tee $$.diff
patch -p1 < $$.diff
rm -f $$.diff
fi
# Step 2: Use the modified package descriptor to download
# the package. Again, nothing more that calling an existing
# script.
./scripts/Download $pkg
# Third and final step is updating the checksum for the
# new download.
$SDEROOT/lib/sde-package/patch-cksum.sh $pkg | patch -p0
else
# Oeps, the given package name does not exist.
echo "ERROR: package $pkg doesn't exist"
# As an extra service for the user a list possibilities is
# presented with packages closely matching the given package
# name.
pkg=`echo "$pkg" | tr '\-_.' '***'`
echo `echo package/*/*$pkg*/ | tr ' ' '\n' | grep -v '*' | cut -d'/' -f3`
fi

Loading…
Cancel
Save