Source

BlingNode / tools_init.py

Full commit
  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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
import os
import re
from subprocess import PIPE, Popen

import common
common = __import__('common')

############################# Mercurial repo directory
HG_REPO="/var/lib/hg/"#+PROJECT_NAME

############################# Subversion repo directory
SVN_REPO="/var/lib/svn/"#+PROJECT_NAME

############################# Trac env directory
TRAC_ENV="/var/lib/trac/"#+PROJECT_NAME

############################# AjaXplorer file storage directory
FILE_STORAGE="/var/lib/files/"#+PROJECT_NAME

############################# Options
TRAC_ENV_WANTED=""
HG_REPO_WANTED=""
SVN_REPO_WANTED=""
FILE_STORAGE_WANTED=""

############################# Repo choice
REPO=""

def mercurial_repo_setup(project_name):
    """
        Sets up the Mercurial repository for the site
    """
    global HG_REPO, HG_REPO_WANTED
    #append project name
    HG_REPO =HG_REPO+project_name

    HG_REPO_WANTED =common.ask_yes_or_no("\n\nWould you like to create a Mercurial repo? (y/n)")

    cgi_file ="/var/lib/hg/"+project_name+".cgi"

    if HG_REPO_WANTED == "y":
    # repo is wanted so make it

        def to_do():
            print "\n---- Making Mercurial repo ----"
            common.command_line_call("""sudo hg init """+HG_REPO)
            print "-- Created Mercurial repo --"

            print "-- Creating new hgrc config file --"
            common.command_line_call("""sudo cp /var/lib/misc/blingnode/lib/mercurial-init-collection/hgrc """+HG_REPO+"""/.hg/""")

            print "-- Now let apache own it --"
            common.command_line_call("""chown -R www-data:www-data """+HG_REPO)

            print "-- Also let apache own the .hg directory --"
            common.command_line_call("""sudo chown -R www-data:www-data """+HG_REPO+"""/.hg""")
            common.command_line_call("""sudo chown root:root """+HG_REPO+"""/.hg/hgrc""")

            print "-- Create necessary CGI file --"
            common.copy_and_sub(r"/var/lib/misc/blingnode/lib/mercurial-init-collection/hgweb-template.cgi",cgi_file,r"PROJECT_NAME",project_name)

            print "---- Mercurial repo Created ----"

            common.check_for_htpasswd_file(project_name)

        if common.does_directory_exist(HG_REPO):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+HG_REPO+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+HG_REPO+". ---- XXXX", to_do, HG_REPO)

        else:
            to_do()

def svn_repo_setup(project_name):
    """
        Sets up the svn repository for this site
    """
    global SVN_REPO, SVN_REPO_WANTED

    SVN_REPO_WANTED = common.ask_yes_or_no(query="\nWould you like to create an svn repo? (y/n)")

    SVN_REPO = SVN_REPO + project_name

    if SVN_REPO_WANTED == "y":

        def to_do():
            print "\n---- Making svn repo ----"
            common.command_line_call("""sudo svnadmin create """+SVN_REPO)
            print "-- Create SVN repo --"
            print "-- Now let apache own it --"
            common.command_line_call("""sudo chown -R www-data:www-data """+SVN_REPO)
            print "---- SVN repo Created ----"

        if common.does_directory_exist(SVN_REPO):
            #common.error_exit(msg="\nDirectory '"+SVN_REPO+"'exists. Exiting script to avoid overwriting the directory.")
            common.on_conflict("XXXX ---- you are going to overwrite "+SVN_REPO+". ---- XXXX", to_do, SVN_REPO)

        else:
            to_do()

def trac_env_setup(project_name):
    """
        Sets up the Trac environment for the site
    """
    global TRAC_ENV, TRAC_ENV_WANTED
    #append project name
    TRAC_ENV =TRAC_ENV+project_name

    def set_trac_env_permissions():
        dir_contents = os.listdir(TRAC_ENV)
        for content in dir_contents:
            #print "setting permission for: "+content
            common.command_line_call("""chown -R www-data:www-data """+TRAC_ENV+"""/"""+content)

    # -- location of all trac plugins > /usr/share/trac/global_plugins
    # -- as long as they are defined in trac.ini, and installed in global_plugins, we will be good

    TRAC_ENV_WANTED = common.ask_yes_or_no("\n\nWould you like to make a Trac Environment? (y/n)")

    if TRAC_ENV_WANTED == "y":
        def to_do():

            def setup_trac_repo():
                """
                    Sets up the repo that trac will use, depending on the user's chosen repo
                    Skips if 'none'/no repo was selected
                """
                global REPO, SVN_REPO, TRAC_ENV

                if REPO=="hg":
                    #---------- Begin hg here document ------- #
                    trac_setup_commands=project_name+"\n\nhg\n\n"
                    trac_command_string = "trac-admin "+TRAC_ENV+" initenv"
                    trac_command_list   = trac_command_string.split(" ")

                    trac_output = Popen(trac_command_list,stdin=PIPE,stdout=PIPE).communicate(input=trac_setup_commands)[0]

                    #write output to /var/lib/misc/blingnode/script-output/
                    common.write_to_script_output("%s_trac_output.txt" % project_name, trac_output)

                    #---------- End hg here document ------- #
                elif REPO=="svn":
                    #---------- Begin svn here document ------- #
                    trac_setup_commands=project_name+"\n\nsvn\n"+SVN_REPO
                    trac_command_string = "trac-admin "+TRAC_ENV+" initenv"
                    trac_command_list   = trac_command_string.split(" ")

                    trac_output = Popen(trac_command_list,stdin=PIPE,stdout=PIPE).communicate(input=trac_setup_commands)[0]

                    #write output to /var/lib/misc/blingnode/script-output/
                    common.write_to_script_output("%s_trac_output.txt" % project_name, trac_output)
                    #---------- End svn here document ------- #
                elif REPO=="none":
                    print "\nNo repo has been setup, skipping trac repo setup.\n"
                else:
                    common.error_exit(msg="Invalid repo choice!")

            print "\n---- Making Trac Environment ----"

            # creating trac env

            setup_trac_repo()

            # importing missing files
            if not common.does_directory_exist("%s/conf" % TRAC_ENV):
                common.command_line_call("sudo mkdir %s/conf" % TRAC_ENV)
            if not common.does_directory_exist("%s/db" % TRAC_ENV):
                common.command_line_call("sudo mkdir %s/db" % TRAC_ENV)
            if not common.does_directory_exist("%s/htdocs" % TRAC_ENV):
                common.command_line_call("sudo mkdir %s/htdocs" % TRAC_ENV)
            if not common.does_directory_exist("%s/.egg-cache" % TRAC_ENV):
                common.command_line_call("sudo mkdir %s/.egg-cache" % TRAC_ENV)
            common.command_line_call("sudo cp -RfT /var/lib/misc/blingnode/lib/trac-init-collection/db %s/db" % TRAC_ENV)
            common.command_line_call("sudo cp -RfT /var/lib/misc/blingnode/lib/trac-init-collection/htdocs %s/htdocs" % TRAC_ENV)
            print "-- Missing Files Imported --"

            # we already have replaced trac.ini, now fix it
            print "-- Replacing trac.ini --"
            common.copy_and_sub("/var/lib/misc/blingnode/lib/trac-init-collection/conf/trac-master.ini",TRAC_ENV+"/conf/trac-master.ini","PROJECT_NAME",project_name,overwrite=True)
            if REPO == "hg":
                common.copy_and_sub("/var/lib/misc/blingnode/lib/trac-init-collection/conf/trac.ini.hg",TRAC_ENV+"/conf/trac.ini","PROJECT_NAME",project_name,overwrite=True)
            elif REPO == "svn":
                common.copy_and_sub("/var/lib/misc/blingnode/lib/trac-init-collection/conf/trac.ini.svn",TRAC_ENV+"/conf/trac.ini","PROJECT_NAME",project_name,overwrite=True)

            #Give it the global plugins
            print "-- Global plugins linked --"
            common.command_line_call("""rm -rf """+TRAC_ENV+"""/plugins""")
            common.command_line_call("""ln -s /usr/share/trac/global_plugins """+TRAC_ENV+"""/plugins""")

            # set proper perms
            print "-- Proper permissions set --"
            set_trac_env_permissions()

            # upgrade needed with plugins from our ini
            print "-- Trac upgraded --"
            common.command_line_call_and_return(r"""sudo trac-admin """+TRAC_ENV+r""" upgrade""", suppress_warnings=True)
            
            # resync for changed repository_type
            common.command_line_call_and_return(r"""sudo trac-admin """+TRAC_ENV+r""" resync""", suppress_warnings=True)

            common.check_for_htpasswd_file(project_name)

            # ask for trac admins
            #print "adding track admins"
            add_trac_admins_now = common.ask_yes_or_no("\nAdd trac admins now? (y/N)")
            if add_trac_admins_now == "y":
                htpasswd_re = r'(?P<name>[A-Za-z0-9\_]+):.+'
                htpasswd_file = open('/var/lib/htpasswd/%s.htpasswd' % project_name, 'rb')
                htpasswd_users = []
                trac_users = []

                for line in htpasswd_file:
                    match = re.search(htpasswd_re, line)
                    htpasswd_users.append(match.group('name'))

                htpasswd_file.close()

                print "\n-- Adding trac admins --"
                print "Available users:"
                for user in htpasswd_users:
                    print " - %s" % user

                while True:
                    if len(trac_users) == len(htpasswd_users):
                        print "WARNING: All users in the HTPASSWD file are already Trac Admins."

                    selected = raw_input('\nEnter name of user or leave blank to move on: ')
                    if not selected:
                        break

                    if selected in trac_users:
                        print "User %s is already a Trac admin!" % selected
                        continue

                    if selected in htpasswd_users:
                        common.command_line_call_and_return("""sudo trac-admin %s permission add %s TRAC_ADMIN""" % (TRAC_ENV, selected),suppress_warnings=True)
                        trac_users.append(selected)
                    else:
                        print '\nThere is no user named %s in the list!' % selected
                        force_admin = common.ask_yes_or_no("Are you sure you want to add '%s' as an Admin? (y/n)" % selected)
                        if force_admin == "y":
                            common.command_line_call("""sudo trac-admin %s permission add %s TRAC_ADMIN""" % (TRAC_ENV, selected))

            print "\n---- Trac env setup complete ----"

            set_trac_env_permissions()

        if common.does_directory_exist(TRAC_ENV):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+TRAC_ENV+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+TRAC_ENV+". ---- XXXX", to_do, TRAC_ENV)
        else:
            to_do()

def ajaxplorer_setup(project_name):
    """
        Sets up the AjaXplorer file storage for the site
    """

    # -- location of AjaXplorer codebase /var/lib/misc/blingnode/lib/ajaxplorer-init-collection
    # -- Location of apache template file is /var/lib/misc/blingnode/lib/ajaxplorer-init-collection/templates/apache-template
    global FILE_STORAGE, FILE_STORAGE_WANTED
    #append project name
    FILE_STORAGE =FILE_STORAGE+project_name

    FILE_STORAGE_WANTED=common.ask_yes_or_no(query="\n\nWould you like to make a File Storage with AjaXplorer? (y/n)")

    if FILE_STORAGE_WANTED == "y":
        def to_do():
            print "\n---- Making File Storage ----"

            #### creating File Storage ####

            # make folder
            common.command_line_call("""mkdir """+FILE_STORAGE)

            # copy over AjaXplorer
            common.command_line_call("""cp -r /var/lib/misc/blingnode/lib/ajaxplorer-init-collection/AjaXplorer-2.5.5 """+FILE_STORAGE+"""/""")

            # chown folder to www-data
            common.command_line_call("""sudo chown -R www-data:www-data """+FILE_STORAGE)

            print "\n---- File Storage setup complete ----"

            common.check_for_htpasswd_file(project_name)

        if common.does_directory_exist(FILE_STORAGE):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+FILE_STORAGE+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+FILE_STORAGE+". ---- XXXX",to_do, FILE_STORAGE)

        else:
            to_do()




def apache_hg_trac_setup(project_name, domain_name):

    ############################# Only Create Sites-Available file if the User Created an TRAC ENVIRONMENT earlier
    global TRAC_ENV_WANTED
    if TRAC_ENV_WANTED == "y":

        trac_apache_site_available_file="trac."+project_name+"."+domain_name
        trac_apache_site_available="/etc/apache2/sites-available/"+trac_apache_site_available_file

        def to_do():
            print "\n---- Making TRAC Apache Site ----"

            # change values
            common.copy_and_sub("/var/lib/misc/blingnode/lib/apache-files-collection/trac_hg_template", trac_apache_site_available + "_", "PROJECT_NAME", project_name)
            common.copy_and_sub(trac_apache_site_available + "_", trac_apache_site_available, "DOMAIN", domain_name)
            common.command_line_call("sudo rm -f %s_" % trac_apache_site_available)

            # enable site
            print "-- Going to Enable "+trac_apache_site_available_file+" --"
            common.command_line_call("""a2ensite """+trac_apache_site_available_file)

            # restart apache
            common.command_line_call("""/etc/init.d/apache2 reload """)

            # tell user what to setup DNS
            print "---- Success: Apache Trac site setup ----"

        if common.does_file_exist(trac_apache_site_available):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+trac_apache_site_available+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+trac_apache_site_available+". try again. ---- XXXX",to_do,trac_apache_site_available)
        else:
            to_do()

    else:
        print "\n---- You did NOT create a TRAC ENVIRONMENT ----"

def apache_svn_trac_setup(project_name, domain_name):

    ############################# Only Create Sites-Available file if the User Created an TRAC ENVIRONMENT earlier
    global TRAC_ENV_WANTED
    if TRAC_ENV_WANTED == "y":

        trac_apache_site_available_file="trac."+project_name+"."+domain_name
        trac_apache_site_available="/etc/apache2/sites-available/"+trac_apache_site_available_file

        def to_do():
            print "\n---- Making TRAC Apache Site ----"

            # change values
            common.copy_and_sub("/var/lib/misc/blingnode/lib/apache-files-collection/trac_svn_template", trac_apache_site_available + "_", "PROJECT_NAME", project_name)
            common.copy_and_sub(trac_apache_site_available + "_", trac_apache_site_available, "DOMAIN", domain_name)
            common.command_line_call("sudo rm -f %s_" % trac_apache_site_available)

            # enable site
            print "-- Going to Enable "+trac_apache_site_available_file+" --"
            common.command_line_call("""a2ensite """+trac_apache_site_available_file)

            # restart apache
            common.command_line_call("""/etc/init.d/apache2 reload """)

            # tell user what to setup DNS
            print "---- Success: Apache Trac site setup ----"

        if common.does_file_exist(trac_apache_site_available):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+trac_apache_site_available+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+trac_apache_site_available+". try again. ---- XXXX",to_do,trac_apache_site_available)
        else:
            to_do()

    else:
        print "\n---- You did NOT create a TRAC ENVIRONMENT ----"

def apache_mercurial_setup(project_name, domain_name):
    ############################# Only Create Sites-Available file if the User Created an Mercurial Repo Earlier
    global HG_REPO_WANTED
    if HG_REPO_WANTED == "y":

        hg_apache_site_available_file="source."+project_name+"."+domain_name
        hg_apache_site_available="/etc/apache2/sites-available/"+hg_apache_site_available_file

        def to_do():
            print "\n---- Making HG Apache Site ----"

            # change values
            common.copy_and_sub("/var/lib/misc/blingnode/lib/apache-files-collection/source_hg_template", hg_apache_site_available + "_", "PROJECT_NAME", project_name)
            common.copy_and_sub(hg_apache_site_available + "_", hg_apache_site_available, "DOMAIN", domain_name)
            common.command_line_call("sudo rm -f %s_" % hg_apache_site_available)

            # enable site
            print "-- Going to Enable "+hg_apache_site_available_file+" --"
            common.command_line_call("""a2ensite """+hg_apache_site_available_file)

            # restart apache
            common.command_line_call("""/etc/init.d/apache2 reload""")

            # tell user what to setup DNS
            print "---- Success: Apache Mercurial site setup ----"

        if common.does_file_exist(hg_apache_site_available):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+hg_apache_site_available_file+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+hg_apache_site_available+". ---- XXXX",to_do, hg_apache_site_available)
        else:
            to_do()

    else:
        print "\n\n---- You did NOT create an Mercurial REPO ----"
        common.debug_exit()

def apache_svn_setup(project_name, domain_name):
    ############################# Only Create Sites-Available file if the User Created an Mercurial Repo Earlier
    global SVN_REPO_WANTED
    if SVN_REPO_WANTED == "y":

        svn_apache_site_available_file="source."+project_name+"."+domain_name
        svn_apache_site_available="/etc/apache2/sites-available/"+svn_apache_site_available_file

        def to_do():
            print "\n---- Making SVN Apache Site ----"

            # change values
            common.copy_and_sub("/var/lib/misc/blingnode/lib/apache-files-collection/source_svn_template", svn_apache_site_available + "_", "PROJECT_NAME", project_name)
            common.copy_and_sub(svn_apache_site_available + "_", svn_apache_site_available, "DOMAIN", domain_name)
            common.command_line_call("sudo rm -f %s_" % svn_apache_site_available)

            # enable site
            print "-- Going to Enable "+svn_apache_site_available_file+" --"
            common.command_line_call("""a2ensite """+svn_apache_site_available_file)

            # restart apache
            common.command_line_call("""/etc/init.d/apache2 reload""")

            # tell user what to setup DNS
            print "---- Success: Apache Mercurial site setup ----"

        if common.does_file_exist(svn_apache_site_available):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+svn_apache_site_available_file+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+svn_apache_site_available+". ---- XXXX",to_do, svn_apache_site_available)
        else:
            to_do()

    else:
        print "\n\n---- You did NOT create an Mercurial REPO ----"
        common.debug_exit()

def apache_hg_file_storage_setup(project_name, domain_name):
    ############################# Only Create Sites-Available file if the User Created a FILE STORAGE  Earlier
    global FILE_STORAGE_WANTED
    if FILE_STORAGE_WANTED == "y":

        file_storage_apache_site_available_file="files."+project_name+"."+domain_name
        file_storage_apache_site_available="/etc/apache2/sites-available/"+file_storage_apache_site_available_file

        def to_do():
            print "\n---- Making FILE STORAGE Apache Site ----"

            # change values
            common.copy_and_sub("/var/lib/misc/blingnode/lib/apache-files-collection/files_hg_template", file_storage_apache_site_available + "_", "PROJECT_NAME", project_name)
            common.copy_and_sub(file_storage_apache_site_available + "_", file_storage_apache_site_available, "DOMAIN", domain_name)
            common.command_line_call("sudo rm -f %s_" % file_storage_apache_site_available)

            # enable site
            print "-- Going to Enable "+file_storage_apache_site_available+" --"
            common.command_line_call("""a2ensite """+file_storage_apache_site_available_file)

            # restart apache
            common.command_line_call("""/etc/init.d/apache2 reload """)

            # tell user what to setup DNS
            print "---- Success: Apache File site setup. ----"

        if common.does_file_exist(file_storage_apache_site_available):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+file_storage_apache_site_available+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+file_storage_apache_site_available+". ---- XXXX",\
to_do, file_storage_apache_site_available)

        else:
            to_do()
    else:
        print "\n---- You did NOT create a FILE STORAGE ----"

def apache_svn_file_storage_setup(project_name, domain_name):
    ############################# Only Create Sites-Available file if the User Created a FILE STORAGE  Earlier
    global FILE_STORAGE_WANTED
    if FILE_STORAGE_WANTED == "y":

        file_storage_apache_site_available_file="files."+project_name+"."+domain_name
        file_storage_apache_site_available="/etc/apache2/sites-available/"+file_storage_apache_site_available_file

        def to_do():
            print "\n---- Making FILE STORAGE Apache Site ----"

            # change values
            common.copy_and_sub("/var/lib/misc/blingnode/lib/apache-files-collection/files_svn_template", file_storage_apache_site_available + "_", "PROJECT_NAME", project_name)
            common.copy_and_sub(file_storage_apache_site_available + "_", file_storage_apache_site_available, "DOMAIN", domain_name)
            common.command_line_call("sudo rm -f %s_" % file_storage_apache_site_available)

            # enable site
            print "-- Going to Enable "+file_storage_apache_site_available+" --"
            common.command_line_call("""a2ensite """+file_storage_apache_site_available_file)

            # restart apache
            common.command_line_call("""/etc/init.d/apache2 reload """)

            # tell user what to setup DNS
            print "---- Success: Apache File site setup. ----"

        if common.does_file_exist(file_storage_apache_site_available):
            #common.error_exit(msg="XXXX ---- you are going to overwrite "+file_storage_apache_site_available+". try again. ---- XXXX")
            common.on_conflict("XXXX ---- you are going to overwrite "+file_storage_apache_site_available+". ---- XXXX",\
to_do, file_storage_apache_site_available)

        else:
            to_do()
    else:
        print "\n---- You did NOT create a FILE STORAGE ----"


def dashboard_symlink(project_name):

    DASHBOARD_SYM_WANTED=common.ask_yes_or_no(query="\nWould you like to create SymLink to the Trac.db for the DASHBOARD? (y/n)")

    trac_db_file="/var/lib/trac/"+project_name+"/db/trac.db"
    dashboard_syms_dir="/var/www/dashboard/env/trunk/trac_dbs/"
    dashboard_sym_file=dashboard_syms_dir+project_name+".db"

    if dashboard_sym_wanted == "y":

        if common.does_file_exist(dashboard_sym_file):
            common.error_exit(msg="\nfile '"+dashboard_sym_file+"' already exists. exiting script to avoid overwriting.")

        else:
            print "\n---- making dashboard symlink repo ----"
            common.command_line_call("""ln -s """+trac_db_file+""" """+dashboard_sym_file)
            print "---- dashboard symlink created ----"

def repo_query():
    while True:
        print "\nWill you use Subversion (svn) or Mercurial (hg) for the site's repository?"
        repo = raw_input("\nEnter repository to be used (svn/hg/none):\n")
        repo = repo.lower()
        if repo=="svn" or repo=="hg" or repo=="none":
            return repo
        else:
            print "\nYou entered an invalid repository. Try again."

def main():
    ####### Check For root Access
    if not common.is_user_root():
        common.error_exit(msg="\nERROR: Run this script as root\n")

    #tell user what we will accomplish
    print "\n\n---- You are setting up a new Collaboration Tools Env.  You will be guided through the following: ----"
    print "---- Mercurial setup/Trac setup/File Storage setup/Apache setup/ ----"

    # show user variables to fill
    project_name = raw_input("\nWhat is the Project Name?\n")
    domain_name = raw_input("\nWhat domain name will this project be in?\n")

    ####### htpasswd setup
    common.check_for_htpasswd_file(project_name, warn_if_exists=True)

    #ask user what repository to use
    global REPO
    REPO = repo_query()

    if REPO=="hg":
        ####### Mercurial repo setup
        print "Mercurial repo selected"
        mercurial_repo_setup(project_name)
    elif REPO=="svn":
        print "SVN repo selected"
        ####### SVN repo setup
        svn_repo_setup(project_name)
    elif REPO=="none":
        print "\nNo repository will be set up.\n"
    else:
        common.error_exit(msg="Invalid repo choice %s" % REPO)

    ####### Trac env setup
    trac_env_setup(project_name)

    ####### AjaXplorer setup
    ajaxplorer_setup(project_name)

    print "\n\n\n---- Creating Sites-Available files for Trac and Mercurial ----"

    if REPO=="hg":
        ####### apache hg trac setup
        apache_hg_trac_setup(project_name, domain_name)

        ####### apache Mercurial setup
        apache_mercurial_setup(project_name, domain_name)

        ####### apache hg file storage setup
        apache_hg_file_storage_setup(project_name, domain_name)

    elif REPO=="svn":
        ####### apache svn trac setup
        apache_svn_trac_setup(project_name, domain_name)

        ####### apache  Subversion setup
        apache_svn_setup(project_name, domain_name)

        ####### apache svn file storage setup
        apache_svn_file_storage_setup(project_name, domain_name)
        
    elif REPO=="none":
        print "\nNo repository will be set up.\n"
        print "sites-available files for trac and file storage will"
        print "  be derived from apache hg templates.\n"

        apache_hg_trac_setup(project_name, domain_name)
        apache_hg_file_storage_setup(project_name, domain_name)
        
    else:
        common.error_exit(msg="Invalid repo choice %s" % REPO)

    ####### DASHBOARD SymLink
    #dashboard_symlink(project_name)

    print "\n\n!!!! SUCCESS !!!!\n\n\n ---- Now you need to: ----\n1. Make DNS Entries in your DNS Manager\n2. Maybe run the django_ve_init.py file to create a new Development Env\n3. Start Using your new Project Environment!"

if __name__ == "__main__":
    main()