#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: bin/sde-update-package
|
|
# Copyright (C) 2006 - 2008 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: Updates a package to a new upstream version
|
|
#Alias: pkg
|
|
|
|
[ -n "$SDEROOT" ] ||
|
|
export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
|
|
|
|
. "$SDEROOT/lib/libsde.in"
|
|
. "$SDEROOT/lib/sde-package.in"
|
|
|
|
update_usage() {
|
|
local progname=${0##*/}
|
|
cat <<EOT
|
|
Usage: ${progname//-/ } [--location <url>] [<package>] [<version>]
|
|
Updates a package (which is autodetected if you are on it) to a
|
|
given version, or simply download and regenerate checksums.
|
|
Using --location you are able to specify which will be the new
|
|
download location for this update.
|
|
|
|
${progname//-/ } [--no-location] --md5 <url> (Alias: up)
|
|
Updates a set of packages based on a remote .md5 file
|
|
Using --no-location you tell the tool to not assume the download
|
|
location of the md5 file for the updates but keep their individual
|
|
download locations.
|
|
EOT
|
|
}
|
|
|
|
shortopts=
|
|
longopts='help,location:,no-location,md5:'
|
|
options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
|
|
if [ $? -ne 0 ]; then
|
|
update_usage
|
|
exit -1
|
|
fi
|
|
|
|
# load new arguments list
|
|
eval set -- "$options"
|
|
|
|
location=
|
|
nolocation=
|
|
md5file=
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--help)
|
|
update_usage
|
|
exit 0 ;;
|
|
|
|
--location)
|
|
location=$2; shift
|
|
;;
|
|
--no-location)
|
|
nolocation=yes
|
|
;;
|
|
--md5)
|
|
md5file=$2; shift
|
|
;;
|
|
|
|
--) shift; break ;;
|
|
*) echo_abort 1 "Unknown argument '$1', aborting."
|
|
esac
|
|
shift
|
|
done
|
|
|
|
update_patch_package() {
|
|
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)"
|
|
|
|
gawk -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
|
|
}
|
|
|
|
update_package() {
|
|
local pkg="$1" ver="$2" location="$3"
|
|
local confdir=$( package_confdir "$pkg" )
|
|
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
|
|
update_patch_package "$descfile" "$ver" "$location"
|
|
fi
|
|
|
|
cd "$SDEROOT"
|
|
./bin/sde-download -q "$pkg" && ./lib/sde-package/patch-cksum.sh "$pkg" | patch -p0
|
|
}
|
|
|
|
update_package_md5() {
|
|
local md5="$1" nolocation=
|
|
shift
|
|
|
|
echo_info "Loading MD5 file from '$md5'"
|
|
if [ "$1" = "--no-location" ]; then
|
|
nolocation=yes; shift
|
|
echo_info "(Using individual download locations)"
|
|
fi
|
|
|
|
$SDEROOT/bin/sde-parse-md5 "$md5" | while read pkg ver file; do
|
|
if [ -z "$nolocation" ]; then
|
|
update_package "$pkg" "$ver" "${file%/*}/"
|
|
else
|
|
update_package "$pkg" "$ver"
|
|
fi
|
|
done
|
|
}
|
|
|
|
if [ -n "$md5file" ]; then
|
|
update_package_md5 "$md5file" ${nolocation:+--no-location}
|
|
exit $?
|
|
elif [ $# -eq 2 ]; then
|
|
# package and version
|
|
pkg="$( echo "$1" | tr A-Z a-z)"
|
|
ver="$2"
|
|
elif [ $# -eq 1 ]; then
|
|
# package or version?
|
|
pkg="$( echo "$1" | tr A-Z a-z)"
|
|
if [ ! -d "$( package_confdir "$pkg" )" ]; then
|
|
pkg="$( package_autodetect )"
|
|
ver="$1"
|
|
fi
|
|
elif [ $# -eq 0 ]; then
|
|
# can i refresh an autodetected package?
|
|
pkg=$( package_autodetect )
|
|
else
|
|
echo_error "Invalid Syntax."
|
|
update_usage
|
|
exit 1
|
|
fi
|
|
|
|
if [ -n "$pkg" ]; then
|
|
update_package "$pkg" "$ver" "${location}"
|
|
else
|
|
echo_error "I could't guess which package you want to update."
|
|
update_usage
|
|
exit 2
|
|
fi
|