sunterlib/scsh/CSAN/CSAN.scm

382 lines
14 KiB
Scheme
Raw Normal View History

2012-01-25 11:57:25 -05:00
;;; CSAN.scm - Scheme Perl Archive Network
2012-01-17 10:15:03 -05:00
;;;
2012-01-17 12:20:18 -05:00
;;; Copyright (c) 2012 Johan Ceuppens
2012-01-17 10:15:03 -05:00
;;;
;;; All rights reserved.
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;; 3. The name of the authors may not be used to endorse or promote products
;;; derived from this software without specific prior written permission.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
;;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
;;; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
;;; IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
;;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
;;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
;;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
;;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2012-01-18 03:06:46 -05:00
;; FXIME refactor
2012-01-17 10:42:36 -05:00
2012-01-25 11:57:25 -05:00
(define (CSAN-question~ droptext question answer defaultchoice procedure)
2012-01-17 10:42:36 -05:00
(let ((s ""))
(display droptext)
(newline)
(display question)(display " ")
(display "[")(display defaultchoice)(display "] ")
(set! s (read))
(cond ((and (symbol? s)
(string=? (symbol->string s) defaultchoice))
(set! answer defaultchoice))
((and (number? s)
(string=? (symbol->number s) defaultchoice))
(set! answer defaultchoice))
((string=? (symbol->string s)(string #\return))
(set! answer defaultchoice))
2012-01-17 13:10:44 -05:00
((and (symbol? s)(string? (symbol->string s)))
2012-01-17 10:42:36 -05:00
(set! answer (symbol->string s)))
2012-01-17 13:10:44 -05:00
((and (number? s)(string? (number->string s)))
(set! answer (number->string s)))
2012-01-25 11:57:25 -05:00
(else (CSAN-question~ droptext question answer defaultchoice)))
2012-01-18 03:06:46 -05:00
procedure))
2012-01-17 10:15:03 -05:00
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-1
2012-01-18 08:23:59 -05:00
"1. The following questions are intended to help you with the
2012-01-25 11:57:25 -05:00
configuration. The CSAN module needs a directory of its own to cache
important index files and maybe keep a temporary mirror of CSAN files.
2012-01-17 11:45:51 -05:00
This may be a site-wide or a personal directory.")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-2
"2. Unless you are accessing the CSAN on your filesystem via a file: URL,
CSAN.pm needs to keep the source files it downloads somewhere. Please
2012-01-17 11:45:51 -05:00
supply a directory where the downloaded files are to be kept.")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-3
2012-01-18 08:23:59 -05:00
"3. ")
2012-01-17 11:45:51 -05:00
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-4
"4. Normally CSAN.pm keeps config variables in memory and changes need to
2012-01-17 11:45:51 -05:00
be saved in a separate 'o conf commit' command to make them permanent
between sessions. If you set the 'auto_commit' option to true, changes
to a config variable are always automatically committed to disk.")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-5
"5. CSAN.pm can limit the size of the disk area for keeping the build
2012-01-17 11:45:51 -05:00
directories with all the intermediate files.")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-6
"6. The CSAN indexes are usually rebuilt once or twice per hour, but the
typical CSAN mirror mirrors only once or twice per day. Depending on
2012-01-17 11:45:51 -05:00
the quality of your mirror and your desire to be on the bleeding edge,
you may want to set the following value to more or less than one day
2012-01-25 11:57:25 -05:00
(which is the default). It determines after how many days CSAN.pm
2012-01-17 11:45:51 -05:00
downloads new indexes.")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-7
"7. By default, each time the CSAN module is started, cache scanning is
2012-01-17 11:45:51 -05:00
performed to keep the cache size in sync. To prevent this, answer
'never'.")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-8
"8. To considerably speed up the initial CSAN shell startup, it is
2012-01-17 11:45:51 -05:00
possible to use Storable to create a cache of metadata. If Storable is
not available, the normal index mechanism will be used.
Note: this mechanism is not used when use_sqlite is on and SQLLite is
running.")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-9
"9. The CSAN module can detect when a module which you are trying to build
2012-01-17 11:45:51 -05:00
depends on prerequisites. If this happens, it can build the
prerequisites for you automatically ('follow'), ask you for
confirmation ('ask'), or just ignore them ('ignore'). Please set your
policy to one of the three values.")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-10 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "Every Makefile.PL is run by perl in a separate process. Likewise we
;; run 'make' and 'make install' in separate processes. If you have
;; any parameters (e.g. PREFIX, UNINST or the like) you want to
;; pass to the calls, please specify them here.
;; If you don't understand this question, just press ENTER.
;; Typical frequently used settings:
;; PREFIX=~/perl # non-root users (please see manual for more hints)
;; <makepl_arg>
;; Parameters for the 'perl Makefile.PL' command? [] ")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-11 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "Typical frequently used settings:
;; PREFIX=~/perl # non-root users (please see manual for more hints)
;; <makepl_arg>
;; Parameters for the 'perl Makefile.PL' command? []
;; Parameters for the 'make' command? Typical frequently used setting:
;; -j3 # dual processor system (on GNU make)
;; <make_arg>
;; Your choice: [] ")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-12 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "Parameters for the 'make install' command?
;; Typical frequently used setting:
;; UNINST=1 # to always uninstall potentially conflicting files
;; <make_install_arg>
;; Your choice: []"
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-13 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "A Build.PL is run by perl in a separate process. Likewise we run
;; './Build' and './Build install' in separate processes. If you have any
;; parameters you want to pass to the calls, please specify them here.
;; Typical frequently used settings:
;; --install_base /home/xxx # different installation directory
;; <mbuildpl_arg>
;; Parameters for the 'perl Build.PL' command? [] ")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-14 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "Parameters for the './Build' command? Setting might be:
;; --extra_linker_flags -L/usr/foo/lib # non-standard library location
;; <mbuild_arg>
;; Your choice: [] ")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-15 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "Do you want to use a different command for './Build install'? Sudo
;; users will probably prefer:
;; su root -c ./Build
;; or
;; sudo ./Build
;; or
;; /path1/to/sudo -u admin_account ./Build
;; <mbuild_install_build_command>")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-16 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "Parameters for the './Build install' command? Typical frequently used
;; setting:
;; --uninst 1 # uninstall conflicting files
;; <mbuild_install_arg>
;; Your choice: [] ")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-17 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "If you're accessing the net via proxies, you can specify them in the
2012-01-25 11:57:25 -05:00
;; CSAN configuration or via environment variables. The variable in
;; the $CSAN::Config takes precedence.
2012-01-17 11:45:51 -05:00
;; <ftp_proxy>
;; Your ftp_proxy? []")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-18 ;;FIXME
2012-01-17 11:45:51 -05:00
;; " <http_proxy>
;; Your http_proxy? []")
2012-01-25 11:57:25 -05:00
;; (define CSAN-shell-droptext-19 ;;FIXME
2012-01-17 11:45:51 -05:00
;; "<no_proxy>
;; Your no_proxy? []")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-20
"20. CSAN needs access to at least one CSAN mirror.
2012-01-17 11:45:51 -05:00
As you did not allow me to connect to the internet you need to supply
2012-01-25 11:57:25 -05:00
a valid CSAN URL now.
2012-01-17 11:45:51 -05:00
")
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-21
2012-01-18 08:23:59 -05:00
"21. Enter another URL or RETURN to quit: []")
2012-01-17 11:45:51 -05:00
2012-01-25 11:57:25 -05:00
(define CSAN-shell-droptext-22
2012-01-18 08:23:59 -05:00
"22. Please remember to call 'o conf commit' to make the config permanent!
2012-01-17 11:45:51 -05:00
2012-01-27 13:02:22 -05:00
cpan shell -- CSAN exploration and modules installation (v0.1)
Enter 'h' for help.
Commands : get filename.tar.gz")
2012-01-17 13:10:44 -05:00
2012-01-18 07:55:20 -05:00
(define questions (make-table))
2012-01-25 11:57:25 -05:00
(table-set! questions 1 CSAN-shell-droptext-1)
(table-set! questions 2 CSAN-shell-droptext-2)
(table-set! questions 3 CSAN-shell-droptext-3)
(table-set! questions 4 CSAN-shell-droptext-4)
(table-set! questions 5 CSAN-shell-droptext-5)
(table-set! questions 6 CSAN-shell-droptext-6)
(table-set! questions 7 CSAN-shell-droptext-7)
(table-set! questions 8 CSAN-shell-droptext-8)
(table-set! questions 9 CSAN-shell-droptext-9)
(table-set! questions 20 CSAN-shell-droptext-20)
(table-set! questions 21 CSAN-shell-droptext-21)
(table-set! questions 22 CSAN-shell-droptext-22)
2012-01-18 08:23:59 -05:00
(define question?
(lambda (n)
(case ((n) (string-match (table-ref n) (rx (| ((string n)))))
(table-ref n)))))
2012-01-18 04:20:07 -05:00
2012-01-18 03:06:46 -05:00
(define questionaire
2012-01-25 11:57:25 -05:00
(lambda (CSAN-dir)
2012-01-18 09:50:20 -05:00
;; (fork-and-forget
2012-01-18 03:06:46 -05:00
(define answer "")
2012-01-25 11:57:25 -05:00
(define CSAN-build-and-cache-dir CSAN-dir)
(define CSAN-download-target-dir CSAN-dir)
(define CSAN-mirror-url (if (file-exists? (string-append CSAN-dir "/mirror"))
2012-01-18 09:05:50 -05:00
2012-01-25 11:57:25 -05:00
(read (string-append CSAN-dir "/mirror"))
2012-01-18 09:05:50 -05:00
"localhost"))
2012-01-18 03:06:46 -05:00
;; question 1
2012-01-18 08:23:59 -05:00
;;((lambda ()
(cond
2012-01-25 11:57:25 -05:00
((and (file-exists? CSAN-build-and-cache-dir)
(file-exists? (string-append CSAN-dir "/mirror")))
(let ((CSAN-mirror-url (make-string-input-port
(open-input-file (string-append CSAN-build-and-cache-dir "/mirror")))))
(CSAN-shell-spawn CSAN-dir CSAN-mirror-url)))
2012-01-18 03:06:46 -05:00
(else
2012-01-25 11:57:25 -05:00
;;;;;;;;prototype (define (CSAN-question~ droptext question answer defaultchoice)
((CSAN-question~ (question? 1)
"CSAN build and cache directory"
2012-01-18 03:06:46 -05:00
""
2012-01-25 11:57:25 -05:00
CSAN-build-and-cache-dir
2012-01-18 03:06:46 -05:00
(lambda (answer)
(let ((dir (create-directory answer)))
2012-01-18 10:42:33 -05:00
(run (touch (string-append dir "/help")))
(let ((out (open-output-file (string-append dir "/help"))))
(write "Commands : 'h' and 'get <filename-on-server>"))
2012-01-18 03:06:46 -05:00
(if (file-directory? dir)
2012-01-25 11:57:25 -05:00
(set! CSAN-dir answer)
(set! CSAN-build-and-cache-dir answer)
2012-01-18 03:06:46 -05:00
#f)))) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-download-target-dir (string-append CSAN-build-and-cache-dir "/" "sources"))
((CSAN-question~ (question? 2)
2012-01-18 03:06:46 -05:00
"Download target directory"
""
2012-01-25 11:57:25 -05:00
CSAN-download-target-dir
2012-01-18 03:06:46 -05:00
(lambda (answer)
(let ((dir (create-directory answer)))
(if (file-directory? answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-download-target-dir answer)
2012-01-18 03:06:46 -05:00
#f)))) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-build-dir (string-append CSAN-build-and-cache-dir "/" "build"))
((CSAN-question~ (question? 3)
2012-01-18 03:06:46 -05:00
"Directory where the build process takes place?"
""
2012-01-25 11:57:25 -05:00
CSAN-download-target-dir
2012-01-18 03:06:46 -05:00
(lambda (answer)
(let ((dir (create-directory answer)))
(if (file-directory? answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-build-dir answer)
2012-01-18 03:06:46 -05:00
#f)))) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-config "no")
((CSAN-question~ (question? 4)
2012-01-18 03:06:46 -05:00
"Always commit changes to config variables to disk?"
""
2012-01-25 11:57:25 -05:00
CSAN-config
2012-01-18 03:06:46 -05:00
(lambda (answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-config answer)
2012-01-18 03:06:46 -05:00
#f)) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-build-Mb 100)
((CSAN-question~ (question? 5)
2012-01-18 03:06:46 -05:00
"Cache size for build directory (in MB)?"
""
2012-01-25 11:57:25 -05:00
CSAN-build-Mb
2012-01-18 03:06:46 -05:00
(lambda (answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-build-Mb answer)
2012-01-18 03:06:46 -05:00
#f)) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-expire 1)
((CSAN-question~ (question? 6)
2012-01-18 03:06:46 -05:00
"Let the index expire after how many days?"
""
2012-01-25 11:57:25 -05:00
CSAN-expire
2012-01-18 03:06:46 -05:00
(lambda (answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-expire answer)
2012-01-18 03:06:46 -05:00
#f)) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-scan-cache "atstart")
((CSAN-question~ (question? 7)
2012-01-18 03:06:46 -05:00
"Perform cache scanning (atstart or never)?"
""
2012-01-25 11:57:25 -05:00
CSAN-scan-cache
2012-01-18 03:06:46 -05:00
(lambda (answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-scan-cache answer)
2012-01-18 03:06:46 -05:00
#f)) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-cache-metadata "yes")
((CSAN-question~ (question? 8)
2012-01-18 03:06:46 -05:00
"Cache metadata (yes/no)?"
""
2012-01-25 11:57:25 -05:00
CSAN-cache-metadata
2012-01-18 03:06:46 -05:00
(lambda (answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-cache-metadata answer)
2012-01-18 03:06:46 -05:00
#f)) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-policy-building "ask")
((CSAN-question~ (question? 9)
2012-01-18 03:06:46 -05:00
"Policy on building prerequisites (follow, ask or ignore)? [ask]"
""
2012-01-25 11:57:25 -05:00
CSAN-policy-building
2012-01-18 03:06:46 -05:00
(lambda (answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-policy-building answer)
2012-01-18 03:06:46 -05:00
#f)) answer)
;; question 10 is under dev
;; question 11 is under dev
;; question 12 is under dev
;; question 13 is under dev
;; ... until 20
2012-01-25 11:57:25 -05:00
((CSAN-question~ (question? 20)
"Please enter the URL of your CSAN mirror "
2012-01-18 03:06:46 -05:00
""
2012-01-25 11:57:25 -05:00
CSAN-mirror-url
2012-01-18 03:06:46 -05:00
(lambda (answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-mirror-url answer)
(run (touch (string-append CSAN-dir "/mirror")))
(let ((out (open-output-file (string-append CSAN-dir "/mirror"))))
2012-01-18 03:06:46 -05:00
(write answer out))
#f)) answer)
2012-01-25 11:57:25 -05:00
(define CSAN-mirror-url-2 "")
((CSAN-question~ (question? 21)
2012-01-18 03:06:46 -05:00
"Enter another URL or RETURN to quit: [] "
""
2012-01-25 11:57:25 -05:00
CSAN-mirror-url-2
2012-01-18 03:06:46 -05:00
(lambda (answer)
2012-01-25 11:57:25 -05:00
(set! CSAN-mirror-url-2 answer)
2012-01-18 03:06:46 -05:00
#f)) answer)
2012-01-18 08:23:59 -05:00
(display (question? 22))
2012-01-25 11:57:25 -05:00
(CSAN-shell-spawn CSAN-dir CSAN-mirror-url))
2012-01-18 03:06:46 -05:00
)))