Last active
August 29, 2015 13:56
-
-
Save renzo1974/9066943 to your computer and use it in GitHub Desktop.
Create symlinks on windows from joomla project folders to joomla installation path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() | |
$princ = New-Object System.Security.Principal.WindowsPrincipal($identity) | |
if(!$princ.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) | |
{ | |
$powershell = [System.Diagnostics.Process]::GetCurrentProcess() | |
$psi = New-Object System.Diagnostics.ProcessStartInfo $powerShell.Path | |
$script = $MyInvocation.MyCommand.Path | |
$prm = $script | |
foreach($a in $args) { | |
$prm += ' ' + $a | |
} | |
$psi.Arguments = $prm | |
$psi.Verb = "runas" | |
[System.Diagnostics.Process]::Start($psi) | Out-Null | |
return; | |
} | |
#------------------------------------------------------------------------------------- | |
Function New-SymLink ($link, $target) | |
{ | |
if (test-path -pathtype container $target) | |
{ | |
$command = "cmd /c mklink /d" | |
} | |
else | |
{ | |
$command = "cmd /c mklink" | |
} | |
invoke-expression "$command ""$link"" ""$target""" | |
} | |
#------------------------------------------------------------------------------------- | |
$extName = Read-Host 'Gib den Namen der Komponente ein (z.B. com_joecc)' | |
Add-Type -AssemblyName System.Windows.Forms | |
$extPath = Read-Host 'Gib den Pfad zum Projekt der Joomla-Komponente ein ([ENTER] für Ordnerauswahl-Dialog)' | |
if ([string]::IsNullOrWhiteSpace($extPath)){ | |
write-host 'Der Dialog zur Ordner-Auswahl wurde geöffnet' | |
$FolderBrowserExt = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{ | |
SelectedPath = 'MyDocuments' | |
} | |
[void]$FolderBrowserExt.ShowDialog() | |
$extPath = $FolderBrowserExt.SelectedPath | |
} | |
if (!(Test-Path -Path $extPath)){ | |
Write-Host -ForegroundColor Red -Object 'Der Pfad ist ungültig - Abbruch!' | |
exit 1 | |
} | |
$jPath = Read-Host 'Gib den Pfad zur Joomla Installation ein ([ENTER] für Ordnerauswahl-Dialog)' | |
if ([string]::IsNullOrWhiteSpace($jPath)){ | |
write-host 'Der Dialog zur Ordner-Auswahl wurde geöffnet' | |
$FolderBrowserJ = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{ | |
SelectedPath = 'c:\wamp\www' | |
} | |
[void]$FolderBrowserJ.ShowDialog() | |
$jPath = $FolderBrowserJ.SelectedPath | |
} | |
if (!(Test-Path -Path $extPath)){ | |
Write-Host -ForegroundColor Red -Object 'Der Pfad ist ungültig - Abbruch!' | |
exit 1 | |
} | |
$answer = Read-Host -Prompt ([string]::Format('Ich werde die Komponente im Ordner {0} mit der Joomla-Installation {1} verknüpfen. Korrekt? (J/N) [ENTER = J]',$extPath,$jPath)) | |
$answer = $answer.ToLower() | |
if (($answer -ne 'j') -and !([string]::IsNullOrWhiteSpace($answer))){ | |
Write-Host -ForegroundColor Red -Object 'Ok, du wolltest nicht! Also hab ich aufgehört...' | |
exit 0 | |
} | |
Write-Host -ForegroundColor Green -Object 'Ok, los geht''s!' | |
Write-Host 'Erstelle Admin-Verknüpfung' | |
$extPathAdmin = Join-Path -ChildPath 'admin' -Path $extPath | |
$jPathAdmin = Join-Path -ChildPath 'administrator\components' -Path $jPath | |
$jPathAdmin = Join-Path -childPath $extName -Path $jPathAdmin | |
Remove-Item $jPathAdmin -Force -Recurse | |
New-SymLink $jPathAdmin $extPathAdmin | |
Write-Host 'Erstelle Site-Verknüpfung' | |
$extPathSite = Join-Path -ChildPath 'site' -Path $extPath | |
$jPathSite = Join-Path -ChildPath 'components' -Path $jPath | |
$jPathSite = Join-Path -childPath $extName -Path $jPathSite | |
Remove-Item $jPathSite -Force -Recurse | |
New-SymLink $jPathSite $extPathSite | |
Write-Host 'Erstelle Media-Verknüpfung' | |
$extPathMedia = Join-Path -ChildPath 'media' -Path $extPath | |
$jPathMedia = Join-Path -ChildPath 'media' -Path $jPath | |
$jPathMedia = Join-Path -childPath $extName -Path $jPathMedia | |
Remove-Item $jPathMedia -Force -Recurse | |
New-SymLink $jPathMedia $extPathMedia | |
Write-Host -ForegroundColor Green -Object 'Alles gemacht! Viel Spass beim coden...' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment