Last active
March 12, 2024 00:45
-
-
Save KevinJump/a0bd8b69c41fdd762e68728f326d1569 to your computer and use it in GitHub Desktop.
Umbraco Setup and tear down scripts. (Gives you an approx 35 second Umbraco install)
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
# statup umbraco, and add some packages if you want | |
# | |
# e.g numbraco MyTestSite uSync Jumoo.TranslationManager vendr -NoStarter | |
# | |
# extras!!! | |
# | |
# open vscode in the folder as part of the build | |
# numbraco MyTestSite -code | |
# | |
# don't run the site | |
# numbraco MyTestSite -doNotRun | |
# | |
# Required dbatools powershell scripts and local SQLExpress install. | |
param( | |
[Parameter(Mandatory)] | |
[string] | |
$sitename, | |
[string[]] | |
$packages, | |
# dont install the starter kit. | |
[switch] | |
$NoStarter, | |
# open vscode in the folder | |
[switch] | |
$code, | |
# don't run the site at the end. | |
[switch] | |
$doNotRun | |
) | |
# check if you don't have DBATools it will still work | |
Function Test-CommandExists | |
{ | |
Param ($command) | |
$oldPreference = $ErrorActionPreference | |
$ErrorActionPreference = ‘stop’ | |
try {if(Get-Command $command){RETURN $true}} | |
Catch {Write-Host “$command does not exist”; RETURN $false} | |
Finally {$ErrorActionPreference=$oldPreference} | |
} #end function test-CommandExists | |
# optional if you don't have dbatools, remove this, Umbraco will create the DB for you (will take 10-15 seconds longer) | |
if (Test-CommandExists new-dbaDatabase) { | |
Write-Host "Creating Database" -ForegroundColor Blue | |
new-dbaDatabase -SqlInstance $env:COMPUTERNAME\sqlExpress -name $sitename | |
} | |
else { | |
Write-Host "DBA Tools not installed, going for auto creation" -ForegroundColor Yellow | |
} | |
dotnet new umbraco -n $sitename --connection-string "Server=$env:COMPUTERNAME\SQLExpress;Database=$sitename;Integrated Security=true" | |
Set-Location $sitename | |
# you can put username and password here, but if you set UMB_USER, UMB_EMAIL and UMB_PASSWORD on your local pc, then you don't have to. | |
Set-Item Env:\UMBRACO__CMS__GLOBAL__INSTALLMISSINGDATABASE true | |
Set-Item Env:\UMBRACO__CMS__UNATTENDED__INSTALLUNATTENDED true | |
Set-Item Env:\UMBRACO__CMS__UNATTENDED__UNATTENDEDUSERNAME $env:UMB_USER | |
Set-Item Env:\UMBRACO__CMS__UNATTENDED__UNATTENDEDUSEREMAIL $env:UMB_EMAIL | |
Set-Item Env:\UMBRACO__CMS__UNATTENDED__UNATTENDEDUSERPASSWORD $env:UMB_PASSWORD | |
if (!$nostarter) { | |
Write-Host "Adding the starter kit" -ForegroundColor Blue | |
dotnet add package Umbraco.TheStarterKit -s https://api.nuget.org/v3/index.json | |
} | |
foreach($package in $packages) { | |
Write-Host "Adding $package" -ForegroundColor Blue | |
dotnet add package $package | |
} | |
if ($code) { | |
code $sitename | |
} | |
if ($doNotRun) { | |
dotnet build | |
} | |
else { | |
Write-Host "Running Site" -ForegroundColor Blue | |
Set-Location .. | |
$project = ".\$sitename\$sitename.csproj"; | |
dotnet run --project $project | |
} |
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
# | |
# Cleanup an umbraco install and its db | |
# | |
# unumbraco MyTestSite -removeFolder | |
# | |
# -removeFolder (option) when set will also remove the folder from disk | |
# | |
param( | |
[Parameter(Mandatory)] | |
[string] | |
$sitename, | |
[switch] | |
$removeFolder | |
) | |
Write-Host ">> Removing database $sitename" | |
remove-dbaDatabase -SqlInstance $env:COMPUTERNAME\sqlExpress -database $sitename -Confirm:$false | |
if ($removeFolder) { | |
# check to see if we are in the site folder, | |
$currentFolderName = Split-PAth -path (Get-Location) -leaf | |
if ($currentFolderName -eq $sitename) { | |
# if we are go up a folder. | |
Write-Host ">> Moving to parent folder of $sitename" | |
Set-Location .. | |
} | |
Write-Host ">> Removing folder $sitename" | |
if (Test-Path $sitename) { | |
Remove-Item -Path $sitename -Recurse | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
version of Sebastiaan's Unattended umbraco scripts https://gist.github.com/nul800sebastiaan/1553316fda85011270ce2bde35243e5b.
For local setups I have three environmental varitables on my machine
UMB_USER
,UMB_EMAIL
andUMB_PASSWORD
. these mean i can run the scripts above and the sites will get created with what ever those values are set to.