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
Configuration cFirefox
{
    param
    (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]
        $VersionNumber,

        [Parameter()]
        [string]
        $Language = "en-US",

        [Parameter()]
        [ValidateSet("x86", "x64")]
        [string]
        $MachineBits = "x86",

        [Parameter()]
        [string]
        $InstallerPath,

        [Parameter()]
        [string]
        $LocalPath = "$env:SystemDrive\Windows\temp\DtlDownloads\Firefox Setup " + $VersionNumber + ".exe",

        [Parameter()]
        [string]
        $InstallDirectoryName,

        [Parameter()]
        [string]
        $InstallDirectoryPath,

        [Parameter()]
        [bool]
        $QuickLaunchShortcut = $false,

        [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()]
        [PSCredential]
        $Credential
    )

    Import-DscResource -ModuleName DSCR_Application

    if ($MachineBits -eq "x64") {
        $OS = "win64"
    }
    else {
        $OS = "win32"
    }

    $IniPath = "$env:SystemDrive\Windows\temp\DtlDownloads\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())
    )

    if ($InstallDirectoryName) {
        $IniContent += ("InstallDirectoryName=" + $InstallDirectoryName)
    }

    if ($InstallDirectoryPath) {
        $IniContent += ("InstallDirectoryPath=" + $InstallDirectoryPath)
    }

    if (-not $InstallerPath) {
        $InstallerPath = ("https://ftp.mozilla.org/pub/firefox/releases/{0}/{1}/{2}/Firefox%20Setup%20{0}.exe" -f $VersionNumber, $OS, $Language)
    }

    if ($VersionNumber -match 'esr') {
        $v1 = $VersionNumber.Substring(0, $VersionNumber.IndexOf('esr'))
        $AppName = ("Mozilla Firefox {0}{1} ({2} {3})" -f $v1, ' ESR', $MachineBits, $Language)
    }
    else {
        $AppName = ("Mozilla Firefox {0} ({1} {2})" -f $VersionNumber, $MachineBits, $Language)
    }

    if ($Credential) {
        cApplication Install
        {
            Name          = $AppName
            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
            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
        }
    }
}