Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/configuration #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified DnnWebsiteManagement/DnnWebsiteManagement.psd1
Binary file not shown.
121 changes: 102 additions & 19 deletions DnnWebsiteManagement/DnnWebsiteManagement.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ Push-Location
Import-Module SQLPS -DisableNameChecking
Pop-Location

$defaultDNNVersion = $env:DnnWebsiteManagement_DefaultVersion
if ($defaultDNNVersion -eq $null) { $defaultDNNVersion = '9.1.0' }

$defaultIncludeSource = $env:DnnWebsiteManagement_DefaultIncludeSource
if ($defaultIncludeSource -eq 'false') { $defaultIncludeSource = $false }
elseif ($defaultIncludeSource -eq 'no') { $defaultIncludeSource = $false }
elseif ($defaultIncludeSource -eq '0') { $defaultIncludeSource = $false }
elseif ($defaultIncludeSource -eq '') { $defaultIncludeSource = $false }
elseif ($defaultIncludeSource -eq $null) { $defaultIncludeSource = $false }
else { $defaultIncludeSource = $true }

$www = $env:www
if ($www -eq $null) { $www = 'C:\inetpub\wwwroot' }

Add-Type -TypeDefinition @"
public enum DnnProduct
{
Expand Down Expand Up @@ -557,10 +543,10 @@ function getPackageName([System.Version]$version, [DnnProduct]$product) {
function findPackagePath([System.Version]$version, [DnnProduct]$product, [string]$type) {
$majorVersion = $version.Major
switch ($product) {
DnnPlatform { $packagesFolder = "${env:soft}\DNN\Versions\DotNetNuke $majorVersion"; break; }
EvoqContent { $packagesFolder = "${env:soft}\DNN\Versions\Evoq Content Basic"; break; }
EvoqContentEnterprise { $packagesFolder = "${env:soft}\DNN\Versions\Evoq Content"; break; }
EvoqEngage { $packagesFolder = "${env:soft}\DNN\Versions\Evoq Engage"; break; }
DnnPlatform { $packagesFolder = "${ModuleSettings.DnnPackages}\DNN\Versions\DotNetNuke $majorVersion"; break; }
EvoqContent { $packagesFolder = "${ModuleSettings.DnnPackages}\DNN\Versions\Evoq Content Basic"; break; }
EvoqContentEnterprise { $packagesFolder = "${ModuleSettings.DnnPackages}\DNN\Versions\Evoq Content"; break; }
EvoqEngage { $packagesFolder = "${ModuleSettings.DnnPackages}\DNN\Versions\Evoq Engage"; break; }
}

$packageName = getPackageName $version $product
Expand Down Expand Up @@ -659,7 +645,8 @@ function Extract-Packages {
$version = New-Object System.Version($version)
Write-Verbose "Version is $version"

if ($env:soft -eq $null) {

if ($ModuleSettings.DnnPackages -eq $null) {
throw 'You must set the environment variable `soft` to the path that contains your DNN install packages'
}

Expand Down Expand Up @@ -878,6 +865,102 @@ function Watermark-Logos {
}
}

#-------------------- Module Initialization -----------------------------

# -----------------------------------------------------------------------
# This is the initialization module script that completes
# the settings initialization process. You can override the default
# settings by passing either a file containing the appropriate
# settings in hashtable form as shown in ModuleSettings.ps1 or you
# can pass in a hashtable with the appropriate settings directly.
# -----------------------------------------------------------------------
function WriteUsageInfo([string]$msg)
{
if ($msg) { Write-Host $msg }

Write-Host @"

You can override individual settings by passing a hashtable with just those
settings defined as shown below:

Import-Module DnnWebSiteManage -arg @{DefaultVersion = "9.2.2"}

Any value not specified will be retrieved from the default settings built
into the DNNWebsiteManagement module manifest.

If you have a sufficiently large number of altered setting, copy the settings
file, modify it and pass the path to your settings file to Import-Module e.g.:

Import-Module DNNWebsiteManagement -arg "$(Split-Path $profile -parent)\
ModuleSettings.ps1"

"@
}

function UpdateDefaultSettingsWithUserSettings([hashtable]$userSettings)
{
# Walk the user specified settings and overwrite the defaults with them
foreach ($key in $userSettings.Keys)
{
if (!$ModuleSettings.ContainsKey($key))
{
Write-Warning "$key is not a recognized DnnWebsiteManagement setting"
continue
}

$ModuleSettings.$key = $userSettings.$key
}
}

if ($Args.Length -gt 0)
{

if ($Args[0] -eq 'help')
{
WriteUsageInfo
return
}
elseif ($Args[0] -is [hashtable])
{
UpdateDefaultSettingsWithUserSettings $Args[0]
}
elseif (Test-Path $Args[0])
{
$userSettings = & $Args[0]
if ($userSettings -isnot [hashtable])
{
WriteUsage "'$($args[0])' must return a hashtable instead of a $($userSettings.GetType().FullName)"
return
}

UpdateDefaultSettingsWithUserSettings $userSettings
}
else
{
WriteUsageInfo "'$($args[0])' is not recognized as either a hashtable or a valid path"
return
}
}

$defaultDNNVersion = $ModuleSettings.DefaultVersion # $env:DnnWebsiteManagement_DefaultVersion
if ($defaultDNNVersion -eq $null) { $defaultDNNVersion = '9.1.0' }

$defaultIncludeSource = $ModuleSettings.DefaultIncludeSource # $env:DnnWebsiteManagement_DefaultIncludeSource
if ($defaultIncludeSource -eq 'false') { $defaultIncludeSource = $false }
elseif ($defaultIncludeSource -eq 'no') { $defaultIncludeSource = $false }
elseif ($defaultIncludeSource -eq '0') { $defaultIncludeSource = $false }
elseif ($defaultIncludeSource -eq '') { $defaultIncludeSource = $false }
elseif ($defaultIncludeSource -eq $null) { $defaultIncludeSource = $false }
else { $defaultIncludeSource = $true }

$www = $ModuleSettings.WebHome # $env:www
if ($www -eq $null) { $www = 'C:\inetpub\wwwroot' }

Remove-Item Function:\WriteUsageInfo
Remove-Item Function:\UpdateDefaultSettingsWithUserSettings

#---------------------------------------------------------------------------

Export-ModuleMember Install-DNNResources
Export-ModuleMember Remove-DNNSite
Export-ModuleMember Rename-DNNSite
Expand Down
13 changes: 13 additions & 0 deletions DnnWebsiteManagement/Initialize.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Set-StrictMode -Version 2.0

# ---------------------------------------------------------------------------
# The initialization script loads the Module's private data into a global
# variable so that it is available to all nested modules and so that it
# can be easily overridden by the user at run-time.
# ---------------------------------------------------------------------------
$Module = $ExecutionContext.SessionState.Module
if (! $Module) {
Throw ( New-Object System.InvalidOperationException `
"An active module was not found!")
}
$Global:ModuleSettings = $Module.PrivateData.ModuleSettings
26 changes: 26 additions & 0 deletions DnnWebsiteManagement/ModuleSettings.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ---------------------------------------------------------------------------
# You can override individual settings by passing a hashtable with just those
# settings defined as shown below:
#
# Import-Module dnnwebsitemanagement -arg @{defaultVersion = "9.2.2"}
#
# Any value not specified will be retrieved from the default settings built
# into the DnnWebsiteManagement module manifest.
#
# If you have a sufficiently large number of altered setting, copy this file,
# modify it and pass the path to your settings file to Import-Module e.g.:
#
# Import-Module dnnwebsitemanagement -arg "$(Split-Path $profile -parent)\ModuleSettings.ps1"
#
# ---------------------------------------------------------------------------
@{
DefaultVersion = "9.1.0"

DefaultIncludeSource = $true

WebHome = "C:\inetpub\wwwroot"

DnnPackages = "${Env:ProgramFiles(x86)}\nvisionative\nvQuickSite\Downloads"

Browser = "Chrome" # The default browser used when calling Start-Browser
}