2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: bin/sde-update-package
6 # Copyright (C) 2006 - 2008 The OpenSDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- SDE-COPYRIGHT-NOTE-END ---
16 #Description: Updates a package to a new upstream version
20 export SDEROOT
=$
( cd "${0%/*}/.."; pwd -P )
22 .
"$SDEROOT/lib/libsde.in"
23 .
"$SDEROOT/lib/sde-package.in"
26 local progname
=${0##*/}
28 Usage: ${progname//-/ } [--location <url>] [<package>] [<version>]
29 Updates a package (which is autodetected if you are on it) to a
30 given version, or simply download and regenerate checksums.
31 Using --location you are able to specify which will be the new
32 download location for this update.
34 ${progname//-/ } [--no-location] --md5 <url> (Alias: up)
35 Updates a set of packages based on a remote .md5 file
36 Using --no-location you tell the tool to not assume the download
37 location of the md5 file for the updates but keep their individual
43 longopts
='help,location:,no-location,md5:'
44 options
=$
( getopt
-o "$shortopts" -l "$longopts" -- "$@" )
50 # load new arguments list
51 eval set -- "$options"
57 while [ $# -gt 0 ]; do
74 *) echo_abort
1 "Unknown argument '$1', aborting."
79 update_patch_package
() {
80 local descfile
="$1" ver
="$2" location
="$3"
82 local tmpfile
=$
( mktemp
)
84 oldver
=$
( sed -n -e 's,^\[V\][ \t]\+\([^ \t]\+\)[ \t]*,\1,p' "$descfile" |
head -n 1 )
85 echo_info
"$pkg ($oldver -> $ver)"
87 gawk
-f $SDEROOT/lib
/sde-package
/package-update.
awk -v "ver=$ver" -v "location=$location" "$descfile" > $tmpfile
88 if diff -u $descfile $tmpfile; then
89 echo_warning
"No change detected."
91 cp $tmpfile "$descfile"
97 local pkg
="$1" ver
="$2" location
="$3"
98 local confdir
=$
( package_confdir
"$pkg" )
99 local descfile
="${confdir}/${pkg}.desc"
102 if [ -z "$confdir" -o ! -f "$descfile" ]; then
103 echo_error
"Package '$pkg' doesn't exist."
105 elif [ -z "$ver" ]; then
106 echo_info
"Updating checksum for $pkg."
108 update_patch_package
"$descfile" "$ver" "$location"
112 .
/bin
/sde-download
-q "$pkg" && .
/lib
/sde-package
/patch-cksum.sh
"$pkg" |
patch -p0
115 update_package_md5
() {
116 local md5
="$1" baseurl
=
117 local nolocation
= location
=
120 echo_info
"Loading MD5 file from '$md5'"
121 if [ "$1" = "--no-location" ]; then
122 nolocation
=yes; shift
123 echo_info
"(Using individual download locations)"
127 $SDEROOT/bin
/sde-parse-md5
"$md5" |
while read pkg ver
file; do
128 if [ -z "$nolocation" ]; then
129 location
="$baseurl/$file";
130 update_package
"$pkg" "$ver" "${location%/*}/"
132 update_package
"$pkg" "$ver"
137 if [ -n "$md5file" ]; then
138 update_package_md5
"$md5file" ${nolocation:+--no-location}
140 elif [ $# -eq 2 ]; then
141 # package and version
142 pkg
="$( echo "$1" | tr A-Z a-z)"
144 elif [ $# -eq 1 ]; then
145 # package or version?
146 pkg
="$( echo "$1" | tr A-Z a-z)"
147 if [ ! -d "$( package_confdir "$pkg" )" ]; then
148 pkg
="$( package_autodetect )"
151 elif [ $# -eq 0 ]; then
152 # can i refresh an autodetected package?
153 pkg
=$
( package_autodetect
)
155 echo_error
"Invalid Syntax."
160 if [ -n "$pkg" ]; then
161 update_package
"$pkg" "$ver" "${location}"
163 echo_error
"I could't guess which package you want to update."