-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.rb
184 lines (142 loc) · 4.63 KB
/
install.rb
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# IAN install program
require 'ftools' # so we can call File.copy and File.makedirs
def validate(path)
# empty/nonexistant
if not path or path.length == 0
print "No path specified.\n"
return false
end
# garbage chars present
if path =~ /[\|\*\"\<\>\?]/
print "Illegal character present in path: ",$&,"\n"
return false
end
# c:, u:, or \, /
if path =~ /^[A-Za-z]:$/ or path == "\\" or path == "/"
print "IAN requires a full path as an installation target.\n"
return false
end
# c:\ u:\ etc.
if path =~ /^[A-Za-z]:(\\|\/)+$/
print "IAN requires that a subdirectory is specified as an installation target.\n"
return false
end
# c:\fred, c:\fred\, c:\fred\joe, c:\fred\joe\, \fred, fred, fred\, fred\joe,
# fred\joe\, ., .., .\, .\joe, .\.\.
tmp = path.dup
# optionally match leading drive designation
if tmp =~ /^[A-Za-z]\:(.*)/
tmp = $1
end
# optionally match leading slash
if tmp =~ /^(\\|\/)(.*)/
tmp = $2
end
while tmp and tmp.length != 0
# match subdir to end of string
if tmp =~ /^[\s\w\`\~\!\@\#\$\%\^\&\(\)\-\_\+\=\{\}\[\]\;\'\,\.]+$/
tmp = ""
# match subdir to next slash
elsif tmp =~ /^[\s\w\`\~\!\@\#\$\%\^\&\(\)\-\_\+\=\{\}\[\]\;\'\,\.]+\\|\/(.*)/
tmp = $1
else # no subdir to match
print "Illegal path syntax.\n"
return false
end
end
return true
end
def pathName(path,subdir)
pathName = path
pathName += "\\" if pathName[pathName.length-1,1] != "\\"
pathName += subdir
pathName
end
def makePathDir(path)
exists = FileTest.exists?(path)
if exists
if not File.stat(path).directory?
print "A file exists with the name ",path,". Unable to create directory. Exiting.\n"
exit
else
print "Directory ",path," already exists. Continuing.\n"
end
else # path does not yet exist
print "Making directory ",path,"\n"
File.makedirs(path)
end
end
def copyFiles(srcPath,fileSpec,destPath)
print "Copying files to ",destPath,"\n"
if srcPath.length == 0
dir = Dir.new(".")
else
dir = Dir.new(srcPath)
end
dir.each do | fileName |
if fileName =~ fileSpec
if srcPath.length == 0
srcFile = fileName
else
srcFile = srcPath + "\\" + fileName
end
File.copy(srcFile,destPath) if not File.stat(srcFile).directory?
end
end
end
# get install directory from user
print "\nIAN installation program : July 2004\n\n"
print "Enter the path where you would like IAN installed\n"
path = gets.chomp
exit if not validate(path)
# if path ends in \ or / remove it
lastChar = path[path.length-1,1]
path = path[0,path.length-1] if lastChar == "\\" or lastChar == "/"
# make sure we create install dirs if needed
makePathDir(path)
makePathDir(pathName(path,"options"))
makePathDir(pathName(path,"analyses"))
makePathDir(pathName(path,"imagetypes"))
makePathDir(pathName(path,"reports"))
# copy files over to install dirs
copyFiles("",/.*\.bmp/i,path)
copyFiles("",/.*\.dat/i,path)
copyFiles("",/.*\.dll/i,path)
copyFiles("",/.*\.gis/i,path)
copyFiles("",/.*\.png/i,path)
copyFiles("",/.*\.rb/i,path)
copyFiles("",/.*\.rbw/i,path)
copyFiles("",/.*\.so/i,path)
copyFiles("options",/.*\.rb/i,pathName(path,"options"))
copyFiles("analyses",/.*\.rb/i,pathName(path,"analyses"))
copyFiles("imageTypes",/.*\.rb/i,pathName(path,"imageTypes"))
copyFiles("reports",/.*\.rb/i,pathName(path,"reports"))
# make command line batch files at install dir
print "Making IanC.bat script\n"
batchFile = File.new(pathName(path,"IanC.bat"),"w")
batchFile.write("@echo off\n")
batchFile.write("set commline=ruby \""+path+"\\clui.rb\"\n")
batchFile.write(":getArg\n")
batchFile.write("if \"%1\"==\"\" goto end\n")
batchFile.write("set commline=%commline% %1\n")
batchFile.write("shift\n")
batchFile.write("goto getArg\n")
batchFile.write(":end\n")
batchFile.write("%commline%\n")
batchFile.write("set commline=\n")
batchFile.close
print "Making Ian.bat script\n"
batchFile = File.new(pathName(path,"Ian.bat"),"w")
batchFile.write("@echo off\n")
batchFile.write("set commline=ruby \""+path+"\\winui.rbw\"\n")
batchFile.write(":getArg\n")
batchFile.write("if \"%1\"==\"\" goto end\n")
batchFile.write("set commline=%commline% %1\n")
batchFile.write("shift\n")
batchFile.write("goto getArg\n")
batchFile.write(":end\n")
batchFile.write("%commline%\n")
batchFile.write("set commline=\n")
batchFile.close
print "\nInstallation complete! Please Press Enter to Exit."
gets