/
setup.io
80 lines (65 loc) · 3.07 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
BoidSetup := Object clone
BoidSetup fishTemplate := """
# Start Boid configuration
set -x BOIDDIR #{boidDir path}
set -x IOIMPORT $IOIMPORT $BOIDDIR/active/io
set PATH $PATH $BOIDDIR/active/bin
# End Boid configuration"""
BoidSetup shTemplate := """
# Start Boid configuration
BOIDDIR=#{boidDir path}
IOIMPORT="$IOIMPORT:$BOIDDIR/active/lib"
PATH="$PATH:$BOIDDIR/active/bin"
export BOIDDIR IOIMPORT PATH
# End Boid configuration"""
BoidSetup do(
abort := method(msg,
"% setup aborted:" println
" #{msg}" interpolate println
System exit(1)
)
# Configure Boid directories
boidFile := method(File with("boid.io"))
boidDir := method(Directory with(User homeDirectory path .. "/.boid"))
ioDir := method(Directory with(boidDir path .. "/active/io"))
binDir := method(Directory with(boidDir path .. "/active/bin"))
# Select appropriate startup script template based on user's shell
# Thanks to rip for a good jumping-off point
shStartupScripts := list(".bash_profile", ".bash_login", ".bashrc", ".zshenv", ".profile", ".zshrc")
fishStartupScript := ".config/fish/config.fish"
fish := method(File with(User homeDirectory path .. "/" .. fishStartupScript) exists)
startupScript := File openForAppending(User homeDirectory path .. "/" .. if(fish, fishStartupScript, shStartupScripts select(s, File with(User homeDirectory path .. "/" .. s) exists) first))
template := if(fish, fishTemplate, shTemplate)
template = template interpolate
"% boid setup" println
if (Directory exists(boidDir path),
abort("previous install detected in `#{boidDir path}'" interpolate)
)
# Create necessary directories, if required
"% creating directories:" println
" - #{boidDir path}" interpolate println
Directory setCurrentWorkingDirectory(boidDir parentDirectory path)
Directory createSubdirectory(boidDir name)
if(boidDir exists not, abort("failed to create .boid directory"))
baseDir := Directory with(boidDir path .. "/base")
baseDir create
Directory createSubdirectory(boidDir name .. "/base/io")
""" - #{boidDir path .. "/base/io"}""" interpolate println
if(Directory with(boidDir path .. "/base/io") exists not, abort("failed to create #{boidDir path}/base/io directory" interpolate))
Directory createSubdirectory(boidDir name .. "/base/bin")
""" - #{boidDir path .. "/base/bin"}""" interpolate println
if(Directory with(boidDir path .. "/base/bin") exists not, abort("failed to create #{boidDir path}/base/bin directory" interpolate))
# Create the necessary symbolic links
"% activating base environment" println
#"ln -s #{baseDir path} #{boidDir path}/active" interpolate println
cmd := System runCommand("ln -s #{baseDir path} #{boidDir path}/active" interpolate)
if(cmd exitStatus > 0, abort("failed to create symlink to active environment:\n #{cmd stderr}" interpolate))
File with(baseDir path .. "/.active") create
# Modify the user's startup script
"% modifying your startup script" println
" - #{startupScript path}" interpolate println
startupScript write(template interpolate) close
# Finish up
"% success!" println
" restart your shell to finish up the process" println
)