Skip to content

Commit c32763a

Browse files
authored
Merge pull request #5 from ferricoxide/AddWindows_EXE
Add Installer-EXE logic for Windows-Based targets
2 parents 24524d8 + a1e0212 commit c32763a

19 files changed

Lines changed: 438 additions & 45 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM plus3it/tardigrade-ci:0.28.7

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
chrome-browser-formula
2+
==================
3+
4+
A SaltStack formula designed to install and configure Google's [Chrome Browser](https://www.google.com/chrome).
5+
6+
It is primarily expected that this formula will be run via [P3](https://www.plus3it.com/)'s "[watchmaker](https://watchmaker.readthedocs.io/en/stable/)" framework.
7+
8+
This formula is able to install the Chrome browser on both Linux[^1] and Windows Server[^2] operating environments:
9+
10+
* On Linux hosts, it will install using the distro's native package-manager[^1]
11+
* On Windows hosts, it will install using the installer-EXE[^3]
12+
13+
## Available states
14+
15+
- [chrome-browser](#chrome-browser)
16+
- [chrome-browser.clean](#chrome-browser.clean)
17+
- [chrome-browser.package](#chrome-browser.package)
18+
- [chrome-browser.package.clean](#chrome-browser.package.clean)
19+
- [chrome-browser.config](#chrome-browser.config)
20+
- [chrome-browser.config.clean](#chrome-browser.config.clean)
21+
22+
### chrome-browser
23+
24+
Executes the `package` and `config` states to install and configure the Chrome Browser
25+
26+
### chrome-browser.clean
27+
28+
Executes the `package` and `config` states' `clean` actions to fully uninstall the Chrome Browser and remove previously-installed browser policy-configs (and, on Windows, associated registry entries)
29+
30+
### chrome-browser.package
31+
32+
Executes _just_ the `package` state to install the Chrome Browser package.
33+
34+
### chrome-browser.package.clean
35+
36+
Executes _just_ the `package.clean` state to uninstall the Chrome Browser package.
37+
38+
### chrome-browser.config
39+
40+
Executes _just_ the `config` state to install/configure the Chrome policy files
41+
42+
### chrome-browser.config.clean
43+
44+
Executes _just_ the `config` state to uninstall the Chrome policy files and, on Windows, remove any registry-keys set by prior install-runs of the formula.
45+
46+
47+
48+
[^1]: As of this README's writing, only Enterprise Linux and related distros (Red Hat and Oracle Enterprise, CentOS Stream, Rocky and Alma Linux). It has only been specifically tested with EL **_9_** variants.
49+
[^2]: As of this README's writing, this functionality has only been tested on Windows Server 2022
50+
[^3]: Future iterations _may_ allow the use of MSI-based installers.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- from tplroot ~ "/map.jinja" import mapdata as chrome with context %}
7+
8+
{%- for key in chrome.policy_extras.registry_keys %}
9+
Remove Registry Key {{ loop.index }}:
10+
reg.absent:
11+
- name: {{ key }}
12+
- onchanges:
13+
- cmd: Uninstall Google Chrome
14+
{%- endfor %}
15+
16+
{%- for id, path in chrome.policy_extras.policy_files.items() %}
17+
Remove Chrome Policy File "{{ id }}":
18+
file.absent:
19+
- name: {{ path }}
20+
- onchanges:
21+
- cmd: Uninstall Google Chrome
22+
{%- endfor %}

chrome-browser/config/win_file.sls

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
#
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- from tplroot ~ "/map.jinja" import mapdata as chrome with context %}
7+
8+
{%- set policy_path = 'C:/Windows/PolicyDefinitions' %}
9+
{%- set source_root = 'C:/Windows/Temp/Chrome/full_extract/windows/admx' %}
10+
{%- set ChromeTmp = 'C:/Windows/Temp/Chrome' %}
11+
{%- set no_update_value = chrome.policy_extras.settings.no_update | string | lower %}
12+
{%- set hklm_root = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome' %}
13+
{%- set chrome_files = {
14+
'google_admx': {'src': source_root ~ '/google.admx', 'dest': policy_path ~ '/google.admx'},
15+
'chrome_admx': {'src': source_root ~ '/chrome.admx', 'dest': policy_path ~ '/chrome.admx'},
16+
'chrome_adml': {'src': source_root ~ '/en-US/chrome.adml', 'dest': policy_path ~ '/en-US/chrome.adml'}
17+
}
18+
%}
19+
20+
Cleanup Chrome Temp Directory:
21+
file.absent:
22+
- name: '{{ ChromeTmp }}'
23+
- require:
24+
{%- for id in chrome_files.keys() %}
25+
- file: 'Deploy file {{ id }}'
26+
{%- endfor %}
27+
28+
{%- if chrome.policy_extras.settings.home_page %}
29+
Configure Chrome Homepage:
30+
reg.present:
31+
- name: '{{ hklm_root }}'
32+
- vname: 'HomepageLocation'
33+
- vdata: '{{ chrome.policy_extras.settings.home_page }}'
34+
- vtype: REG_SZ
35+
- require:
36+
{%- for id in chrome_files.keys() %}
37+
- file: 'Deploy file {{ id }}'
38+
{%- endfor %}
39+
{%- endif %}
40+
41+
{%- if chrome.policy_extras.settings.managed_bookmarks_enabled | string | lower == 'true' and chrome.policy_extras.settings.managed_bookmarks %}
42+
Configure Managed Bookmarks:
43+
reg.present:
44+
- name: '{{ hklm_root }}'
45+
- vname: 'ManagedBookmarks'
46+
- vdata: {{ chrome.policy_extras.settings.managed_bookmarks | json }}
47+
- vtype: REG_SZ
48+
- require:
49+
{%- for id in chrome_files.keys() %}
50+
- file: 'Deploy file {{ id }}'
51+
{%- endfor %}
52+
{%- endif %}
53+
54+
{%- for id, paths in chrome_files.items() %}
55+
Deploy file {{ id }}:
56+
file.copy:
57+
- name: '{{ paths.dest }}'
58+
- source: '{{ paths.src }}'
59+
- force: True
60+
- makedirs: True
61+
- require:
62+
- archive: 'Extract Chrome Bundle'
63+
{%- endfor %}
64+
65+
{%- if no_update_value == 'true' %}
66+
Disable Chrome Auto-Update:
67+
reg.present:
68+
- name: '{{ hklm_root | replace('\\Chrome', '\\Update') }}'
69+
- vname: 'UpdateDefault'
70+
- vdata: 0
71+
- vtype: REG_DWORD
72+
- require:
73+
{%- for id in chrome_files.keys() %}
74+
- file: 'Deploy file {{ id }}'
75+
{%- endfor %}
76+
{%- endif %}
77+
78+
{%- if chrome.policy_extras.settings.password_manager_enabled | string | lower == 'false' %}
79+
Disable Chrome Password Manager:
80+
reg.present:
81+
- name: '{{ hklm_root }}'
82+
- vname: 'PasswordManagerEnabled'
83+
- vdata: 0
84+
- vtype: REG_DWORD
85+
- require:
86+
{%- for id in chrome_files.keys() %}
87+
- file: 'Deploy file {{ id }}'
88+
{%- endfor %}
89+
{%- endif %}
90+
91+
Ensure Chrome TempDir Exists:
92+
file.directory:
93+
- name: '{{ ChromeTmp }}'
94+
- makedirs: True
95+
96+
Extract Chrome Bundle:
97+
archive.extracted:
98+
- name: '{{ ChromeTmp }}/full_extract'
99+
- source: 'https://dl.google.com/dl/edgedl/chrome/policy/policy_templates.zip'
100+
- skip_verify: True
101+
- enforce_toplevel: False
102+
- overwrite: True
103+
- require:
104+
- file: 'Ensure Chrome TempDir Exists'
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
$RealPF = [System.Environment]::GetEnvironmentVariable("ProgramW6432")
2+
if (-not $RealPF) { $RealPF = $env:ProgramFiles }
3+
4+
$ChromePath = Join-Path $RealPF "Google\Chrome\Application"
5+
$ChromeExe = Join-Path $ChromePath "chrome.exe"
6+
7+
# PRE-CONDITION (State Check)
8+
if (Test-Path $ChromeExe) {
9+
Write-Output "Found chrome-binary '$ChromeExe'"
10+
}
11+
elseif (-not (Test-Path $ChromeExe)) {
12+
# Salt will see this string in the 'comment' or 'stdout' field
13+
Write-Output "State: Already Absent"
14+
exit 100
15+
}
16+
17+
# EXECUTION
18+
$VDir = Get-ChildItem -Path $ChromePath | Where-Object { $_.Name -match '^\d' } | Select-Object -First 1
19+
if ($VDir) {
20+
$VerPath = Join-Path -Path $ChromePath -ChildPath $VDir.Name
21+
$Setup = Join-Path -Path $VerPath -ChildPath "Installer\setup.exe"
22+
23+
if ( Test-Path $Setup ) {
24+
Write-Output "Found uninstaller (setup utility) at '$Setup'"
25+
Write-Output "Uninstalling version $( $VDir.Name )..."
26+
$Proc = Start-Process "$Setup" -ArgumentList '--uninstall --multi-install --chrome --system-level --force-uninstall' -Wait -PassThru
27+
$Proc.WaitForExit()
28+
29+
# FINAL VERIFICATION
30+
if ( -not ( Test-Path $ChromeExe ) ) {
31+
Write-Output "State: Success"
32+
exit 0
33+
} else {
34+
Write-Error "State: Failed to remove binary"
35+
exit 1
36+
}
37+
}
38+
}
39+
40+
exit 100

chrome-browser/package/clean.sls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=sls
33

4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_config_clean = tplroot ~ '.config.clean' %}
7+
{%- from tplroot ~ "/map.jinja" import mapdata as TEMPLATE with context %}
8+
49
include:
10+
- {{ sls_config_clean }}
511
{%- if grains.kernel == "Linux" %}
612
- .lin_clean
713
{%- elif grains.kernel == "Windows" %}

chrome-browser/package/install.sls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ include:
55
{%- if grains.kernel == "Linux" %}
66
- .lin_install
77
{%- elif grains.kernel == "Windows" %}
8+
- .win_pre-install
89
- .win_install
10+
- .win_post-install
911
{%- endif %}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_config_clean = tplroot ~ '.config.clean' %}
7+
{%- from tplroot ~ "/map.jinja" import mapdata as TEMPLATE with context %}
8+
9+
Purge Chrome Directory:
10+
file.absent:
11+
- name: 'C:\Program Files\Google\Chrome\Application'
12+
- onchanges:
13+
- cmd: Uninstall Google Chrome
14+
15+
Uninstall Google Chrome:
16+
cmd.script:
17+
- source: salt://{{ tplroot }}/files/uninstall_chrome.ps1
18+
- shell: powershell
19+
- success_retcodes: [
20+
0,
21+
100
22+
]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
{#- Get the `tplroot` from `tpldir` #}
4+
{%- set tplroot = tpldir.split('/')[0] %}
5+
{%- from tplroot ~ "/map.jinja" import mapdata as chrome with context %}
6+
{%- if salt.grains.get('cpuarch') == "AMD64" %}
7+
{%- set temp_exe = 'C:/Windows/Temp/ChromeStandaloneSetup64.exe' %}
8+
{%- else %}
9+
{%- set temp_exe = 'C:/Windows/Temp/ChromeStandaloneSetup32.exe' %}
10+
{%- endif %}
11+
12+
Clean staged Chrome Standalone EXE-based installer:
13+
file.absent:
14+
- name: '{{ temp_exe }}'
15+
- require:
16+
- cmd: 'Install Google Chrome EXE'
17+
18+
Download Chrome Standalone EXE-based installer:
19+
file.managed:
20+
- name: '{{ temp_exe }}'
21+
- source: '{{ chrome.pkg.installer_uri }}'
22+
- skip_verify: True
23+
- makedirs: True
24+
25+
Install Google Chrome EXE:
26+
cmd.run:
27+
- name: |
28+
Start-Process "{{ temp_exe }}" -ArgumentList '/silent /install' -Wait
29+
Start-Sleep -Seconds 5
30+
- require:
31+
- file: 'Download Chrome Standalone EXE-based installer'
32+
- shell: powershell
33+
- success_retcodes: [
34+
0,
35+
3010
36+
]
37+
- unless: 'if (Test-Path "${env:ProgramFiles}\Google\Chrome\Application\chrome.exe") { exit 0 } else { exit 1 }'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
{#- Get the `tplroot` from `tpldir` #}
4+
{%- set tplroot = tpldir.split('/')[0] %}
5+
{%- from tplroot ~ "/map.jinja" import mapdata as chrome with context %}
6+
{%- set hklm_root = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components' %}
7+
{%- set hklm_path = 'SOFTWARE\Microsoft\Active Setup\Installed Components' %}
8+
{%- set salt_reg_root = 'HKEY_LOCAL_MACHINE\\' ~ hklm_path %}
9+
{%- set ps_reg_root = 'HKLM:\\' ~ hklm_path %}
10+
11+
Re-enable IE ESC for Administrators:
12+
reg.present:
13+
- name: '{{ salt_reg_root }}\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}'
14+
- vname: IsInstalled
15+
- vtype: REG_DWORD
16+
- vdata: 1
17+
- require:
18+
- cmd: 'Install Google Chrome EXE'
19+
- cmd: 'Revert IE ESC to Original States'
20+
21+
Re-enable IE ESC for Users:
22+
reg.present:
23+
- name: '{{ salt_reg_root }}\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}'
24+
- vname: IsInstalled
25+
- vtype: REG_DWORD
26+
- vdata: 1
27+
- require:
28+
- cmd: 'Install Google Chrome EXE'
29+
- cmd: 'Revert IE ESC to Original States'
30+
31+
Revert IE ESC to Original States:
32+
cmd.run:
33+
- name: |
34+
$path = "C:/Windows/Temp/ie_esc_original_state.txt"
35+
if (Test-Path $path) {
36+
$s = (Get-Content $path).Split(',')
37+
if ($s[0] -eq "1") { Set-ItemProperty '{{ ps_reg_root }}\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}' IsInstalled 1 }
38+
if ($s[1] -eq "1") { Set-ItemProperty '{{ ps_reg_root }}\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}' IsInstalled 1 }
39+
Remove-Item $path -Force
40+
}
41+
- shell: powershell

0 commit comments

Comments
 (0)