1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs bootstrap.image checksums checksums.md5
4 http.client io.files kernel math.parser splitting urls ;
5 IN: bootstrap.image.download
7 CONSTANT: url URL" http://downloads.factorcode.org/images/master/"
9 : download-checksums ( -- alist )
10 url "checksums.txt" >url derive-url http-get nip
11 lines [ " " split1 ] { } map>assoc ;
13 : file-checksum ( image -- checksum )
14 md5 checksum-file bytes>hex-string ;
16 : download-checksum ( image -- checksum )
17 download-checksums at ;
19 : need-new-image? ( image -- ? )
21 [ [ file-checksum ] [ download-checksum ] bi = not ]
25 : verify-image ( image -- )
26 need-new-image? [ "Boot image corrupt" throw ] when ;
28 : download-image ( image -- )
29 [ url swap >url derive-url download ]
33 : maybe-download-image ( image -- ? )
34 dup need-new-image? [ download-image t ] [ drop f ] if ;
36 : download-my-image ( -- )
37 my-boot-image-name maybe-download-image drop ;
39 MAIN: download-my-image