source: trunk/base/src/port1.0/portupdatecheck.tcl @ 13463

Last change on this file since 13463 was 13463, checked in by pguyot (Paul Guyot), 15 years ago

Rename url_mod_date to moddate.

  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
1# et:ts=4
2# portupdatecheck.tcl
3#
4# $Id: portupdatecheck.tcl,v 1.2 2005/08/11 02:11:32 pguyot Exp $
5#
6# Copyright (c) 2005 Paul Guyot <pguyot@kallisys.net>,
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are
11# met:
12#
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in the
17#    documentation and/or other materials provided with the distribution.
18# 3. Neither the name of Apple Computer, Inc. nor the names of its
19#    contributors may be used to endorse or promote products derived from
20#    this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33#
34
35package provide portupdatecheck 1.0
36package require portutil 1.0
37
38set com.apple.updatecheck [target_new com.apple.updatecheck updatecheck_main]
39target_runtype ${com.apple.updatecheck} always
40target_state ${com.apple.updatecheck} no
41target_provides ${com.apple.updatecheck} updatecheck
42target_requires ${com.apple.updatecheck} main
43target_prerun ${com.apple.updatecheck} updatecheck_start
44
45set_ui_prefix
46
47# define options
48options updatecheck.url updatecheck.type updatecheck.md5 updatecheck.name
49
50# defaults
51default updatecheck.url {$homepage}
52default updatecheck.type moddate
53default updatecheck.md5 ""
54default updatecheck.name {$name}
55
56proc updatecheck_start {args} {
57        global UI_PREFIX portname portversion portrevision variations portvariants
58   
59        if { ![info exists portvariants] } {
60                set portvariants ""
61
62                set vlist [lsort -ascii [array names variations]]
63
64                # Put together variants in the form +foo+bar for the registry
65                foreach v $vlist {
66                        if { ![string equal $v [option os.platform]] && ![string equal $v [option os.arch]] } {
67                                set portvariants "${portvariants}+${v}"
68                        }
69                }
70        }
71}
72
73proc updatecheck_main {args} {
74        global updatecheck.url updatecheck.type updatecheck.md5 updatecheck.name
75        global portname portpath workpath
76       
77        set updated 0
78
79        set tempfile ${workpath}/updatecheck.TMP
80        set port_moddate [file mtime ${portpath}/Portfile]
81       
82        # set the url depending on the type.
83        if {${updatecheck.type} == "freshmeat"} {
84                set updatecheck.url "http://freshmeat.net/projects-xml/${updatecheck.name}/${updatecheck.name}.xml"
85               
86                if {[catch {curl fetch ${updatecheck.url} $tempfile} error]} {
87                        ui_error "cannot check if $portname was updated ($error)"
88                } else {
89                        # let's extract the modification date from the file.
90                        set chan [open $tempfile "r"]
91                        set updated -1
92                        while {1} {
93                                set line [gets $chan]
94                                if {[regexp "<date_updated>(.*)</date_updated>" $line line date_string]} {
95                                        if {[catch {set date_updated [clock scan $date_string -gmt 1]} error]} {
96                                                set updated 0
97                                                ui_error "cannot check if $portname was updated (couldn't parse date_updated tag: $error)"
98                                        } else {
99                                                set updated [expr $date_updated > $port_moddate]
100                                        }
101                                        break
102                                }
103                        }
104                        if {$updated < 0} {
105                                ui_error "cannot check if $portname was updated (couldn't find date_updated tag)"
106                        }
107                }               
108        } elseif {${updatecheck.type} == "md5"} {
109                if {[catch {curl fetch ${updatecheck.url} $tempfile} error]} {
110                        ui_error "cannot check if $portname was updated ($error)"
111                } else {
112                        # let's compute the md5 sum.
113                        set dist_md5 [md5 file $tempfile]
114                        if {$dist_md5 != ${updatecheck.md5}} {
115                                ui_debug "md5sum for ${updatecheck.url}: $dist_md5"
116                                set updated 1
117                        }
118                }
119        } else {
120                set port_moddate [file mtime ${portpath}/Portfile]
121                if {[catch {set updated [curl isnewer ${updatecheck.url} $port_moddate]} error]} {
122                        ui_error "cannot check if $portname was updated ($error)"
123                }
124        }
125       
126        file delete -force $tempfile
127
128        if {$updated} {
129                ui_info "$portname seems to have been updated"
130        } else {
131                ui_debug "$portname seems to be up to date"
132        }
133}
Note: See TracBrowser for help on using the repository browser.