update-eggs added by mario-goulart on Tue Nov 1 14:49:04 2011

#!/bin/sh
#| -*- scheme -*-
exec csi -s $0 "$@"
|#
(use http-client posix utils data-structures)

(define henrietta-uri "http://code.call-cc.org/cgi-bin/henrietta.cgi?list=1")

(define (all-eggs)
  (with-input-from-request
   henrietta-uri
   #f
   (lambda ()
     (string-split (read-all) "\n"))))

(define (installed-eggs)
  (let ((local-eggs
         (map pathname-file
              (glob (make-pathname (repository-path) "*" "setup-info"))))
        (remote-eggs (all-eggs)))
    (delete-duplicates
     (filter (lambda (egg)
               (member egg remote-eggs))
             local-eggs)
     string=?)))

(define (usage #!optional exit-code)
  (print #<#EOF
Usage: #(pathname-strip-directory (program-name)) <options>

<options>:

-help
  Print this message

-continue
  Continue updating even if installation of eggs fail

The CHICKEN_INSTALL_OPTIONS environment variable can be used to
set options to be used by chicken-install.
EOF
)
  (when exit-code (exit exit-code)))


(let* ((args (command-line-arguments))
       (continue? (member "-continue" args)))
  (when (or (member "--help" args)
            (member "-help" args)
            (member "-h" args))
    (usage 0))
  (for-each
   (lambda (egg)
     ((if continue?
          system
          system*)
      (sprintf "chicken-install ~a ~a"
               (or (get-environment-variable "CHICKEN_INSTALL_OPTIONS") "")
               egg)))
   (installed-eggs)))