-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.tcl
executable file
·328 lines (286 loc) · 10.2 KB
/
install.tcl
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!tclsh8.6
# TKE - Advanced Programmer's Editor
# Copyright (C) 2014-2019 Trevor Williams ([email protected])
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
######################################################################
# Name: install.tcl
# Author: Trevor Williams ([email protected])
# Date: 5/26/2014
# Description: Handles installation of TKE.
######################################################################
# Bring in the version information
source [file join lib version.tcl]
# Check to make sure that the Tcl version is okay
puts -nonewline "Tcl version 8.6.x or higher is required... "
flush stdout
lassign [split [set version [info patchlevel]] .] major minor
if {($major > 8) || (($major == 8) && ($minor >= 6))} {
puts "Found ($version)"
} else {
puts "Not Found! ($version)"
exit 1
}
# Update the version to just the major/minor revision information
set version [string range $version 0 2]
# Make sure that wish exists
puts -nonewline "Installation requires wish$version... "
flush stdout
if {![file exists [set wish [file join [file dirname [info nameofexecutable]] wish$version]]]} {
puts "Not Found! ($wish)"
exit 1
} else {
puts "Found ($wish)"
}
# Make sure that the Tk package is available on the system
puts -nonewline "Installation requires the Tk package... "
flush stdout
if {[catch "package require Tk" rc]} {
puts "Not Found! ($rc)"
puts "Install tk8.6 package"
exit 1
} else {
puts "Found"
}
# Make sure that the Tclx package is available on the system
puts -nonewline "Installation requires the Tclx package... "
flush stdout
if {[catch "package require Tclx" rc]} {
puts "Not Found! ($rc)"
puts "Install tclx package"
exit 1
} else {
puts "Found"
}
# Make sure that the Tcllib package is available on the system
puts -nonewline "Installation requires the Tcllib package... "
flush stdout
if {[catch "package require struct::set" rc]} {
puts "Not Found! ($rc)"
puts "Install tcllib package"
exit 1
} else {
puts "Found"
}
# Make sure that the Tklib package is available on the system
puts -nonewline "Installation requires the Tklib package... "
flush stdout
if {[catch "package require tooltip" rc]} {
puts "Not Found! ($rc)"
puts "Install tklib package"
exit 1
} else {
puts "Found"
}
# Check to see if tkdnd package is available on the system
puts -nonewline "Checking for tkdnd package... "
flush stdout
if {[catch "package require tkdnd" rc]} {
puts "Not Found (Drag and drop support will be disabled)"
puts "Install tkdnd package"
} else {
puts "Found"
}
# Check to see if Expect package is available on the system
puts -nonewline "Checking for Expect package... "
flush stdout
if {[catch "package require Expect" rc]} {
puts "Not Found (SFTP support will be disabled)"
puts "Install expect package"
} else {
puts "Found"
}
# Check to see if Img package is available on the system
puts -nonewline "Checking for Img package... "
flush stdout
if {[catch "package require Img" rc]} {
puts "Not Found (Only .gif, .bmp and .png images will be previewable in the file information panel)"
} else {
puts "Found"
}
# Check to see if the tcl-vfs package is available on the system
puts -nonewline "Checking for tcl-vfs package... "
flush stdout
if {[catch "package require vfs" rc]} {
puts "Not Found! (Zip/Unzip functions will use zip/unzip on the system)"
puts "Install tcl-vfs package"
} else {
puts "Found"
}
proc get_yes_or_no {question} {
set answer "x"
while {![regexp {^([yn]?)$} [string tolower $answer] -> answer]} {
puts -nonewline "$question (Y/n)? "
flush stdout
set answer [gets stdin]
}
return $answer
}
proc copy_lib_files {lib_dir} {
# Create the lib directory
file mkdir $lib_dir
# Copy each of the top-level directories recursively to the new lib directory
foreach {src dst} [list data data doc doc lib lib plugins plugins specl specl LICENSE LICENSE \
[file join scripts uninstall.tcl] uninstall.tcl] {
puts -nonewline "Copying $src to [file join $lib_dir $dst]... "
flush stdout
if {[catch "file copy $src $lib_dir" rc]} {
puts "error!"
puts " $rc"
return
} else {
puts "done."
}
}
}
set install_dir ""
while {$install_dir eq ""} {
# Get the installation directory from the user
puts -nonewline "\nEnter root installation directory (or Control-C to quit): "
flush stdout
set install_dir [file normalize [gets stdin]]
set lib_dir [file join $install_dir lib tke]
set bin_dir [file join $install_dir bin]
# Make sure that the library directory can be written
if {[file exists [file dirname $lib_dir]] && ![file writable [file dirname $lib_dir]]} {
puts "[file dirname $lib_dir] is not writable"
set install_dir ""
continue
}
# Make sure that the binary directory can be written
if {[file exists $bin_dir] && ![file writable $bin_dir]} {
puts "$bin_dir is not writable"
set install_dir ""
continue
}
# Output path information to user
puts ""
puts "Library will be installed at: $lib_dir"
puts "Binary will be installed at: [file join $bin_dir tke]"
puts ""
# If the specified root directory is okay, install everything there
if {[get_yes_or_no "Is this okay"] ne "n"} {
puts ""
# Copy directories to lib directory
if {[file exists $lib_dir]} {
if {[get_yes_or_no "$lib_dir exists. Replace"] ne "n"} {
puts ""
file delete -force $lib_dir
copy_lib_files $lib_dir
} else {
set install_dir ""
continue
}
} else {
copy_lib_files $lib_dir
}
# Create the bin directory if it doesn't exist
if {![file exists $bin_dir]} {
file mkdir $bin_dir
}
# Create the file
puts -nonewline "Creating [file join $bin_dir tke]... "
flush stdout
if {![catch "open [file join $bin_dir tke] w" rc]} {
puts $rc "#!/bin/sh"
puts $rc ""
puts $rc "$wish [file join $lib_dir lib tke.tcl] -name tke -- \$@"
close $rc
file attributes [file join $bin_dir tke] -permission rwxr-xr-x
puts "done."
} else {
puts "error."
puts " $rc"
set install_dir ""
continue
}
} else {
set install_dir ""
}
}
# If we are running on a system with a /usr/share/applications directory, create a tke.desktop file there
if {[file exists [set app_dir [file join / usr share applications]]]} {
set app_file [file join $app_dir tke.desktop]
puts -nonewline "Creating $app_file... "
flush stdout
if {![catch "open $app_file w" rc]} {
puts $rc "\[Desktop Entry\]"
puts $rc "Name=TKE"
puts $rc "Exec=$wish [file join $lib_dir lib tke.tcl] -name tke -- -nosb %f"
puts $rc "Icon=[file join $lib_dir lib images tke_logo.svg]"
puts $rc "Type=Application"
puts $rc "Comment=Advanced code editor"
puts $rc "Categories=Programming;Development;Utility;TextEditor"
puts $rc "GenericName=Text Editor"
puts $rc "MimeTypes=text/plain;text/html;text/css;text/x-script.csh;text/x-fortran;text/x-java-source;text/javascript;text/x-pascal;text/pascal;text/x-script.python;text/x-asm;text/xml;text/x-script.tcl;application/x-tkethemz;application/x-tkeplugz"
close $rc
puts "done."
} else {
puts "not done."
}
}
# Create the MIME file so that the TKE theme and plugin bundle file extensions will be opened by TKE
if {[file exists [set mime_dir [file join / usr share mime packages]]]} {
set mime_file [file join $mime_dir tke.xml]
set mime_icon_dir [file join / usr share icons hicolor scalable mimetypes]
puts -nonewline "Creating mime file $mime_file... "
flush stdout
if {![catch "open $mime_file w" rc]} {
puts $rc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
puts $rc "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">"
puts $rc " <mime-type type=\"application/x-tkethemz\">"
puts $rc " <comment>TKE theme bundle</comment>"
puts $rc " <generic-icon name=\"application-x-tkethemz\"/>"
puts $rc " <glob pattern=\"*.tkethemz\"/>"
puts $rc " </mime-type>"
puts $rc " <mime-type type=\"application/x-tkeplugz\">"
puts $rc " <comment>TKE plugin bundle</comment>"
puts $rc " <generic-icon name=\"application-x-tkeplugz\"/>"
puts $rc " <glob pattern=\"*.tkeplugz\"/>"
puts $rc " </mime-type>"
puts $rc "</mime-info>"
close $rc
puts "done."
puts -nonewline "Updating mime database... "
flush stdout
catch { file copy -force [file join $lib_dir lib images tke_theme.svg] [file join $mime_icon_dir application-x-tkethemz.svg] }
catch { file copy -force [file join $lib_dir lib images tke_plugin.svg] [file join $mime_icon_dir application-x-tkeplugz.svg] }
if {![catch { exec -ignorestderr update-mime-database [file join / usr share mime] }]} {
puts "done."
} else {
puts "not done."
catch { file delete -force $mime_file }
}
} else {
puts "not done."
}
}
# If we are running on a system that can use appdata, add the file there
if {[file exists [set appdata_dir [file join / usr share appdata]]]} {
puts -nonewline "Copying tke.appdata.xml to [file join $appdata_dir tke.appdata.xml]... "
flush stdout
if {[catch "file copy [file join data tke.appdata.xml] $appdata_dir"]} {
puts "not done."
} else {
puts "done."
}
}
# Check to see if the bin directory is in the user's path
if {[lsearch [split $env(PATH) :] $bin_dir] == -1} {
puts "\n$bin_dir is not in your PATH environment variable list."
puts "Make sure that you put this directory into your path in your startup script.\n"
}
# Exit the application
exit