-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.io
145 lines (111 loc) · 4.05 KB
/
setup.io
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Importer addSearchPath("io/")
# Parse arguments
if(System args size > 4,
"Error: wrong number of arguments" println
System exit(1))
options := System getOptions(System args)
(
# check options
availableOptions := list(System launchScript, "dev", "notouch", "shrc")
options keys foreach(opt,
if(availableOptions contains(opt) not,
"Error: unknown option \"#{opt}\"" interpolate println
"Available options are:" println
"\t--dev" println
"\t--notouch" println
"\t--shrc=<path>" println
System exit(1)))
)
isDev := options hasKey("dev")
eeriePackageUrl := if(isDev,
Directory currentWorkingDirectory,
"https://github.com/IoLanguage/eerie.git")
isNotouch := options hasKey("notouch")
isWindows := (System platform containsAnyCaseSeq("windows") or(
System platform containsAnyCaseSeq("mingw")))
shrc := block(
if(options hasKey("shrc"), return list(options at("shrc")))
if(isWindows,
list(),
list("~/.profile", "~/.bash_profile", "~/.zshrc"))
) call
eeriePath := if(isWindows, System installPrefix .. "\\eerie",
("~/.eerie" stringByExpandingTilde))
eerieDir := Directory with(eeriePath)
writePath := method(eeriePath,
# we write eeriePath into a file and then read this file inside
# install_unix.sh
# this allows us to update current session with $EERIEDIR
path := Directory currentWorkingDirectory .. "/__install_path"
file := File with(path) create
file setContents(eeriePath)
)
System setEnvironmentVariable("EERIEDIR", eeriePath)
System setEnvironmentVariable("PATH",
"#{System getEnvironmentVariable(\"PATH\")}:#{eeriePath}/base/bin:#{eeriePath}/activeEnv/bin" interpolate)
shellScript := """
# Eerie config
export EERIEDIR=#{eeriePath}
export PATH=$PATH:$EERIEDIR/base/bin:$EERIEDIR/activeEnv/bin
# End Eerie config""" interpolate
appendEnvVariables := method(
# just remind to setup variables if --notouch
if(isNotouch,
"----" println
"Make sure to update your shell's environment variables before using Eerie." println
"Here's a sample code you could use:" println
shellScript println
return)
# add envvars to shell's configs
shrc foreach(shfile,
shfile := File with(shfile stringByExpandingTilde)
shfile exists ifFalse(
shfile create
Eerie log("Created #{shfile path}"))
shfile contents containsSeq("EERIEDIR") ifFalse(
shfile appendToContents(shellScript)
Eerie log("Added new environment variables to #{shfile path}")))
# set envvars permanently on Windows
if(isWindows and(shrc size == 0),
Eerie sh("setx EERIEDIR #{eeriePath}" interpolate, true)
Eerie sh("setx PATH \"%PATH%;#{eeriePath}\\base\\bin;#{eeriePath}\\activeEnv\\bin\"" \
interpolate,
true))
)
createDirectories := method(
eerieDir createIfAbsent
eerieDir directoryNamed("env") create
eerieDir directoryNamed("tmp") create
eerieDir fileNamed("/config.json") create \
openForUpdating write("{\"envs\": {}}") close
)
createDefaultEnvs := method(
baseEnv := Eerie Env with("_base") create activate use
SystemCommand lnDirectory(baseEnv path, eeriePath .. "/base")
Eerie Env with("_plugins") create
Eerie Env with("default") create
Eerie saveConfig
)
installEeriePkg := method(
Eerie Transaction clone install(Eerie Package fromUri(eeriePackageUrl)) run
)
activateDefaultEnv := method(Eerie Env named("default") activate)
# Run the process
if(eerieDir exists,
"Error: Eerie is already installed at #{eerieDir path}" interpolate println
System exit(1))
createDirectories
Eerie do(
_log := getSlot("log")
_allowedModes := list("info", "error", "transaction", "install")
log = method(str, mode,
(mode == nil or self _allowedModes contains(mode)) ifTrue(
call delegateToMethod(self, "_log"))
)
)
createDefaultEnvs
installEeriePkg
appendEnvVariables
activateDefaultEnv
writePath(eeriePath)
" --- Done! --- " println