Skip to content

Instantly share code, notes, and snippets.

@Kr3m
Created April 10, 2015 21:24
Show Gist options
  • Save Kr3m/5eff4819bedc7c9e09dd to your computer and use it in GitHub Desktop.
Save Kr3m/5eff4819bedc7c9e09dd to your computer and use it in GitHub Desktop.
PowerShell script created to make easy CodeIgniter setups
# CodeIgniter Setup Script by Kevin Remisoski - (old could use some work as noted below)
# Work to be done:
# 1. Merge hosts.pl
# 2. Create menu with support for various frameworks and multi-level for various versions
# 3. Support for grunt, bower, npm, etc..
# Dependencies - git > http://git-scm.com/ && hosts.pl > https://gist.github.com/markembling/173887
# 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.
# 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.
# I hope someone finds this useful. The instructions are easy as noted below:
# 1. open powershell (if you can't execute scripts as an admin, you'll have to google that :P)
# 2. change into a directory and create a new directory for your local web project.
# 3. change into the new directory, save the following code into C:\scripts\ci.ps1
# 4. in the new directory type \scripts\ci.ps1 and hit the tab key and enter.
# 5. set environment variables for KWEBPATH (your web root not your project folder going into it)
# 6. do the same as above for APACHECONF but point it to your conf\extras folder
# 7. ENJOY!
$project = Read-Host 'Type the name of your project with no spaces only dashes.'
$cisource = $env:CIPATH
$ciclone = $cisource + "\..\"
$cipull = $cisource
$cisys = $cisource + "\system"
$cicopy = $ciclone + ".\"
$cigit = "https://github.com/EllisLab/CodeIgniter.git"
$shutupRobo = "/NJH /NJS /NDL /NC /NS /NFL "
echo "If you see a fatal error here, that is normal."
echo "This only means that you already have CodeIgniter cloned."
echo "Proceeding with update!"
cd $ciclone
git clone $cigit
cd $cipull
git pull $cigit
$webpath = $env:KWEBPATH
$pub = "/pub"
$webdir = $webpath + $project + $pub
$apppath = $env:KWEBPATH + $project + "\application\"
New-Item $webdir -Type directory
CD $webdir
echo "`n`nCOPYING FILES`n`n"
Start-Sleep -s 2
ROBOCOPY $cisource .\ /MIR /XD /NJH /NJS /NDL /NC /NS /NFL $cisys
ROBOCOPY .\application ..\application *.* /NJH /NJS /NDL /NC /NS /NFL /E /MOVE
Remove-Item * -Recurse -Force -Include .*,*.txt,*.rst,*.md,tests,user_guide_src
$1 = "<IfModule mod_rewrite.c>"
$2 = "`nRewriteEngine On"
$3 = "`nRewriteBase /"
$4 = "`nRewriteRule ^index\.php$ - [L]"
$5 = "`nRewriteCond %{REQUEST_FILENAME} !-f"
$6 = "`nRewriteCond %{REQUEST_FILENAME} !-d"
$7 = "`nRewriteRule . /index.php [L]"
$8 = "`n</IfModule>"
ni .\.htaccess -Type file -Value ($1 + $2 + $3 + $4 + $5 + $6 + $7 + $8 )
$source = '.\index.php'
$target = $source
$oldsys = "'system';"
$newsys = "`'$cisys`';"
$oldapp = "'application';"
$newapp = "'../application';"
(Get-Content $source) | ForEach-Object {
$_ -replace $oldsys, $newsys `
-replace $oldapp, $newapp
} | Set-Content $target
CD ..\application\config
$a = "'index.php';"
$b = "'';"
(Get-Content .\config.php) | ForEach-Object { $_ -replace $a, $b} | Set-Content .\config.php
$suffix = ".ci"
$ip = "127.0.0.1"
$hdomain = $project + $suffix
$a = "<VirtualHost *:80>"
$b = "`tServerAdmin kevin@CURRENT"
$c = "`tServerName " + $project + $suffix
$d = "`tDocumentRoot `"" + $webdir + "`""
$e = "`n`t<Directory `"" + $webdir + "`">"
$f = "`t`tDirectoryIndex index.php"
$g = "`t`tAllowOverride All"
$h = "`t`tOrder allow,deny"
$i = "`t`tAllow from all"
$j = "`t</Directory>"
$k = "</VirtualHost>"
$projectArray = $a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k
$apacheconf = $env:APACHECONF
$vhost = $apacheconf + "httpd-vhosts.conf"
Add-Content $vhost $projectArray
C:\scripts\hosts.ps1 add $ip $hdomain
echo "This is not a time to freak out. It's just restarting your webserver :P"
Restart-Service Apache2.2
echo "Your Project Has Been Created!"
$newClassPath = $apppath + "controllers\"
CD $newClassPath
$a = "<?php"
$b = "`n"
$c = "/*"
$d = " * class Rock"
$e = " */"
$f = "`n"
$g = "class Rock extends CI_Controller {"
$h = "`n"
$i = "`tfunction __construct()"
$j = "`t{"
$k = "`t`tparent::__construct();"
$l = "`t}"
$m = "`n"
$n = "`tfunction index()"
$o = "`t{"
$p = "`t`techo '<h1>Yeah Baby! Clean URLs by design.</h1>';"
$q = "`t`techo '<h2>Go Back To Home Page...</h2>';"
$r = "`t`t`$this->load->helper('url');"
$s = "`t`techo '<a href=`"' . site_url() . '`">Home</a>';"
$t = "`t}"
$u = "}"
$demoController = $a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u
$newClass = $newClassPath + "rock.php"
Add-Content $newClass $demoController
Start-Sleep -s 2
$website = "http://" + $project + $suffix + "/rock"
START $website
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment