Advertisement
kremisoski

CodeIgniter Powershell Setup Script

Jul 24th, 2013
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # CodeIgniter Setup Script by Kevin Remisoski
  2.  
  3. # Dependencies - git
  4.  
  5. # This is just a powershell script I created.  I just learned powershell a little bit in the last 15 minutes, and thought I'd modify an existing batch file I created to take care of some more advanced features I wanted.
  6.  
  7. # Still left to do:  possibly swap out some of the standard DOS commands for Powershell equivalents, but my top priority when I get up aside from work is recreating my .htaccess file for clean URLs.
  8.  
  9. # I hope someone finds this useful.  The instructions are easy as noted below:
  10.  
  11. # 1.  open powershell (if you can't execute scripts as an admin, you'll have to google that :P)
  12. # 2.  change into a directory and create a new directory for your local web project.
  13. # 3.  change into the new directory, save the following code into C:\scripts\ci.ps1
  14. # 4.  in the new directory type \scripts\ci.ps1 and hit the tab key and enter.
  15. # 5.  set environment variables for KWEBPATH (your web root not your project folder going into it)
  16. # 6.  do the same as above for APACHECONF but point it to your conf\extras folder
  17. # 7.  ENJOY!
  18.  
  19. $project = Read-Host 'Type the name of your project with no spaces only dashes.'
  20. $cisource = $env:CIPATH
  21. $ciclone = $cisource + "\..\"
  22. $cipull = $cisource
  23. $cisys = $cisource + "\system"
  24. $cicopy = $ciclone + ".\"
  25. $cigit = "https://github.com/EllisLab/CodeIgniter.git"
  26. $shutupRobo = "/NJH /NJS /NDL /NC /NS /NFL "
  27.  
  28. echo "If you see a fatal error here, that is normal."
  29. echo "This only means that you already have CodeIgniter cloned."
  30. echo "Proceeding with update!"
  31.  
  32. cd $ciclone
  33. git clone $cigit
  34. cd $cipull
  35. git pull $cigit
  36.  
  37. $webpath = $env:KWEBPATH
  38. $pub = "/pub"
  39. $webdir = $webpath + $project + $pub
  40. $apppath = $env:KWEBPATH + $project + "\application\"
  41. New-Item $webdir -Type directory
  42. CD $webdir
  43.  
  44. echo "`n`nCOPYING FILES`n`n"
  45. Start-Sleep -s 2
  46.  
  47. ROBOCOPY $cisource .\ /MIR /XD /NJH /NJS /NDL /NC /NS /NFL $cisys
  48. ROBOCOPY .\application ..\application *.* /NJH /NJS /NDL /NC /NS /NFL /E /MOVE
  49.  
  50. Remove-Item * -Recurse -Force -Include .*,*.txt,*.rst,*.md,tests,user_guide_src
  51.  
  52. $1 = "<IfModule mod_rewrite.c>"
  53. $2 = "`nRewriteEngine On"
  54. $3 = "`nRewriteBase /"
  55. $4 = "`nRewriteRule ^index\.php$ - [L]"
  56. $5 = "`nRewriteCond %{REQUEST_FILENAME} !-f"
  57. $6 = "`nRewriteCond %{REQUEST_FILENAME} !-d"
  58. $7 = "`nRewriteRule . /index.php [L]"
  59. $8 = "`n</IfModule>"
  60. ni .\.htaccess -Type file -Value ($1 + $2 + $3 + $4 + $5  + $6  + $7  + $8 )
  61.  
  62. $source = '.\index.php'
  63. $target = $source
  64. $oldsys = "'system';"
  65. $newsys = "`'$cisys`';"
  66. $oldapp = "'application';"
  67. $newapp = "'../application';"
  68. (Get-Content $source) | ForEach-Object {
  69. $_ -replace $oldsys, $newsys `
  70. -replace $oldapp, $newapp
  71. } | Set-Content $target
  72. CD ..\application\config
  73. $a = "'index.php';"
  74. $b = "'';"
  75. (Get-Content .\config.php) | ForEach-Object { $_ -replace $a, $b} | Set-Content .\config.php
  76.  
  77. $suffix = ".ci"
  78. $ip = "127.0.0.1"
  79. $hdomain = $project + $suffix
  80.  
  81. $a = "<VirtualHost *:80>"
  82. $b = "`tServerAdmin kevin@CURRENT"
  83. $c = "`tServerName " + $project + $suffix
  84. $d = "`tDocumentRoot `"" + $webdir + "`""
  85. $e = "`n`t<Directory `"" + $webdir + "`">"
  86. $f = "`t`tDirectoryIndex index.php"
  87. $g = "`t`tAllowOverride All"
  88. $h = "`t`tOrder allow,deny"
  89. $i = "`t`tAllow from all"
  90. $j = "`t</Directory>"
  91. $k = "</VirtualHost>"
  92.  
  93. $projectArray = $a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k
  94.  
  95. $apacheconf = $env:APACHECONF
  96. $vhost = $apacheconf + "httpd-vhosts.conf"
  97. Add-Content $vhost $projectArray
  98.  
  99. C:\scripts\hosts.ps1 add $ip $hdomain
  100. echo "This is not a time to freak out.  It's just restarting your webserver :P"
  101. Restart-Service Apache2.2
  102. echo "Your Project Has Been Created!"
  103.  
  104. $newClassPath = $apppath + "controllers\"
  105. CD $newClassPath
  106. $a = "<?php"
  107. $b = "`n"
  108. $c = "/*"
  109. $d = " * class Rock"
  110. $e = " */"
  111. $f = "`n"
  112. $g = "class Rock extends CI_Controller {"
  113. $h = "`n"
  114. $i = "`tfunction __construct()"
  115. $j = "`t{"
  116. $k = "`t`tparent::__construct();"
  117. $l = "`t}"
  118. $m = "`n"
  119. $n = "`tfunction index()"
  120. $o = "`t{"
  121. $p = "`t`techo '<h1>Yeah Baby! Clean URLs by design.</h1>';"
  122. $q = "`t`techo '<h2>Go Back To Home Page...</h2>';"
  123. $r = "`t`t`$this->load->helper('url');"
  124. $s = "`t`techo '<a href=`"' . site_url() . '`">Home</a>';"
  125. $t = "`t}"
  126. $u = "}"
  127.  
  128. $demoController = $a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u
  129. $newClass = $newClassPath + "rock.php"
  130. Add-Content $newClass $demoController
  131.  
  132. Start-Sleep -s 2
  133. $website = "http://" + $project + $suffix + "/rock"
  134. START $website
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement