@@ -31,6 +31,8 @@ def run(self):
31
31
self .installWordPress ()
32
32
elif self .installApp == 'joomla' :
33
33
self .installJoomla ()
34
+ elif self .installApp == 'git' :
35
+ self .setupGit ()
34
36
35
37
except BaseException , msg :
36
38
logging .writeToFile ( str (msg ) + ' [ApplicationInstaller.run]' )
@@ -50,6 +52,18 @@ def installWPCLI(self):
50
52
except BaseException , msg :
51
53
logging .writeToFile ( str (msg ) + ' [ApplicationInstaller.installWPCLI]' )
52
54
55
+ def installGit (self , tempStatusPath ):
56
+ try :
57
+
58
+ command = 'sudo yum -y install http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm'
59
+ subprocess .call (shlex .split (command ))
60
+
61
+ command = 'sudo yum install git -y'
62
+ subprocess .call (shlex .split (command ))
63
+
64
+ except BaseException , msg :
65
+ logging .writeToFile ( str (msg ) + ' [ApplicationInstaller.installGit]' )
66
+
53
67
54
68
def installWordPress (self ):
55
69
try :
@@ -292,6 +306,148 @@ def installWordPress(self):
292
306
return 0
293
307
294
308
309
+ def setupGit (self ):
310
+ try :
311
+ admin = self .extraArgs ['admin' ]
312
+ domainName = self .extraArgs ['domainName' ]
313
+ username = self .extraArgs ['username' ]
314
+ reponame = self .extraArgs ['reponame' ]
315
+ branch = self .extraArgs ['branch' ]
316
+ tempStatusPath = self .extraArgs ['tempStatusPath' ]
317
+
318
+ statusFile = open (tempStatusPath , 'w' )
319
+ statusFile .writelines ('Checking if GIT installed..,0' )
320
+ statusFile .close ()
321
+
322
+ finalPath = "/home/" + domainName + "/public_html/"
323
+
324
+
325
+ ### Check git
326
+
327
+ try :
328
+ command = 'sudo /usr/local/bin/git --help'
329
+ res = subprocess .call (shlex .split (command ))
330
+
331
+ if res == 1 :
332
+ statusFile = open (tempStatusPath , 'w' )
333
+ statusFile .writelines ('Installing GIT..,0' )
334
+ statusFile .close ()
335
+ self .installGit (tempStatusPath )
336
+ statusFile = open (tempStatusPath , 'w' )
337
+ statusFile .writelines ('GIT successfully installed,40' )
338
+ statusFile .close ()
339
+ except subprocess .CalledProcessError :
340
+ statusFile = open (tempStatusPath , 'w' )
341
+ statusFile .writelines ('Installing GIT..,0' )
342
+ statusFile .close ()
343
+ self .installGit (tempStatusPath )
344
+ statusFile = open (tempStatusPath , 'w' )
345
+ statusFile .writelines ('GIT successfully installed.,40' )
346
+ statusFile .close ()
347
+
348
+ ## Open Status File
349
+
350
+ statusFile = open (tempStatusPath , 'w' )
351
+ statusFile .writelines ('Setting up directories..,40' )
352
+ statusFile .close ()
353
+
354
+ try :
355
+ website = ChildDomains .objects .get (domain = domainName )
356
+ externalApp = website .master .externalApp
357
+
358
+ if admin .type != 1 :
359
+ if website .master .admin != admin :
360
+ statusFile = open (tempStatusPath , 'w' )
361
+ statusFile .writelines ("You do not own this website." + " [404]" )
362
+ statusFile .close ()
363
+ return 0
364
+
365
+ except :
366
+ website = Websites .objects .get (domain = domainName )
367
+ externalApp = website .externalApp
368
+
369
+ if admin .type != 1 :
370
+ if website .admin != admin :
371
+ statusFile = open (tempStatusPath , 'w' )
372
+ statusFile .writelines ("You do not own this website." + " [404]" )
373
+ statusFile .close ()
374
+ return 0
375
+
376
+ ## Security Check
377
+
378
+ if finalPath .find (".." ) > - 1 :
379
+ statusFile = open (tempStatusPath , 'w' )
380
+ statusFile .writelines ("Specified path must be inside virtual host home." + " [404]" )
381
+ statusFile .close ()
382
+ return 0
383
+
384
+ FNULL = open (os .devnull , 'w' )
385
+
386
+ if not os .path .exists (finalPath ):
387
+ command = 'sudo mkdir -p ' + finalPath
388
+ subprocess .call (shlex .split (command ))
389
+
390
+ ## checking for directories/files
391
+
392
+ dirFiles = os .listdir (finalPath )
393
+
394
+ if len (dirFiles ) == 1 :
395
+ if dirFiles [0 ] == ".well-known" :
396
+ pass
397
+ else :
398
+ statusFile = open (tempStatusPath , 'w' )
399
+ statusFile .writelines ("Target directory should be empty before installation, otherwise data loss could occur." + " [404]" )
400
+ statusFile .close ()
401
+ return 0
402
+ elif len (dirFiles ) == 0 :
403
+ pass
404
+ else :
405
+ statusFile = open (tempStatusPath , 'w' )
406
+ statusFile .writelines (
407
+ "Target directory should be empty before installation, otherwise data loss could occur." + " [404]" )
408
+ statusFile .close ()
409
+ return 0
410
+
411
+ ####
412
+
413
+ statusFile = open (tempStatusPath , 'w' )
414
+ statusFile .writelines ('Cloning the repo..,40' )
415
+ statusFile .close ()
416
+
417
+ try :
418
+
419
+ command = 'sudo GIT_SSH_COMMAND="ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no" /usr/local/bin/git clone ' \
420
+ '--depth 1 --no-single-branch [email protected] :' + username + '/' + reponame + '.git -b ' + branch + ' ' + finalPath
421
+ subprocess .call (shlex .split (command ))
422
+
423
+ except subprocess .CalledProcessError , msg :
424
+ statusFile = open (tempStatusPath , 'w' )
425
+ statusFile .writelines ('Failed to clone repository. [404]' )
426
+ statusFile .close ()
427
+ return 0
428
+
429
+ ##
430
+
431
+ command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath
432
+ cmd = shlex .split (command )
433
+ res = subprocess .call (cmd , stdout = FNULL , stderr = subprocess .STDOUT )
434
+
435
+ vhost .addRewriteRules (domainName )
436
+ installUtilities .reStartLiteSpeed ()
437
+
438
+ statusFile = open (tempStatusPath , 'w' )
439
+ statusFile .writelines ("Successfully Installed. [200]" )
440
+ statusFile .close ()
441
+ return 0
442
+
443
+
444
+ except BaseException , msg :
445
+ statusFile = open (tempStatusPath , 'w' )
446
+ statusFile .writelines (str (msg ) + " [404]" )
447
+ statusFile .close ()
448
+ return 0
449
+
450
+
295
451
def installJoomla (self ):
296
452
297
453
try :
0 commit comments