#!/usr/bin/env csi -script (import (chicken file) (chicken file posix) (chicken irregex) (chicken pathname) (chicken platform) (chicken process) (chicken process-context)) ;; kinda silly (define (parse-args #!optional (args (command-line-arguments))) (when (null? args) (usage)) (let ((verb (car args)) (rest (cdr args))) `((command . ,(executable-pathname)) (verb . ,(string->symbol verb)) (args . ,rest)))) (define (usage) (print "usage: " (program-name) " init ") (exit 1)) (define (dispatch) (let ((args (parse-args))) (let ((verb (alist-ref 'verb args))) (case verb ((init) (let ((args (alist-ref 'args args))) (when (null? args) (usage)) (cenv-init-repository (car args)))) (else (usage)))))) (define (template str alist) (irregex-replace/all "{{([A-Za-z0-9_-]+)}}" str (lambda (m) (let ((key (string->symbol (irregex-match-substring m 1)))) (or (alist-ref key alist) (error 'template "missing value for key" key)))))) ;; realpath is available as C_realpath but only if we compile. (define (realpath x) (normalize-pathname (if (absolute-pathname? x) x (make-pathname (current-directory) x)))) (define (last x) (if (pair? (cdr x)) (last (cdr x)) (car x))) ;; We precompute our env dir, the chicken prefix, and the chicken system repo; so we ;; cannot relocate, but it makes things simpler. ;; We may want to ignore any CHICKEN_REPOSITORY_PATH set in the calling environment; ;; we currently honor it, which is of debatable utility. (define center-data #< #t) (map (cut string-append dirname <>) '("/bin" "/lib" "/share"))) (create-center dirname) (create-cexec dirname) (test-cenv dirname)) (dispatch)