-
Notifications
You must be signed in to change notification settings - Fork 13
/
install.sc
101 lines (85 loc) · 3.12 KB
/
install.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;; Info Begin
(define install-version "0.3.8")
(define windows?
(case (machine-type)
((a6nt i3nt ta6nt ti3nt) #t)
(else #f)))
(define target-linux-path "/usr/local/lib/raven")
(define target-window-path (string-append (or (getenv "UserProfile") "c:") "\\raven"))
(define target-path (if windows? target-window-path target-linux-path))
(define raven-url "http://ravensc.com/raven")
;;; Info End
;;; Helper Begin
(define (read-file file-name)
(let ((p (open-input-file file-name)))
(let loop ((lst '()) (c (read-char p)))
(if (eof-object? c)
(begin
(close-input-port p)
(list->string (reverse lst)))
(loop (cons c lst) (read-char p))))))
(define (system-return cmd)
(define tmp "./##tmp##")
(define rst "")
(and (zero? (system (string-append cmd " > " tmp)))
(file-exists? tmp)
(begin (set! rst (read-file tmp))))
(delete-file tmp)
rst
)
(define (newest-version)
(define ver (system-return (string-append "curl -s " raven-url)))
(if (or (string-ci=? ver "#f") (string-ci=? ver ""))
#f
ver))
(define (clear-directory path)
(when (file-directory? path)
(for-each
(lambda (p)
(let ([p2 (string-append path "/" p)])
(if (file-directory? p2)
(clear-directory p2)
(delete-file p2)
)))
(directory-list path))
(delete-directory path)))
(define (install)
(define ver (newest-version))
(if ver
(begin
(unless (file-directory? target-path)
(mkdir target-path))
(clear-directory (format "~a/raven" target-path))
(printf "loading raven ~a ......\n" ver)
(if windows?
(if (and
(system (format "cd /d ~a && curl -# -o raven.tar.gz ~a/~a && 7z x raven.tar.gz -y -aoa >> install.log && 7z x raven.tar -o~a/raven -y -aoa >> install.log"
target-path raven-url ver target-path))
(delete-file (format "~a/raven.tar.gz" target-path))
(delete-file (format "~a/raven.tar" target-path))
(delete-file (format "~a/install.log" target-path)))
(begin
(printf "The script has been downloaded in ~a\\raven\nYou should add this path to the system variables PATH before you enjoy the raven\n" target-path)
(printf "install raven ~a success\n" ver))
(printf "install raven ~a fail\n" ver)
)
(if (and
(mkdir (format "~a/raven" target-path))
(system (format "cd ~a && curl -# -o raven.tar.gz ~a/~a && tar -xzf raven.tar.gz -C ~a/raven"
target-path raven-url ver target-path))
(delete-file (format "~a/raven.tar.gz" target-path)))
(begin
(delete-file "/usr/local/bin/raven")
(system "ln -s /usr/local/lib/raven/raven/raven.sc /usr/local/bin/raven")
(system "chmod +x /usr/local/bin/raven")
(printf "install raven ~a success\n" ver))
(printf "install raven ~a fail\n" ver)
)
)
)
(printf "dont't exist raven\n")
)
)
;;; Helper End
(install)
(exit)