Skip to content

Instantly share code, notes, and snippets.

@tairun
Last active September 27, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tairun/19b0176b687bb320df90 to your computer and use it in GitHub Desktop.
Save tairun/19b0176b687bb320df90 to your computer and use it in GitHub Desktop.
#Hello
write-host "Hello. This script will install php-cs-fixer for you." -foregroundcolor DarkGreen -backgroundcolor white
$PSVersionTable.PSVersion
#functions and variables
if ($env:TEMP -eq $null) {
$env:TEMP = Join-Path $env:SystemDrive 'temp'
}
if (![System.IO.Directory]::Exists($env:TEMP)) {
Write-Host "Creating temporary download directory in env:TEMP" -foregroundcolor DarkBlue -backgroundcolor white
[System.IO.Directory]::CreateDirectory($env:TEMP)
}
$php_path = Join-Path $env:WINDIR "php"
#download stuff
$url1 = "http://get.sensiolabs.org/php-cs-fixer.phar"
$file1 = Join-Path $env:TEMP "php-cs-fixer"
Write-Host "--> Downloading $url1 to $file1" -foregroundcolor DarkRed -backgroundcolor white
wget $url1 -Outfile $file1
$url2 = "http://windows.php.net/downloads/releases/php-5.6.13-nts-Win32-VC11-x86.zip"
$file2 = Join-Path $env:TEMP "php.zip"
Write-Host "--> Downloading $url2 to $file2" -foregroundcolor DarkRed -backgroundcolor white
wget $url2 -Outfile $file2
#Copy php-cs-fixer
Write-Host "Copying php-cs-fixer to $env:WINDIR" -foregroundcolor DarkBlue -backgroundcolor white
copy-item $file1 "$env:WINDIR"
#Create directory for php installation if it doesn't yet exist
if (![System.IO.Directory]::Exists($php_path)) {
Write-Host "Createing directory for php installation in $php_path" -foregroundcolor DarkBlue -backgroundcolor white
[System.IO.Directory]::CreateDirectory($php_path)
}
#unzip and copy (overwriting)
Write-Host "Unzipping php installation to $php_path" -foregroundcolor DarkBlue -backgroundcolor white
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($file2)
$destination = $shell_app.namespace($php_path)
$destination.Copyhere($zip_file.items(), 0x14)
#Add php directory to USERS path variable
Write-Host "Adding php to environment" -foregroundcolor DarkBlue -backgroundcolor white
$old_path=(Get-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\Environment' -Name PATH).Path
$new_path=$old_path+";$php_path"
Set-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\Environment' -Name PATH –Value $new_path
#Cleaning temp stuff
Write-Host "Removing temporary files..." -foregroundcolor DarkRed -backgroundcolor white
rm $file1
rm $file2
#Wait for user input to terminate
Write-Host "All done! Bye for now." -foregroundcolor DarkGreen -backgroundcolor white
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment