www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

installer-sh.rkt (2824B)


      1 #lang at-exp racket/base
      2 (require racket/system
      3          racket/file
      4          racket/port
      5          racket/format
      6          racket/runtime-path
      7          setup/cross-system
      8          file/tar)
      9 
     10 (provide installer-sh)
     11 
     12 (define-runtime-path installer-header "unix-installer/installer-header")
     13 
     14 (define (system/show . l)
     15   (displayln (apply ~a #:separator " " l))
     16   (unless (apply system* (find-executable-path (car l)) (cdr l))
     17     (error "failed")))
     18 
     19 (define (system/read . l)
     20   (displayln (apply ~a #:separator " " l))
     21   (define o (open-output-bytes))
     22   (parameterize ([current-output-port o])
     23     (apply system* (find-executable-path (car l)) (cdr l)))
     24   (read (open-input-bytes (get-output-bytes o))))
     25 
     26 (define (count-lines i)
     27   (if (input-port? i)
     28       (for/sum ([l (in-lines i)]) 1)
     29       (call-with-input-file* i count-lines)))
     30 
     31 (define (generate-installer-sh src-dir dest target-dir-name human-name release? readme)
     32   (system/show "chmod"
     33                "-R" "g+w" src-dir)
     34   (define tmp-tgz (make-temporary-file "~a.tgz"))
     35   (delete-file tmp-tgz)
     36   (printf "Tarring to ~s\n" tmp-tgz)
     37   (when readme
     38     (call-with-output-file*
     39      (build-path src-dir "README")
     40      #:exists 'truncate
     41      (lambda (o)
     42        (display readme o))))
     43   (parameterize ([current-directory src-dir])
     44     (apply tar-gzip tmp-tgz (directory-list)))
     45   (define tree-size (system/read "du" "-hs" src-dir))
     46   (define archive-cksum (system/read "cksum" tmp-tgz))
     47   (define script
     48     @~a{#!/bin/sh
     49 
     50          # This is a self-extracting shell script for @|human-name|.
     51          # To use it, just run it, or run "sh" with it as an argument.
     52         
     53          DISTNAME="@|human-name|"
     54          TARGET="@|target-dir-name|"
     55          BINSUM="@|archive-cksum|"
     56          ORIGSIZE="@|tree-size|"
     57          RELEASED="@(if release? "yes" "no")"})
     58   (define installer-lines (+ (count-lines (open-input-string script))
     59                              (count-lines installer-header)
     60                              2))
     61   (call-with-output-file* 
     62    dest
     63    #:exists 'truncate
     64    (lambda (o)
     65      (display script o)
     66      (newline o)
     67      (fprintf o "BINSTARTLINE=\"~a\"\n" installer-lines)
     68      (call-with-input-file*
     69       installer-header
     70       (lambda (i)
     71         (copy-port i o)))
     72      (call-with-input-file*
     73       tmp-tgz
     74       (lambda (i)
     75         (copy-port i o)))))
     76   (system/show "chmod" "+x" dest)
     77   (delete-file tmp-tgz))
     78 
     79 (define (installer-sh human-name base-name dir-name release? dist-suffix readme)
     80   (define sh-path (format "bundle/~a-~a~a.sh" 
     81                           base-name 
     82                           (cross-system-library-subpath #f) 
     83                           dist-suffix))
     84   (generate-installer-sh "bundle/racket" sh-path
     85                          dir-name human-name
     86                          release?
     87                          readme)
     88   sh-path)