1 ! Copyright (C) 2008 Slava Pestov.
2 ! Copyright (C) 2015 Doug Coleman.
3 ! See http://factorcode.org/license.txt for BSD license.
4 USING: bootstrap.image checksums checksums.openssl io
5 io.directories io.encodings.ascii io.encodings.utf8 io.files
6 io.files.temp io.files.unique io.launcher io.pathnames kernel
7 make math.parser namespaces sequences splitting system unicode ;
8 IN: bootstrap.image.upload
10 SYMBOL: upload-images-destination
11 SYMBOL: build-images-destination
13 : latest-destination ( -- dest )
14 upload-images-destination get
15 "sheeple@downloads.factorcode.org:downloads.factorcode.org/images/master/"
18 : build-destination ( -- dest )
19 build-images-destination get
20 "sheeple@downloads.factorcode.org:downloads.factorcode.org/images/build/"
23 : factor-git-branch ( -- name )
24 image-path parent-directory [
25 { "git" "rev-parse" "--abbrev-ref" "HEAD" }
26 utf8 <process-reader> stream-contents
30 : git-branch-destination ( -- dest )
31 build-images-destination get
32 "sheeple@downloads.factorcode.org:downloads.factorcode.org/images/"
34 factor-git-branch "/" 3append ;
36 : checksums-path ( -- temp ) "checksums.txt" temp-file ;
38 : boot-image-names ( -- seq )
39 image-names [ boot-image-name ] map ;
41 : compute-checksums ( -- )
42 checksums-path ascii [
45 [ openssl-md5 checksum-file bytes>hex-string print ]
50 : scp-name ( -- path ) "scp" ;
52 : upload-images ( -- )
54 \ scp-name get-global scp-name or ,
57 git-branch-destination [ print flush ] [ , ] bi
58 ] { } make try-process ;
60 : append-build ( path -- path' )
63 : checksum-lines-append-build ( -- )
64 "checksums.txt" utf8 [
65 [ " " split1 [ append-build ] dip " " glue ] map
68 : with-build-images ( quot -- )
69 [ boot-image-names [ absolute-path ] map ] dip
75 checksums-path "." copy-file-into
76 ! Rewrite checksum lines with build number
77 checksum-lines-append-build
78 ! Rename file to file.build-number
79 "." directory-files [ dup append-build move-file ] each
80 ! Run the quot in the unique directory
82 ] cleanup-unique-directory
83 ] with-temp-directory ; inline
85 : upload-build-images ( -- )
88 \ scp-name get-global scp-name or ,
91 ] { } make try-process
94 : create-remote-upload-directory ( -- )
97 "sheeple@downloads.factorcode.org" ,
98 "mkdir -p downloads.factorcode.org/images/" factor-git-branch append ,
99 ] { } make try-process ;
101 : upload-new-images ( -- )
104 "Computing checksums..." print flush
106 "Creating remote directory..." print flush
107 create-remote-upload-directory
108 "Uploading images..." print flush
110 "Uploading build images..." print flush
112 ] with-resource-directory ;
114 MAIN: upload-new-images