DSCResources/cFirefox/cFirefox.schema.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
Configuration cFirefox { param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $VersionNumber, [Parameter()] [string] $Language = 'en-US', [Parameter()] [ValidateSet('Auto', 'x86', 'x64', 'ARM64')] [string] $MachineBits = 'Auto', [Parameter()] [string] $InstallerPath, [Parameter()] [string] $InstallDirectoryName, [Parameter()] [string] $InstallDirectoryPath, [Parameter()] [bool] $QuickLaunchShortcut = $false, #obsoleted [Parameter()] [bool] $DesktopShortcut = $true, [Parameter()] [bool] $TaskbarShortcut = $false, [Parameter()] [bool] $MaintenanceService = $true, [Parameter()] [bool] $StartMenuShortcuts = $true, [Parameter()] [string] $StartMenuDirectoryName = 'Mozilla Firefox', [Parameter()] [bool] $OptionalExtensions = $true, #only Firefox 60+ [Parameter()] [bool] $RegisterDefaultAgent = $true, #only Firefox 76+ [Parameter()] [bool] $RemoveDistributionDir = $true, [Parameter()] [PSCredential] $Credential ) Import-DscResource -ModuleName DSCR_Application # Determine os architecture $OS = 'win32'; $Arch = 'x86' switch ($MachineBits) { 'x86' { $OS = 'win32'; $Arch = 'x86'; break } 'x64' { $OS = 'win64'; $Arch = 'x64'; break } 'ARM64' { $OS = 'win64-aarch64'; $Arch = 'AArch64'; break } 'Auto' { switch (& { if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } }) { 'AMD64' { $OS = 'win64'; $Arch = 'x64'; break } 'ARM64' { $OS = 'win64-aarch64'; $Arch = 'AArch64'; break } } } } #region Configuration.ini # Create a Configuration.ini file for specifying install options. # https://firefox-source-docs.mozilla.org/browser/installer/windows/installer/FullConfig.html $IniPath = "$env:ProgramData\Microsoft\Windows\PowerShell\Configuration\BuiltinProvCache\DSCR_Firefox\Configuration.ini" [string[]]$IniContent = @( '[Install]', ('QuickLaunchShortcut=' + $QuickLaunchShortcut.ToString().toLower()), ('DesktopShortcut=' + $DesktopShortcut.ToString().toLower()), ('TaskbarShortcut=' + $TaskbarShortcut.ToString().toLower()), ('MaintenanceService=' + $MaintenanceService.ToString().toLower()), ('StartMenuShortcuts=' + $StartMenuShortcuts.ToString().toLower()), ('StartMenuDirectoryName=' + $StartMenuDirectoryName), ('OptionalExtensions=' + $OptionalExtensions.ToString().toLower()) ('RegisterDefaultAgent=' + $RegisterDefaultAgent.ToString().toLower()) ('RemoveDistributionDir=' + $RemoveDistributionDir.ToString().toLower()) ) if ($InstallDirectoryName) { $IniContent += ('InstallDirectoryName=' + $InstallDirectoryName) } if ($InstallDirectoryPath) { $IniContent += ('InstallDirectoryPath=' + $InstallDirectoryPath) } #endregion Configuration.ini if (-not $InstallerPath) { # Download an installer from Mozilla $InstallerPath = ('https://ftp.mozilla.org/pub/firefox/releases/{0}/{1}/{2}/Firefox%20Setup%20{0}.exe' -f $VersionNumber, $OS, $Language) } # Validate version string [System.Version]$TargetVersion = $null if (-not [System.Version]::TryParse(($VersionNumber -replace '[^\d\.]', ''), [ref]$TargetVersion)) { Write-Error -Message 'VersionNumber is not valid format of values.' return } if ($VersionNumber -match 'esr') { $v1 = $VersionNumber.Substring(0, $VersionNumber.IndexOf('esr')) $AppName = ('Mozilla Firefox {0}{1} ({2} {3})' -f $v1, ' ESR', $Arch, $Language) } else { # The format of the application name changed from 90.0 if ($TargetVersion -ge [version]::new(90, 0)) { $AppName = ('Mozilla Firefox ({0} {1})' -f $Arch, $Language) } else { $AppName = ('Mozilla Firefox {0} ({1} {2})' -f $VersionNumber, $Arch, $Language) } } if ($Credential) { cApplication Install { Name = $AppName Version = ($TargetVersion.ToString()) InstallerPath = $InstallerPath Arguments = "-ms /INI=$IniPath" PreAction = { $parent = (split-path -Path $using:IniPath -Parent) if (-not (Test-Path -Path $parent)) { New-Item -Path $parent -ItemType Directory -Force | Out-Null } $using:IniContent -join "`r`n" | Out-File -FilePath $using:IniPath -Encoding ascii -Force } NoRestart = $true Credential = $Credential } } else { cApplication Install { Name = $AppName Version = ($TargetVersion.ToString()) InstallerPath = $InstallerPath Arguments = "-ms /INI=$IniPath" PreAction = { $parent = (split-path -Path $using:IniPath -Parent) if (-not (Test-Path -Path $parent)) { New-Item -Path $parent -ItemType Directory -Force | Out-Null } $using:IniContent -join "`r`n" | Out-File -FilePath $using:IniPath -Encoding ascii -Force } NoRestart = $true } } } |