| 1 |
#!/usr/bin/env gosh |
| 2 |
;;; |
| 3 |
;;; Download cacert.pem file |
| 4 |
;;; |
| 5 |
|
| 6 |
(use gauche.process) |
| 7 |
(use file.util) |
| 8 |
|
| 9 |
(define (usage) |
| 10 |
(print "Usage: gosh tools/get-cacert") |
| 11 |
(print " Download cacert.pem from curl official site (curl.haxx.se) and") |
| 12 |
(print " Saves it to installed Gauche's library directory.") |
| 13 |
(print " (If you installed Gauche with root priviledge, you're asked to") |
| 14 |
(print " enter your password by sudo when the file is copied.)") |
| 15 |
(exit 1)) |
| 16 |
|
| 17 |
(define *cacert-url* "https://curl.haxx.se/ca/cacert.pem") |
| 18 |
|
| 19 |
(define *curl* |
| 20 |
(or (find-file-in-paths "curl") |
| 21 |
(exit 1 "Cannot find 'curl' in PATH. We need to use curl to download cacert file."))) |
| 22 |
|
| 23 |
(define *destdir* (sys-dirname (gauche-library-directory))) |
| 24 |
|
| 25 |
(define (main args) |
| 26 |
(when (not (null? (cdr args))) |
| 27 |
(usage)) |
| 28 |
(call-with-temporary-directory do-it :prefix "gauche-get-cacert") |
| 29 |
0) |
| 30 |
|
| 31 |
(define (do-it tmpdir) |
| 32 |
(let1 file (build-path tmpdir "cacert.pem") |
| 33 |
(print #"Donwnloading ~*cacert-url*") |
| 34 |
(or (do-process `(,*curl* -o ,file ,*cacert-url*)) |
| 35 |
(exit 1 "curl failed")) |
| 36 |
(if (sys-access *destdir* W_OK) |
| 37 |
(copy-file file (build-path *destdir* "cacert.pem") |
| 38 |
:if-exists :supersede) |
| 39 |
(begin |
| 40 |
(print #"We're going to run 'sudo gauche-install ~file ~*destdir*'") |
| 41 |
(do-process! `(sudo gauche-install ,file ,*destdir*)))) |
| 42 |
(print "cacert.pem is stored in " *destdir*))) |
| 43 |
|
| 44 |
;; Local variables: |
| 45 |
;; mode: scheme |
| 46 |
;; end: |