UpdateWordPressCom.ps1


<#PSScriptInfo

.VERSION 0.0.1

.GUID 14bc911e-6214-4c6a-a3a3-5e0583517293

.AUTHOR Fabrice Sanga

.COMPANYNAME sangafabrice

.COPYRIGHT © 2022 SangaFabrice. All rights reserved.

.TAGS wordpress-com nsis update web-framework

.LICENSEURI https://github.com/sangafabrice/reg-cli/blob/main/LICENSE.md

.PROJECTURI https://github.com/sangafabrice/reg-cli/tree/wordpress.com

.ICONURI https://rawcdn.githack.com/sangafabrice/reg-cli/9d5c4b2eb928f6f9f4ada4a83f8f70c9cbb5bef8/icon.png

.EXTERNALMODULEDEPENDENCIES DownloadInfo,RegCli

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES
Initialize WordPress.com updater script.

.PRIVATEDATA

#>


#Requires -Module @{ModuleName = 'DownloadInfo'; ModuleVersion = '5.0.4'}
#Requires -Module @{ModuleName = 'RegCli'; ModuleVersion = '6.2.3'}

[CmdletBinding()]
Param (
    [ValidateNotNullOrEmpty()]
    [ValidateScript({ Test-InstallLocation $_ $PSScriptRoot })]
    [string]
    $InstallLocation = "${Env:ProgramData}\WordPress.com",
    [ValidateNotNullOrEmpty()]
    [ValidateScript({ Test-InstallerLocation $_ })]
    [string]
    $SaveTo = $PSScriptRoot
)

& {
    $UpdateInfo =
        Try {
            Write-Verbose 'Retrieve install or update information...'
            Get-DownloadInfo -PropertyList @{ 
                RepositoryId = 'Automattic/wp-desktop'
                AssetPattern = 'wordpress\.com\-win32\-setup\-(\d+\.)+exe$' 
            }
        }
        Catch { }
    $InstallerDescription = 'Desktop version of WordPress.com'
    $LocalVersion = "$(Get-SavedInstallerVersion $SaveTo $InstallerDescription)"
    If (
        ![string]::IsNullOrEmpty($UpdateInfo.Version) -and
        $LocalVersion -like "$($UpdateInfo.Version -replace 'v')*"
    ) { $UpdateInfo.Version = $LocalVersion }
    Try {
        $UpdateModule =
            Import-CommonScript chrome-installer |
            Import-Module -PassThru -Force -Verbose:$False
        @{
            UpdateInfo = $UpdateInfo
            NameLocation = "$InstallLocation\WordPress.com.exe"
            SaveTo = $SaveTo
            SoftwareName = 'WordPress.com'
            InstallerDescription = $InstallerDescription
            InstallerType = 'NSIS'
            Verbose = $VerbosePreference -ine 'SilentlyContinue'
        } | ForEach-Object { Invoke-CommonScript @_ }
    }
    Catch { }
    Finally { $UpdateModule | Remove-Module -Verbose:$False }
}

<#
.SYNOPSIS
    Updates WordPress.com software.
.DESCRIPTION
    The script installs or updates WordPress.com on Windows.
.NOTES
    Required: at least Powershell Core 7.
.PARAMETER InstallLocation
    Path to the installation directory.
    It is restricted to file system paths.
    It does not necessary exists.
    It defaults to "%ProgramData%\WordPress.com".
.PARAMETER SaveTo
    Path to the directory of the downloaded installer.
    It is an existing file system path.
    It defaults to the script directory.
.EXAMPLE
    Get-ChildItem 'C:\ProgramData\WordPress.com' -ErrorAction SilentlyContinue

    PS > .\UpdateWordPressCom.ps1 -InstallLocation 'C:\ProgramData\WordPress.com' -SaveTo .

    PS > Get-ChildItem 'C:\ProgramData\WordPress.com' | Select-Object Name -First 5
    Name
    ----
    locales
    resources
    swiftshader
    chrome_100_percent.pak
    chrome_200_percent.pak

    PS > Get-ChildItem | Select-Object Name
    Name
    ----
    wordpress.com_v7.2.0.exe
    UpdateWordPressCom.ps1

    Install WordPress.com to 'C:\ProgramData\WordPress.com' and save its setup installer to the current directory.
#>