Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tridion GUI Extension Installer in PowerShell
write-output "/***
* _____ _ _ _____ ______ _ _ _____ _ _ _
* / ____| | | |_ _| | ____| | | (_) |_ _| | | | | |
* | | __| | | | | | | |__ __ _| |_ ___ _ __ ___ _ ___ _ __ | | _ __ ___| |_ __ _| | | ___ _ __
* | | |_ | | | | | | | __| \ \/ / __/ _ \ '_ \/ __| |/ _ \| '_ \ | | | '_ \/ __| __/ _` | | |/ _ \ '__|
* | |__| | |__| |_| |_ | |____ > <| || __/ | | \__ \ | (_) | | | | _| |_| | | \__ \ || (_| | | | __/ |
* \_____|\____/|_____| |______/_/\_\\__\___|_| |_|___/_|\___/|_| |_| |_____|_| |_|___/\__\__,_|_|_|\___|_|
*
*
"
write-output "1********************************************************************"
write-output "* Tridion GUI Extensions Installer 1.2 *"
write-output "* Created by Robert Curlette, Yabolka *"
write-output "* *"
write-output "* Info: Installs a Tridion GUI Extension by doing the following: *"
write-output "* - Copy Editor folder to Webroot/Editors *"
write-output "* - Create VDir in Editors section in Tridion IIS *"
write-output "* - Update System.config *"
write-output "* *"
write-output "* Optional, if existing: *"
write-output "* - Copy dll files to WebRoot bin *"
write-output "* - Copy Model Folder and files *"
write-output "* *"
write-output "* Assumes the following folders exist: *"
write-output "* /Editor/ *"
write-output "* /Editor/Configuration/editor.config *"
write-output "* *"
write-output "* Optional: *"
write-output "* /Model/ *"
write-output "* /Model/Configuration/model.config *"
write-output "* /dlls/ *"
write-output "* *"
write-output "********************************************************************"
# import various stuff we need
[Reflection.Assembly]::LoadWithpartialName("System.Xml.Linq") | Out-Null
[string]$filename #= $args[0]
# Get zip file with GUI Extension - 2 formats, normal and Github
$filename=$args[0]
if($filename -eq $null)
{
$filename = Read-Host "Name of GUI Extension folder or .zip?"
}
if($filename -eq "")
{
write-output 'No GUI Extension specified, exiting'
exit
}
if(!(Test-Path $filename))
{
write-output("Warning: No file with name '" + $filename + "'. Please check filename and try again.")
exit
}
Write-Output("GUI Extension " + $filename + " installation beginning...");
#************* Unzip files *******************
$shell_app=new-object -com shell.application
if($filename.EndsWith(".zip"))
{
$zip_file = $shell_app.namespace((Get-Location).Path + "\$filename")
Write-Output(" Unzipping " + $filename)
$destination = $shell_app.namespace((Get-Location).Path)
$destination.Copyhere($zip_file.items())
}
if($filename.Contains("."))
{
$guiExtensionName = $filename.Split(".")[0]
}
else
{
$guiExtensionName = $filename
}
$editorPath = ".\Editor"
# Exit if no Editor folder found
if(!(Test-Path Editor -pathType container))
{
# Github format
if(Test-Path $guiExtensionName\Editor -pathType container)
{
$editorPath = $guiExtensionName + '\Editor'
}
else
{
write-output ("Error: No 'Editor' folder found. Please make sure your .zip file contans an 'Editor' folder.")
exit
}
}
write-output(" Editor folder found at " + $editorPath)
#************* Editor - Get Install location *******************
$tridionInstallLocationUser = Read-Host "Where is Tridion installed? (Default is C:\Program Files (x86)\Tridion)"
[string]$tridionInstallLocation = "C:\Program Files (x86)\Tridion\"
if($tridionInstallLocationUser -ne "")
{
$tridionInstallLocation = $tridionInstallLocationUser
}
[string]$editorInstallLocation = $tridionInstallLocation + "web\WebUI\Editors\" + $guiExtensionName + "\Editor"
[string]$modelInstallLocation = $tridionInstallLocation + "web\WebUI\Models\" + $guiExtensionName + "\Model"
write-output ("-> Begin Installing GUI Extension Editor to " + $editorInstallLocation)
$editorConfigFile = "Configuration\editor.config"
$modelConfigFile = "Configuration\model.config"
write-output " Editor config @" + $editorInstallLocation\Configuration\editor.config
#************* Copy Editor and Model files *******************
Copy-Item -Path $editorPath $editorInstallLocation -recurse
if((Test-Path $editorInstallLocation\Configuration\Editor -pathType container))
{
write-output (" Success: GUI Extension Editor Files copied to " + $editorInstallLocation)
}
if(!(Test-Path $editorInstallLocation\Configuration\editor.config))
{
write-output(" Error: No editor config found at " + $editorInstallLocation + "\Configuration\editor.config + , exiting.")
exit
}
if($hasModel)
{
write-output ("Begin Copying Model files to " + $modelInstallLocation)
Copy-Item -Path ".\Model" $modelInstallLocation -recurse
write-output (" Success: GUI Extension Model Files copied to " + $modelInstallLocation)
}
#************* Copy DLLs *******************
if(Test-Path dlls -pathType container)
{
$webRootBin = $tridionInstallLocation + "\web\WebUI\WebRoot\bin"
write-output ("Begin Copying DLLs to " + $webRoot)
Copy-Item -Path "dlls\*" $webRootBin -recurse
write-output (" Success: Copied DLLs to " + $webRoot)
}
#************* Update Config *******************
# Update System.config
write-output ("Begin updating system.config")
$configFilename = $tridionInstallLocation + '\web\WebUI\WebRoot\Configuration\System.config'
$conf = [xml](gc $configFilename)
# "http://www.sdltridion.com/2009/GUI/Configuration" <-- Correct for 2011 and 2013??
# specify some namespace so we don't have empty xmlns in the children
# Editor
write-output ("Begin adding Editor to system.config")
$editors = [System.Xml.XmlElement]$conf.Configuration.editors
$myElement = $conf.CreateElement("editor", "http://www.sdltridion.com/2009/GUI/Configuration")
$filenameAttr = $myElement.SetAttribute("name", $guiExtensionName)
$installPathElement = $conf.CreateElement("installpath", "http://www.sdltridion.com/2009/GUI/Configuration")
$installPathElement.InnerText = $editorInstallLocation
$myElement.AppendChild($installPathElement)
$configurationElement = $conf.CreateElement("configuration", "http://www.sdltridion.com/2009/GUI/Configuration")
$configurationElement.InnerText = $editorConfigFile
$myElement.AppendChild($configurationElement)
$vdirElement = $conf.CreateElement("vdir", "http://www.sdltridion.com/2009/GUI/Configuration")
$vdirElement.InnerText = $guiExtensionName
$myElement.AppendChild($vdirElement)
# $myElement.InnerXml = "<installpath>" + $editorInstallLocation + "</installpath><configuration>" + $editorConfigFile + "</configuration><vdir>" + $guiExtensionName + "</vdir>"
$editors.AppendChild($myElement)
write-output (" Success: Editor added to system.config")
#Model
if(Test-Path Model -pathType container)
{
[bool]$hasModel = 1
}
if($hasModel)
{
write-output ("Begin adding Model to system.config")
$models = [System.Xml.XmlElement]$conf.Configuration.models
$myModelElement = $conf.CreateElement("model")
$filenameAttr = $myModelElement.SetAttribute("name", $guiExtensionName)
$installPathElement = $conf.CreateElement("installpath", "http://www.sdltridion.com/2009/GUI/Configuration")
$installPathElement.InnerText = $modelInstallLocation
$myModelElement.AppendChild($installPathElement)
$configurationElement = $conf.CreateElement("configuration", "http://www.sdltridion.com/2009/GUI/Configuration")
$configurationElement.InnerText = $modelConfigFile
$myModelElement.AppendChild($configurationElement)
$vdirElement = $conf.CreateElement("vdir", "http://www.sdltridion.com/2009/GUI/Configuration")
$vdirElement.InnerText = $guiExtensionName
$myModelElement.AppendChild($vdirElement)
$models.AppendChild($myModelElement)
write-output (" Success: Model added to system.config")
}
$conf.Save($configFilename)
write-output (" Success: Updated and saved system.config")
#************* Update IIS *******************
# Create VDIR in Tridion/WebUI/Editors and Models 2011 / 2013 need input
$tridionVersion = Read-Host "Which version of Tridion do you use? (2011 or 2013. Default is 2013)"
if(($tridionVersion -ne "2011") -and($tridionVersion -ne "2013"))
{
$tridionVersion = "2013"
}
write-output ("Begin updating IIS, adding Editor")
$vdirPathEditor = 'IIS:\Sites\SDL Tridion ' + $tridionVersion + '\WebUI\Editors\' + $guiExtensionName
New-Item $vdirPathEditor -type VirtualDirectory -physicalPath $editorInstallLocation
write-output (" Success: Updating IIS and added new Virtual Dir at " + $vdirPathEditor)
# Model
if($hasModel)
{
write-output ("Begin updating IIS, adding Model")
$vdirPathModel = 'IIS:\Sites\SDL Tridion ' + $tridionVersion + '\WebUI\Models\' + $guiExtensionName
New-Item $vdirPathModel -type VirtualDirectory -physicalPath $modelInstallLocation
write-output (" Success: Updating IIS and added new Virtual Dir at " + $vdirPathModel)
}
write-output ("============================================")
write-output ("Finished successfully installing and configuring GUI Extenion " + $guiExtensionName )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment