source: project/chicken/trunk/chicken-uninstall.scm @ 15575

Last change on this file since 15575 was 12937, checked in by felix winkelmann, 11 years ago

updateed copyright

File size: 4.0 KB
Line 
1;;;; chicken-uninstall.scm
2;
3; Copyright (c) 2008-2009, The Chicken Team
4; All rights reserved.
5;
6; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
7; conditions are met:
8;
9;   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
10;     disclaimer.
11;   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12;     disclaimer in the documentation and/or other materials provided with the distribution.
13;   Neither the name of the author nor the names of its contributors may be used to endorse or promote
14;     products derived from this software without specific prior written permission.
15;
16; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24; POSSIBILITY OF SUCH DAMAGE.
25
26
27(require-library
28 setup-api
29 srfi-1 posix data-structures utils ports regex srfi-13 files)
30
31
32(module main ()
33 
34  (import scheme chicken)
35  (import setup-api)
36  (import srfi-1 posix data-structures utils ports regex srfi-13 files)
37
38  (define *force* #f)
39
40  (define (gather-eggs patterns)
41    (let ((eggs (map pathname-file 
42                     (glob (make-pathname (repository-path) "*" "setup-info")))))
43      (delete-duplicates
44       (concatenate (map (cut grep <> eggs) patterns))
45       string=?)))
46
47  (define (quit code)
48    (print "aborted.")
49    (exit code))
50
51  (define (ask eggs)
52    (handle-exceptions ex
53        (if (eq? ex 'aborted)
54            (quit 1) 
55            (signal ex))
56      (yes-or-no? 
57       (string-concatenate
58        (append
59         '("About to delete the following extensions:\n\n")
60         (map (cut string-append "  " <> "\n") eggs)
61         '("\nDo you want to proceed?")))
62       default: "no")))
63
64  (define (uninstall pats)
65    (let ((eggs (gather-eggs pats)))
66      (cond ((null? eggs)
67             (print "nothing to remove.") )
68            ((or *force* (equal? eggs pats) (ask eggs))
69             (for-each
70              (lambda (e)
71                (print "removing " e)
72                (remove-extension e) )
73              eggs)))))
74
75  (define (usage code)
76    (print #<<EOF
77usage: chicken-uninstall [OPTION | PATTERN] ...
78
79  -h   -help                    show this message and exit
80  -v   -version                 show version and exit
81       -force                   don't ask, delete whatever matches
82  -s   -sudo                    use sudo(1) for deleting files
83EOF
84);|
85    (exit code))
86
87  (define *short-options* '(#\h #\s))
88
89  (define (main args)
90    (let loop ((args args) (pats '()))
91      (if (null? args)
92          (uninstall (if (null? pats) (usage 1) (reverse pats)))
93          (let ((arg (car args)))
94            (cond ((or (string=? arg "-help") 
95                       (string=? arg "-h")
96                       (string=? arg "--help"))
97                   (usage 0))
98                  ((or (string=? arg "-v") (string=? arg "-version"))
99                   (print (chicken-version))
100                   (exit 0))
101                  ((string=? arg "-force")
102                   (set! *force* #t)
103                   (loop (cdr args) pats))
104                  ((or (string=? arg "-s") (string=? arg "-sudo"))
105                   (sudo-install #t)
106                   (loop (cdr args) pats))
107                  ((and (positive? (string-length arg))
108                        (char=? #\- (string-ref arg 0)))
109                   (if (> (string-length arg) 2)
110                       (let ((sos (string->list (substring arg 1))))
111                         (if (null? (lset-intersection eq? *short-options* sos))
112                             (loop (append (map (cut string #\- <>) sos) (cdr args)) pats)
113                             (usage 1)))
114                       (usage 1)))
115                  (else (loop (cdr args) (cons arg pats))))))))
116
117  (main (command-line-arguments))
118 
119 )
Note: See TracBrowser for help on using the repository browser.