Repository navigation
Expand file tree
/
Copy pathinstall.tcl
More file actions
executable file
·473 lines (380 loc) · 16.5 KB
/
Copy pathinstall.tcl
File metadata and controls
executable file
·473 lines (380 loc) · 16.5 KB
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#!/usr/bin/env tclsh
#LostMVC installation
package require nx
source [file dir [info script]]/lostshell.tcl
nx::Object create InstallLostMVC -object-mixin LostShell {
:public object method install {} {
if {[:jumpToFunction]} {
:confirmStart
:installationPrequisitories
:installActiveTcl
:installNaviServer
:installNextScripting
:installAndConfigurePostgreSQL
:installNaviServerModules
:installLostMVC
puts "LostMVC and its prequisitories should be installed by now. Have fun!"
}
}
:object method jumpToFunction {} {
if {[info exists ::argv]} {
if {$::argv != ""} {
set :acceptAllDefault 0
set firstWord [lindex $::argv 0]
set secondToLastWord [lrange $::argv 1 end]
:configurationSetup
puts "Running $firstWord $secondToLastWord"
if {[:info lookup method $firstWord] != "" } {
:$firstWord {*}$secondToLastWord
} else { puts "Sorry, the command $firstWord doesn't exist.. try using \"help\"" }
return 0
}
}
return 1
}
:object method help {} {
set allMethods [:info lookup methods]
puts "All methods: \n $allMethods"
}
:object method confirmStart {} {
if {[colorterm]} { background black; }
set confirm "Hello, welcome to the LostMVC installation process."
set options [list 1 "Do a full install (accept all default things)" 2 "Let me confirm each step" 3 "No thanks (exit)"]
set result [:terminal:confirm:continue -default 3 -options $options $confirm]
switch -- $result {
1 { set :acceptAllDefault 1 }
2 { set :acceptAllDefault 0 }
3 { puts "Have a nice day!"; exit }
}
}
:object method installationPrequisitories {} {
#Read configuration
:configurationSetup
:goToTempDir
}
:object method configurationSetup {} {
set scriptLocation [file dirname [info script]]
if {$scriptLocation == "."} { set scriptLocation [pwd] }
set configFileLocation $scriptLocation/lostmvc.config
puts "Reading configuration file (for any download changes refer to $configFileLocation) "
set configFile [open $configFileLocation r]
set :configuration [chan read $configFile]
chan close $configFile
set cores [exec grep -c ^processor /proc/cpuinfo]
dict set :configuration cores $cores
dict set :configuration scriptLocation $scriptLocation
}
:object method goToTempDir {} {
file mkdir lostmvctemp
cd lostmvctemp
puts "Created lostmvctemp/ folder going to [pwd]"
}
#the exec >&@stdout command allows us to capture bouth stdout and stderror to show it DIRECTLY to the user
# this happens in silence, no error is trown
# The followign might be usefull if having problems
# chan configure stdout -buffering none
:object method installActiveTcl {} {
set confirm "Install ActiveTCL? (It's advised if you didn't already install it, so you can install extra tcl packages with teacup) "
if {![:terminal:confirm:continue -default y $confirm]} { return }
set confirm "32 or 64 bit version?"
set bit [:terminal:confirm:continue -default 64 -options [list 32 "32 bit" 64 "64 bit"] $confirm]
set fileurl [dict get ${:configuration} activetcl $bit ]
:downloadExtractAndCD ActiveTCL $fileurl
puts "Running the ActiveTcl installation (this will require root access):"
exec >&@stdout sudo ./install.sh
puts "Setting up shortcuts for ActiveTcl"
exec >&@stdout sudo ln -fs /opt/ActiveTcl-8.6/bin/tclsh8.6 /usr/bin/tclsh
exec >&@stdout sudo ln -fs /opt/ActiveTcl-8.6/bin/tclsh8.6 /usr/bin/tcl
exec >&@stdout sudo ln -fs /opt/ActiveTcl-8.6/bin/tkcon /usr/bin/tkcon
exec >&@stdout sudo ln -fs /opt/ActiveTcl-8.6/bin/teacup /usr/bin/teacup
#library stuff
exec >&@stdout sudo ln -fs /opt/ActiveTcl-8.6/lib/teapot/ /usr/lib/teapot
exec >&@stdout sudo ln -fs /opt/ActiveTcl-8.6/lib/libtcl8.6.so /usr/lib
exec >&@stdout sudo ln -fs /opt/ActiveTcl-8.6/lib/libtk8.6.so /usr/lib
puts "ActiveTcl installed successfully!"
cd [dict get ${:configuration} scriptLocation]
}
#works only with tar.gz files at the moment..
##TODO Figure out .zip / .tar.gz .bzip etc files
:object method downloadExtractAndCD {{-outputFile "" } {-folder ""} name fileurl} {
puts "Downloading $name"
#reconfirms and retries to download
if {![file exists [file tail $fileurl]] || [file exists $outputFile]} {
if {$outputFile != ""} {
exec >&@stdout wget -c -O $outputFile $fileurl
set filename $outputFile
} else {
exec >&@stdout wget -c $fileurl
set filename [file tail $fileurl]
}
puts "Extracting the archive file: "
exec >&@stdout tar zxf $filename
} else { set filename [expr {$outputFile !="" ? $outputFile : [file tail $fileurl] }] }
if {$folder == ""} {
set folder [file rootname [file rootname $filename]]
}
cd $folder
}
:object method installTcl {{-bit:choice,arg=32|64 32}} {
puts "Default installation goes with ActiveTcl type N to compile the latest stable Tcl version"
}
:object method installNaviServer {} {
set confirm "Download, Compile and Install NaviServer? Webserver for running LostMVC. Default location /opt/ns"
if {![:terminal:confirm:continue -default y $confirm]} { return }
set fileurl [dict get ${:configuration} naviserver webserver ]
#:downloadExtractAndCD -outputFile naviserver.tar.gz NaviServer $fileurl
:downloadExtractAndCD NaviServer $fileurl
foreground green
puts "Configuring & Installing NaviServer (with [dict get ${:configuration} cores] cores) "
reset
exec >&@stdout ./configure --prefix=/opt/ns --with-tcl=/opt/ActiveTcl-8.6/lib/tcl8.6 --enable-symbols
exec >&@stdout make -j[dict get ${:configuration} cores]
exec >&@stdout sudo make install
puts "Setting user permissions"
set nsuser www-data
catch {exec >&@stdout sudo useradd $nsuser}
exec >&@stdout sudo chown -R $nsuser /opt/ns/logs
#Use /opt/ns/www or /home/$user/www ..? for users
catch {exec >&@stdout sudo mkdir /opt/ns/www}
exec >&@stdout sudo chown -R $nsuser:$nsuser /opt/ns/www
#Installing as a service
set confirm "Do you want to install NaviServer as a service in init.d ?"
if {[:terminal:confirm:continue $confirm]} {
catch {file mkdir config}
file copy -force [dict get ${:configuration} scriptLocation]/config .
exec >&@stdout sudo cp config/nsd /etc/init.d/
exec >&@stdout sudo chmod +x /etc/init.d/nsd
exec >&@stdout sudo update-rc.d nsd defaults
exec >&@stdout sudo cp config/nsd.logrotate /etc/logrotate.d/
}
cd [dict get ${:configuration} scriptLocation]
}
:object method installNextScripting {} {
set confirm "Download, Compile and Install Next Scripting Framework ? (OO framework created by maintainers of NaviServer, required by LostMVC) "
if {![:terminal:confirm:continue -default y $confirm]} { return }
set fileurl [dict get ${:configuration} nextscripting ]
:downloadExtractAndCD "Next Scripting Framework" $fileurl
puts "Configuring and installing Next Scripting Framework"
exec >&@stdout ./configure --enable-threads --prefix=/opt/ns/ --with-tcl=/opt/ActiveTcl-8.6/lib/tcl8.6
exec >&@stdout make
exec >&@stdout sudo make install
exec >&@stdout sudo make install-aol
puts "Done installing Next Scripting Framework"
cd [dict get ${:configuration} scriptLocation]
}
:object method installAndConfigurePostgreSQL {} {
set confirm "Do you want to install and configure PostgreSQL Server with libpq-dev support?"
if {![:terminal:confirm:continue -default y $confirm]} { return }
exec sudo locale-gen en_US.UTF-8 ;# We need Correct locale otherwise failure wille nsure
exec sudo apt-get install locales ;# We need Correct locale otherwise failure wille nsure
exec sudo dpkg-reconfigure locales ;# We need Correct locale otherwise failure wille nsure
#export LANGUAGE=en_US.UTF-8
#export LANG=en_US.UTF-8
#export LC_ALL=en_US.UTF-8
#sudo pg_createcluster 9.4 main --start
puts "INstalling PostgreSQL webserver and libpq-dev "
exec >&@stdout sudo apt-get install postgresql postgresql-contrib libpq-dev
set password [:terminal:confirmPassword "Configuring Postgresql, please enter a password for postgres (used for database and linux user with FULL ACCESS)"]
exec >&@stdout sudo su postgres -c "psql -c \"ALTER USER postgres WITH PASSWORD '$password';\""
#exec >&@stdout echo -e "$password\n$password\n" | passwd postgres
puts "Enter a username to be used for connecting to PostgreSQL (using something different than postgres is good for security):"
gets stdin username
set password [:terminal:confirmPassword "Enter password for user $username"]
puts "Creating role"
exec >&@stdout sudo su postgres -c "psql -c \" CREATE ROLE $username WITH LOGIN PASSWORD '$password' VALID UNTIL '2099-01-01';\" "
exec >&@stdout sudo su postgres -c "psql -c \" ALTER USER lostone WITH PASSWORD '$password';\""
# exec >&@stdout sudo su postgres -c psql -c
#
#Modifying peer to md5 ONLY AFTER we setup everything
exec >&@stdout sudo vim -c ":%s/\s\s\s\speer/\tmd5/" -c ":wq!" /etc/postgresql/9.4/main/pg_hba.conf
exec >&@stdout sudo service postgresql restart
puts "Modified peer to md5 in /etc/postgres/9.3/main/pg_hba.conf restarting postgres.."
}
#TODO install
# TclOO nx nx::serializer msgcat tclgd base64 json
#sudo teacup install tclgd
#sudo teacup install json
:object method installNaviServerModules {} {
#nsdbi
#nsdbipg
#nsssl
set confirm "Download, Compile and Install the following NaviServer modules: \n nsdbi nsdbipg nsssl \n "
if {![:terminal:confirm:continue -default y $confirm]} { return }
set fileurl [dict get ${:configuration} naviserver modules ]
:downloadExtractAndCD -folder modules "NaviServer Modules" $fileurl
:installNaviServerModule:nsdbi
:installNaviServerModule:nsdbipg
:installNaviServerModule:nsssl
#Optional
set confirm "Install NaviServer nsdbimy MySQL module ?"
if {[:terminal:confirm:continue -default n $confirm]} { :installNaviServerModule:nsdbimy }
set confirm "Install NaviServer nsdbilite SQLite module ?"
if {[:terminal:confirm:continue -default n $confirm]} { :installNaviServerModule:nsdbilite }
puts "If you want to install anyother module you can just go to the modules folder and follow the compilation instructions"
cd [dict get ${:configuration} scriptLocation]
}
:object method installNaviServerModule:nsdbi {} {
cd nsdbi
exec >&@stdout make NAVISERVER=/opt/ns
exec >&@stdout sudo make NAVISERVER=/opt/ns install
cd ..
}
:object method installNaviServerModule:nsdbipg {} {
cd nsdbipg
exec >&@stdout make NAVISERVER=/opt/ns PGINCLUDE=/usr/include/postgresql
exec >&@stdout sudo make NAVISERVER=/opt/ns PGINCLUDE=/usr/include/postgresql install
cd ..
}
:object method installNaviServerModule:nsssl {} {
cd nsssl
exec >&@stdout make NAVISERVER=/opt/ns
exec >&@stdout sudo make NAVISERVER=/opt/ns install
cd ..
}
#TODO nsdbimy
#sudo apt-get install libmysqlclient-dev
#TODO install new SSL certificate?
:object method createNew {} {
cd [dict get ${:configuration} scriptLocation]
set confirm "Create new SSL certificate?"
if {![:terminal:confirm:continue -default y $confirm]} { return }
exec >&@stdout sudo rm -rf /opt/ns/tcl/lostmvc
exec >&@stdout sudo cp -rf tcl /opt/ns/tcl/lostmvc c
#file delete -force -- /opt/ns/tcl/lostmvc
#file copy tcl /opt/ns/tcl/lostmvc
puts "Installed new LostMVC Tcl files"
}
:object method installLostMVC {{-host ""} {-user ""}} {
cd [dict get ${:configuration} scriptLocation]
if {$host == ""} { set location "At location /opt/ns/tcl/lostmvc " } else {
set location "At remote host $user@$host ? "
}
set confirm "Install LostMVC $location "
if {![:terminal:confirm:continue -default y $confirm]} { return }
if {$host == ""} {
exec >&@stdout sudo rm -rf /opt/ns/tcl/lostmvc
exec >&@stdout sudo cp -rf tcl /opt/ns/tcl/lostmvc
exec >&@stdout sudo chown -R www-data:www-data /opt/ns/tcl/lostmvc
#file delete -force -- /opt/ns/tcl/lostmvc
#file copy tcl /opt/ns/tcl/lostmvc
} else {
#exec rsync -ave ssh --rsync-path=sudo\ rsync /opt/ns/www/lostmvc/tcl/ $user@$host:/opt/ns/tcl/lostmvc/
if {0} {
sudo visudo
%rsync ALL=(ALL) NOPASSWD:/usr/bin/rsync
sudo addgroup rsync
#VERY IMPORTANT TO NOT REMOVE USER FROMK OTHER GROUPA!
sudo usermod -a -G rsync lostone
}
exec >&@stdout rsync -ave ssh --rsync-path=sudo\ rsync /opt/ns/www/lostmvc/tcl/ $user@$host:/opt/ns/tcl/lostmvc/
# exec >&@stdout ssh -t $user@$host "sudo cp -R lostmvc /opt/ns/tcl/lostmvc"
# exec >&@stdout sudo chown -R www-data:www-data /opt/ns/tcl/lostmvc
}
puts "Installed new LostMVC Tcl files $location !"
}
:object method updateDomain { domain } {
cd [dict get ${:configuration} scriptLocation]
set localLocation /opt/ns/www/$domain
if {[file exists $localLocation/www]} {
set config [:readConfigFile $localLocation/config ]
foreach {k v} $config { set $k $v }
exec >&@stdout rsync -ave 'ssh -C' --rsync-path=sudo\ rsync $localLocation/www $user@$host:$location
puts "Done sync'ing the domain!"
} else {
puts "$domain doesn't seem to exist, sorry!"
}
}
:object method readConfigFile { configFile } {
if {[file exists $configFile]} {
set file [open $configFile r]
set data [read $file]
close $file
return $data
} else {
#Ask details and write to file!
puts "No configuration file detected."
dict set config host [:terminal:confirm "What hostname to connect to?"]
dict set config user [:terminal:confirm "What username to use?"]
dict set config location [:terminal:confirm "What's the location? Usually something like /var/www/$host/www"]
dict set config modules [:terminal:confirm "Which modules to update? "]
set file [open $configFile w]
puts $file $config
close $file
return $config
}
}
#TODO Finish and test
:object method installNewDomain {{-username ""} {-password ""} domain} {
set nsuser www-data
set domainFolder /opt/ns/www/$domain
if {[file exists $domainFolder ]} { puts "The $domain domain already exists. Try using update $domain " ; exit}
if {$username == ""} {
set username $domain
exec >&@stdout adduser $username
#passwd $username
exec >&@stdout sudo echo -e "$password\n$password\n" | passwd $username
}
exec >&@stdout sudo mkdir -p $domainFolder/www
exec >&@stdout sudo chown -R $username:$nsuser $domainFolder
#710 is better since it gives owner full power, group execute and the rest NOTHING.. so
#no one can access things
#Running generator.adp you have to set permissions 770 temporarily till it writes data
#then set it to 710 or 750 again
#Install Database
#SWITCH BETWEEN BIND AND LOCAL HOSTS!
#Add domain to hosts
exec >&@stdout echo "127.0.0.1 $domain" | sudo tee --append /etc/hosts
#TODO add domain to BIND!
:copyDomainData $domainFolder
exec >&@stdout sudo chown -R $username:$nsuser $domainFolder
exec >&@stdout sudo chmod -R 750 $domainFolder
}
:object method copyDomainData {domain} {
foreach {folder} {img js css fonts lang} {
file copy [pwd]/$folder $domain/www/$folder
# file attributes $domain/www/$folder -group www-data
puts "Copied $folder/ folder.. to $domain/$folder"
}
foreach folder {modules controllers models views sessions templates tcl} {
file mkdir $domain/www/$folder
puts "Creating $domain/$folder folder "
}
#Copy Important Views
set folder views
foreach file {column2.adp layout.adp generator_layout.adp} {
file copy [pwd]/$folder/$file $domain/www/$folder/$file
# file attributes $domain/www/$folder/$file -group www-data
}
puts "Finished copying important Views"
file copy [pwd]/index.adp $domain/www/
file copy [pwd]/tcl/config.adp $domain/www/tcl/config.adp
foreach module {system rbac} {
set folder modules/$module
file copy [pwd]/$folder $domain/www/$folder
# file attributes $domain/www/$folder -group www-data
puts "Finished copying $module Module"
}
}
:object method module {args} {
lassign $args domain module
if {$::argc <= 2} { puts "Usage: module <domain> <module> "; exit }
if {![file exists /opt/ns/www/$domain]} { puts "The $domain domain doesn't exist, try again [pwd]" ; exit}
if {![file exists modules/$module]} {
puts "This module doesn't exist."
puts [:getModules] ; exit}
set moduleLocation /opt/ns/www/$domain/www/modules/$module
file delete -force $moduleLocation
file copy modules/$module $moduleLocation
exec >&@stdout sudo chgrp -R www-data $moduleLocation
exec >&@stdout sudo chmod -R g+w $moduleLocation
puts "Installed $module in $domain/modules/$module"
}
:object method getModules {} {
return "Available modules: \n\t[join [glob -type d modules/*] \n\t]"
}
}
if {[info exists argv0]} {
if { [info script] eq $::argv0 || [starkit::startup] eq "sourced"} {
InstallLostMVC install
}
}