* updated pyxdg (0.19 -> 0.28)
[t2sde.git] / scripts / Update-Pkg
blobe1f1b4cd49ec64cf3fb854dab830a2f928a2bb52
1 #!/usr/bin/env bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # T2 SDE: scripts/Update-Pkg
4 # Copyright (C) 2004 - 2024 The T2 SDE Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 # Extract packagename and version number from the script arguments.
14 pkg="$1"; shift
15 ver="$1"; shift
17 # Remote URL
19 if [[ "$pkg" == http*://* ]]; then
20 curl $pkg/ | tr '"' '\n' | grep "tar.[^.<>]*$"| sort -u |
21 sed 's/\.tar.*//'|
22 while read p; do
23 scripts/Update-Pkg $p
24 done
26 exit # TODO: return any update download error
29 # The script also supports the package name and version separated by a '-',
30 # '_' or '.'. In this case they have to be separated from each other.
31 if [ -z "$ver" ]; then
32 ver=${pkg/*-/}
33 pkg=${pkg%-$ver}
34 if [ "$ver" == "$pkg" ]; then
35 ver=${pkg/*_/}
36 pkg=${pkg%_$ver}
38 if [ "$ver" == "$pkg" ]; then
39 pkg=${pkg/.*/}
40 ver=${ver#$pkg.}
42 [ "$ver" == "$pkg" ] && unset ver
45 # Check if both package name and version have been extracted from the
46 # commandline arguments. If not the script was called with invalid
47 # arguments, show the usage.
48 if [ -z "$pkg" -o -z "$ver" ]; then
49 echo "Usage: $0 pkg ver, pkg-ver, pkg_ver or pkg.ver, or URL"
50 echo ""
51 echo "Updating a package to a new versions."
52 echo ""
53 echo " pkg Packagename to be updated"
54 echo " ver New version number for the package"
55 echo " ver=refresh makes it just add checksums"
56 echo " url extract pkg and version from tarballs"
57 echo ""
58 echo "For detailed information on how to update packages"
59 echo "to new versions, please have a look at the online"
60 echo "T2 documentaion."
61 exit
64 # Make sure any diff files from previous runs are removed.
65 rm -f $$.diff
67 # Only package names in lowercase are supported. As an additional
68 # service any package names supplied in capitols will be converted
69 # to lowercase.
70 pkg=`echo "$pkg" | tr A-Z a-z`
72 # Of course we can only update packages we know about.
73 if [ -d package/*/$pkg ]; then
74 if [ "$ver" != "refresh" ]; then
75 # The package exists so now update the package descriptor
76 # for the given package to the new version. Luckily we have
77 # a script for that too :-)
78 scripts/Create-PkgUpdPatch "$pkg" "$ver" | tee $$.diff
79 patch -p1 < $$.diff
80 rm -f $$.diff
83 # Step 2: Use the modified package descriptor to download
84 # the package. Again, nothing more that calling an existing
85 # script.
86 scripts/Download $pkg || exit 1
88 # Third and final step is updating the checksum for the
89 # new download.
90 scripts/Create-CkSumPatch "$pkg" | patch -p0
91 else
92 # Oeps, the given package name does not exist.
93 echo "ERROR: package $pkg doesn't exist"
94 # As an extra service for the user a list possibilities is
95 # presented with packages closely matching the given package
96 # name.
97 pkg=`echo "$pkg" | tr '\-_.' '***'`
98 echo `echo package/*/*$pkg*/ | tr ' ' '\n' | grep -v '*' | cut -d'/' -f3`