V2.0
Added support for Amazon Workspaces.
This commit is contained in:
parent
40942968ae
commit
c210b4b696
6 changed files with 401 additions and 230 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
|
||||
/Template
|
||||
chrome_downloader.log
|
||||
*.log
|
||||
/Chrome - *
|
||||
/Amazon Workspace - *
|
||||
|
|
|
@ -1,173 +0,0 @@
|
|||
# Read configuration from JSON file
|
||||
$configPath = "$PSScriptRoot\config.json"
|
||||
$config = Get-Content -Path $configPath | ConvertFrom-Json
|
||||
|
||||
# Get the date format from the configuration, or use the default format if not provided
|
||||
$dateFormat = $config.logging.logDateFormat
|
||||
if (-not $dateFormat) {
|
||||
$dateFormat = "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
|
||||
|
||||
# Function to log messages with the specified date format
|
||||
$logFileName = $config.logging.fileName
|
||||
$logFileFormat = $config.logging.fileFormat
|
||||
if (-not $logFileName) {
|
||||
$logFileName = "chrome_downloader"
|
||||
}
|
||||
if (-not $logFileFormat) {
|
||||
$logFileFormat = "log"
|
||||
}
|
||||
$logFileNameFormat = $logFileName+"."+$logFileFormat
|
||||
function Log-Message {
|
||||
param (
|
||||
[string]$message
|
||||
)
|
||||
$timestamp = Get-Date -Format $dateFormat
|
||||
Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileNameFormat" -Encoding utf8
|
||||
}
|
||||
|
||||
# Log the start of the script
|
||||
Log-Message "Debug: Script started"
|
||||
|
||||
# Check if both options are disabled and log a message
|
||||
if (-not $config.options.enableRegularVersion -and -not $config.options.enableForcedVersion) {
|
||||
Log-Message "Warn: Both Regular and Forced versions are disabled. Please enable at least one option to proceed."
|
||||
exit
|
||||
}
|
||||
|
||||
if ($config.options.checkExist) {
|
||||
$testPath = "$PSScriptRoot\Chrome - *"
|
||||
|
||||
# Store subfolders before deletion
|
||||
$subfolders = @()
|
||||
|
||||
if (Test-Path $testPath) {
|
||||
$subfolders = Get-ChildItem -Path $testPath -Directory | ForEach-Object { $_.FullName }
|
||||
|
||||
# Remove the folders
|
||||
Remove-Item $testPath -Recurse -Force
|
||||
}
|
||||
|
||||
# Output the subfolders
|
||||
foreach ($subfolder in $subfolders) {
|
||||
Log-Message "Info: The subfolder '$subfolder\' has been deleted."
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Define URLs
|
||||
$url1 = "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise64.msi"
|
||||
$url2 = "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise.msi"
|
||||
|
||||
# Define source and destination folders
|
||||
$sourceFolderRegular = "$PSScriptRoot\Template\Chrome-Template"
|
||||
$sourceFolderForced = "$PSScriptRoot\Template\Chrome-Template-Forced"
|
||||
|
||||
$destinationFolder = Join-Path -Path $PSScriptRoot -ChildPath "Chrome - VERSION"
|
||||
$forceUpdateFolder = Join-Path -Path $PSScriptRoot -ChildPath "Chrome - VERSION_force_update"
|
||||
|
||||
# Conditional execution based on config
|
||||
if ($config.options.enableRegularVersion) {
|
||||
# Create main folder and files folder if they don't exist
|
||||
$folderName = "Chrome - VERSION"
|
||||
$folderPath = Join-Path -Path $PSScriptRoot -ChildPath $folderName
|
||||
$filesFolder = Join-Path -Path $folderPath -ChildPath "Files"
|
||||
|
||||
if (-not (Test-Path $filesFolder)) {
|
||||
try {
|
||||
New-Item -Path $filesFolder -ItemType Directory -ErrorAction Stop
|
||||
Log-Message "Info: Directory creation, 'Chrome - VERSION' and 'Files' folder successfully created in $PSScriptRoot"
|
||||
} catch {
|
||||
Log-Message "Error: Directory creation failed - $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Copy items from source folder to destination folder
|
||||
try {
|
||||
Copy-Item -Path $sourceFolderRegular\* -Destination $destinationFolder -Recurse -Force -ErrorAction Stop
|
||||
Log-Message "Info: Regular Template successfully copied to $destinationFolder"
|
||||
} catch {
|
||||
Log-Message "Error: Failed to copy Regular Template - $_"
|
||||
}
|
||||
|
||||
# Download 64-bit Chrome installer
|
||||
$fileName1 = [System.IO.Path]::GetFileName($url1)
|
||||
$filePath1 = Join-Path -Path $filesFolder -ChildPath $fileName1
|
||||
try {
|
||||
Invoke-RestMethod -Uri $url1 -OutFile $filePath1 -ErrorAction Stop
|
||||
Log-Message "Info: Download complete, 64-bit version of Chrome successfully downloaded to $filePath1"
|
||||
} catch {
|
||||
Log-Message "Error: 64-bit Chrome download failed - $_"
|
||||
}
|
||||
|
||||
# Download 32-bit Chrome installer
|
||||
$fileName2 = [System.IO.Path]::GetFileName($url2)
|
||||
$filePath2 = Join-Path -Path $filesFolder -ChildPath $fileName2
|
||||
try {
|
||||
Invoke-RestMethod -Uri $url2 -OutFile $filePath2 -ErrorAction Stop
|
||||
Log-Message "Info: Download complete, 32-bit version of Chrome successfully downloaded to $filePath2"
|
||||
} catch {
|
||||
Log-Message "Error: 32-bit Chrome download failed - $_"
|
||||
}
|
||||
}
|
||||
|
||||
if ($config.options.enableForcedVersion) {
|
||||
# Create force update folder if it doesn't exist
|
||||
if (-not (Test-Path $forceUpdateFolder)) {
|
||||
try {
|
||||
New-Item -Path $forceUpdateFolder -ItemType Directory -ErrorAction Stop
|
||||
Log-Message "Info: Directory creation, 'Chrome - VERSION_force_update' successfully created in $PSScriptRoot"
|
||||
} catch {
|
||||
Log-Message "Error: Force update directory creation failed - $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Copy items from forced source folder to force update folder
|
||||
try {
|
||||
Copy-Item -Path "$sourceFolderForced\*" -Destination $forceUpdateFolder -Recurse -Force -ErrorAction Stop
|
||||
Log-Message "Info: Forced Template successfully copied to $forceUpdateFolder"
|
||||
} catch {
|
||||
Log-Message "Error: Failed to copy Forced Template - $_"
|
||||
}
|
||||
|
||||
# If the regular version is not enabled, download 64-bit Chrome installer directly to the force update folder
|
||||
if (-not $config.options.enableRegularVersion) {
|
||||
$fileName1 = [System.IO.Path]::GetFileName($url1)
|
||||
$filePath1 = Join-Path -Path $forceUpdateFolder -ChildPath $fileName1
|
||||
try {
|
||||
Invoke-RestMethod -Uri $url1 -OutFile $filePath1 -ErrorAction Stop
|
||||
Log-Message "Info: Download complete, 64-bit version of Chrome successfully downloaded to force update folder at $filePath1"
|
||||
} catch {
|
||||
Log-Message "Error: 64-bit Chrome download to force update folder failed - $_"
|
||||
}
|
||||
} else {
|
||||
# If the regular version is enabled, copy the downloaded 64-bit installer to the force update folder
|
||||
$fileName1 = [System.IO.Path]::GetFileName($url1)
|
||||
$filePath1 = Join-Path -Path $filesFolder -ChildPath $fileName1
|
||||
if (Test-Path $filePath1) {
|
||||
try {
|
||||
Copy-Item -Path $filePath1 -Destination $forceUpdateFolder -Force -ErrorAction Stop
|
||||
Log-Message "Info: 64-bit version of Chrome copied to force update folder at $forceUpdateFolder"
|
||||
} catch {
|
||||
Log-Message "Error: Failed to copy 64-bit installer to force update folder - $_"
|
||||
}
|
||||
} else {
|
||||
Log-Message "Warn: 64-bit version of Chrome was not downloaded and could not be copied to force update folder."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($config.options.folderNumberedVersion) {
|
||||
# Check if the script is running with administrative privileges
|
||||
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
Log-Message "Error: the config 'folderNumberedVersion' requires administrative privileges to run."
|
||||
}
|
||||
else {
|
||||
& $PSScriptRoot\Rename.ps1
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Output "For additional logs, please refer to $PSScriptRoot\$logFileName."
|
||||
}
|
270
Downloader.ps1
Normal file
270
Downloader.ps1
Normal file
|
@ -0,0 +1,270 @@
|
|||
# Read configuration from JSON file
|
||||
$configPath = "$PSScriptRoot\config.json"
|
||||
$config = Get-Content -Path $configPath | ConvertFrom-Json
|
||||
|
||||
# Get the date format from the configuration, or use the default format if not provided
|
||||
$chromedateFormat = $config.chrome.logging.logDateFormat
|
||||
if (-not $chromedateFormat) {
|
||||
$chromedateFormat = "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
|
||||
# Function to log messages with the specified date format
|
||||
$chromelogFileName = $config.chrome.logging.fileName
|
||||
$chromelogFileFormat = $config.chrome.logging.fileFormat
|
||||
if (-not $chromelogFileName) {
|
||||
$chromelogFileName = "chrome_downloader"
|
||||
}
|
||||
if (-not $chromelogFileFormat) {
|
||||
$chromelogFileFormat = "log"
|
||||
}
|
||||
|
||||
$chromelogFileNameFormat = $chromelogFileName+"."+$chromelogFileFormat
|
||||
|
||||
# Get the date format from the configuration, or use the default format if not provided
|
||||
$amazonworkspacedateFormat = $config.chrome.logging.logDateFormat
|
||||
if (-not $amazonworkspacedateFormat) {
|
||||
$amazonworkspacedateFormat = "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
|
||||
# Function to log messages with the specified date format
|
||||
$amazonworkspacelogFileName = $config.amazonWorkspace.logging.fileName
|
||||
$amazonworkspacelogFileFormat = $config.amazonWorkspace.logging.fileFormat
|
||||
if (-not $amazonworkspacelogFileName) {
|
||||
$amazonworkspacelogFileName = "chrome_downloader"
|
||||
}
|
||||
if (-not $amazonworkspacelogFileFormat) {
|
||||
$amazonworkspacelogFileFormat = "log"
|
||||
}
|
||||
|
||||
$amazonworkspacelogFileNameFormat = $amazonworkspacelogFileName+"."+$amazonworkspacelogFileFormat
|
||||
|
||||
function chrome-Log-Message {
|
||||
param (
|
||||
[string]$message
|
||||
)
|
||||
$timestamp = Get-Date -Format $chromedateFormat
|
||||
Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$chromelogFileNameFormat" -Encoding utf8
|
||||
}
|
||||
|
||||
function amazonworkspace-Log-Message {
|
||||
param (
|
||||
[string]$amazonworkspacemessage
|
||||
)
|
||||
$amazonworkspacetimestamp = Get-Date -Format $amazonworkspacedateFormat
|
||||
Write-Output "[$amazonworkspacetimestamp] - $amazonworkspacemessage" | Out-File -Append -FilePath "$PSScriptRoot\$amazonworkspacelogFileNameFormat" -Encoding utf8
|
||||
}
|
||||
|
||||
# Log the start of the script
|
||||
|
||||
if ($config.chrome.options.enableRegularVersion) {
|
||||
chrome-Log-Message "Debug: Script started"
|
||||
}
|
||||
elseif ($config.chrome.options.enableForcedVersion) {
|
||||
chrome-Log-Message "Debug: Script started"
|
||||
}
|
||||
if ($config.amazonWorkspace.options.download) {
|
||||
amazonworkspace-Log-Message "Debug: Script started"
|
||||
}
|
||||
|
||||
|
||||
# Check if both options are disabled and log a message
|
||||
if (-not $config.chrome.options.enableRegularVersion -and -not $config.chrome.options.enableForcedVersion -and -not $config.amazonWorkspace.options.download) {
|
||||
chrome-Log-Message "Warn: Neither Chrome or amazonWorkspace is selected. Please enable at least one option to proceed."
|
||||
exit
|
||||
}
|
||||
|
||||
if ($config.chrome.options.checkExist) {
|
||||
$testPath = "$PSScriptRoot\Chrome - *"
|
||||
|
||||
# Store subfolders before deletion
|
||||
$subfolders = @()
|
||||
|
||||
if (Test-Path $testPath) {
|
||||
$subfolders = Get-ChildItem -Path $testPath -Directory | ForEach-Object { $_.FullName }
|
||||
|
||||
# Remove the folders
|
||||
Remove-Item $testPath -Recurse -Force
|
||||
}
|
||||
|
||||
# Output the subfolders
|
||||
foreach ($subfolder in $subfolders) {
|
||||
chrome-Log-Message "Info: The subfolder '$subfolder\' has been deleted."
|
||||
}
|
||||
}
|
||||
if ($config.amazonWorkspace.options.checkExist) {
|
||||
$amazonworkspacetestPath = "$PSScriptRoot\Amazon Workspace - *"
|
||||
|
||||
# Store subfolders before deletion
|
||||
$amazonworkspacesubfolders = @()
|
||||
|
||||
if (Test-Path $amazonworkspacetestPath) {
|
||||
$amazonworkspacesubfolders = Get-ChildItem -Path $amazonworkspacetestPath -Directory | ForEach-Object { $_.FullName }
|
||||
|
||||
# Remove the folders
|
||||
Remove-Item $amazonworkspacetestPath -Recurse -Force
|
||||
}
|
||||
|
||||
# Output the subfolders
|
||||
foreach ($amazonworkspacesubfolder in $amazonworkspacesubfolders) {
|
||||
try {
|
||||
amazonworkspace-Log-Message "Info: The subfolder '$amazonworkspacesubfolder\' has been deleted."
|
||||
} catch {
|
||||
Write-Host "Error logging message: $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Define URLs
|
||||
$chrome64BitUrl = "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise64.msi"
|
||||
$chrome32BitUrl = "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise.msi"
|
||||
$amazonworkspace64BitUrl = "https://d2td7dqidlhjx7.cloudfront.net/prod/global/windows/Amazon+WorkSpaces.msi"
|
||||
|
||||
# Define source and destination folders
|
||||
$sourceFolderRegular = "$PSScriptRoot\Template\Chrome-Template"
|
||||
$sourceFolderForced = "$PSScriptRoot\Template\Chrome-Template-Forced"
|
||||
$amazonworkspacesourceFolderRegular = "$PSScriptRoot\Template\Amazon-Workspace-Template"
|
||||
|
||||
$destinationFolder = Join-Path -Path $PSScriptRoot -ChildPath "Chrome - VERSION"
|
||||
$forceUpdateFolder = Join-Path -Path $PSScriptRoot -ChildPath "Chrome - VERSION_force_update"
|
||||
$amazonworkspacedestinationFolder = Join-Path -Path $PSScriptRoot -ChildPath "Amazon Workspace - VERSION"
|
||||
|
||||
# Conditional execution based on config
|
||||
if ($config.chrome.options.enableRegularVersion) {
|
||||
# Create main folder and files folder if they don't exist
|
||||
$folderName = "Chrome - VERSION"
|
||||
$folderPath = Join-Path -Path $PSScriptRoot -ChildPath $folderName
|
||||
$filesFolder = Join-Path -Path $folderPath -ChildPath "Files"
|
||||
|
||||
if (-not (Test-Path $filesFolder)) {
|
||||
try {
|
||||
New-Item -Path $filesFolder -ItemType Directory -ErrorAction Stop
|
||||
chrome-Log-Message "Info: Directory creation, 'Chrome - VERSION' and 'Files' folder successfully created in $PSScriptRoot"
|
||||
} catch {
|
||||
chrome-Log-Message "Error: Directory creation failed - $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Copy items from source folder to destination folder
|
||||
try {
|
||||
Copy-Item -Path $sourceFolderRegular\* -Destination $destinationFolder -Recurse -Force -ErrorAction Stop
|
||||
chrome-Log-Message "Info: Regular Template successfully copied to $destinationFolder"
|
||||
} catch {
|
||||
chrome-Log-Message "Error: Failed to copy Regular Template - $_"
|
||||
}
|
||||
|
||||
# Download 64-bit Chrome installer
|
||||
$fileName1 = [System.IO.Path]::GetFileName($chrome64BitUrl)
|
||||
$filePath1 = Join-Path -Path $filesFolder -ChildPath $fileName1
|
||||
try {
|
||||
Invoke-RestMethod -Uri $chrome64BitUrl -OutFile $filePath1 -ErrorAction Stop
|
||||
chrome-Log-Message "Info: Download complete, 64-bit version of Chrome successfully downloaded to $filePath1"
|
||||
} catch {
|
||||
chrome-Log-Message "Error: 64-bit Chrome download failed - $_"
|
||||
}
|
||||
|
||||
# Download 32-bit Chrome installer
|
||||
$fileName2 = [System.IO.Path]::GetFileName($chrome32BitUrl)
|
||||
$filePath2 = Join-Path -Path $filesFolder -ChildPath $fileName2
|
||||
try {
|
||||
Invoke-RestMethod -Uri $chrome32BitUrl -OutFile $filePath2 -ErrorAction Stop
|
||||
chrome-Log-Message "Info: Download complete, 32-bit version of Chrome successfully downloaded to $filePath2"
|
||||
} catch {
|
||||
chrome-Log-Message "Error: 32-bit Chrome download failed - $_"
|
||||
}
|
||||
}
|
||||
|
||||
if ($config.chrome.options.enableForcedVersion) {
|
||||
# Create force update folder if it doesn't exist
|
||||
if (-not (Test-Path $forceUpdateFolder)) {
|
||||
try {
|
||||
New-Item -Path $forceUpdateFolder -ItemType Directory -ErrorAction Stop
|
||||
chrome-Log-Message "Info: Directory creation, 'Chrome - VERSION_force_update' successfully created in $PSScriptRoot"
|
||||
} catch {
|
||||
chrome-Log-Message "Error: Force update directory creation failed - $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Copy items from forced source folder to force update folder
|
||||
try {
|
||||
Copy-Item -Path "$sourceFolderForced\*" -Destination $forceUpdateFolder -Recurse -Force -ErrorAction Stop
|
||||
chrome-Log-Message "Info: Forced Template successfully copied to $forceUpdateFolder"
|
||||
} catch {
|
||||
chrome-Log-Message "Error: Failed to copy Forced Template - $_"
|
||||
}
|
||||
|
||||
# If the regular version is not enabled, download 64-bit Chrome installer directly to the force update folder
|
||||
if (-not $config.chrome.options.enableRegularVersion) {
|
||||
$fileName1 = [System.IO.Path]::GetFileName($chrome64BitUrl)
|
||||
$filePath1 = Join-Path -Path $forceUpdateFolder -ChildPath $fileName1
|
||||
try {
|
||||
Invoke-RestMethod -Uri $chrome64BitUrl -OutFile $filePath1 -ErrorAction Stop
|
||||
chrome-Log-Message "Info: Download complete, 64-bit version of Chrome successfully downloaded to force update folder at $filePath1"
|
||||
} catch {
|
||||
chrome-Log-Message "Error: 64-bit Chrome download to force update folder failed - $_"
|
||||
}
|
||||
} else {
|
||||
# If the regular version is enabled, copy the downloaded 64-bit installer to the force update folder
|
||||
$fileName1 = [System.IO.Path]::GetFileName($chrome64BitUrl)
|
||||
$filePath1 = Join-Path -Path $filesFolder -ChildPath $fileName1
|
||||
if (Test-Path $filePath1) {
|
||||
try {
|
||||
Copy-Item -Path $filePath1 -Destination $forceUpdateFolder -Force -ErrorAction Stop
|
||||
chrome-Log-Message "Info: 64-bit version of Chrome copied to force update folder at $forceUpdateFolder"
|
||||
} catch {
|
||||
chrome-Log-Message "Error: Failed to copy 64-bit installer to force update folder - $_"
|
||||
}
|
||||
} else {
|
||||
chrome-Log-Message "Warn: 64-bit version of Chrome was not downloaded and could not be copied to force update folder."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($config.amazonWorkspace.options.download) {
|
||||
# Create main folder and files folder if they don't exist
|
||||
$amazonworkspacefolderName = "Amazon Workspace - VERSION"
|
||||
$amazonworkspacefolderPath = Join-Path -Path $PSScriptRoot -ChildPath $amazonworkspacefolderName
|
||||
$amazonworkspacefilesFolder = Join-Path -Path $amazonworkspacefolderPath -ChildPath "Files"
|
||||
|
||||
if (-not (Test-Path $amazonworkspacefilesFolder)) {
|
||||
try {
|
||||
New-Item -Path $amazonworkspacefilesFolder -ItemType Directory -ErrorAction Stop
|
||||
amazonworkspace-Log-Message "Info: Directory creation, 'Amazon Workspace - VERSION' and 'Files' folder successfully created in $PSScriptRoot"
|
||||
} catch {
|
||||
amazonworkspace-Log-Message "Error: Directory creation failed - $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Copy items from source folder to destination folder
|
||||
try {
|
||||
Copy-Item -Path $amazonworkspacesourceFolderRegular\* -Destination $amazonworkspacedestinationFolder -Recurse -Force -ErrorAction Stop
|
||||
amazonworkspace-Log-Message "Info: Regular Template successfully copied to $amazonworkspacedestinationFolder"
|
||||
} catch {
|
||||
amazonworkspace-Log-Message "Error: Failed to copy Regular Template - $_"
|
||||
}
|
||||
|
||||
# Download 64-bit Amazon Workspace installer
|
||||
$amazonworkspacefileName1 = [System.IO.Path]::GetFileName($amazonworkspace64BitUrl)
|
||||
$amazonworkspacefilePath1 = Join-Path -Path $amazonworkspacefilesFolder -ChildPath $amazonworkspacefileName1
|
||||
try {
|
||||
Invoke-RestMethod -Uri $amazonworkspace64BitUrl -OutFile $amazonworkspacefilePath1 -ErrorAction Stop
|
||||
amazonworkspace-Log-Message "Info: Download complete, 64-bit version of Amazon Workspace successfully downloaded to $filePath1"
|
||||
} catch {
|
||||
amazonworkspace-Log-Message "Error: 64-bit Amazon Workspace download failed - $_"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($config.chrome.options.folderNumberedVersion -or $config.amazonWorkspace.options.folderNumberedVersion) {
|
||||
# Check if the script is running with administrative privileges
|
||||
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
chrome-Log-Message "Error: the config 'folderNumberedVersion' requires administrative privileges to run."
|
||||
amazonworkspace-Log-Message "Error: the config 'folderNumberedVersion' requires administrative privileges to run."
|
||||
}
|
||||
else {
|
||||
& $PSScriptRoot\Rename.ps1
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Output "For additional logs, please refer to $PSScriptRoot\$logFileName."
|
||||
}
|
47
README.md
47
README.md
|
@ -1,6 +1,6 @@
|
|||
# Google Chrome Downloader MSI Script
|
||||
# Google Chrome & Amazon Workspaces Downloader MSI Script
|
||||
|
||||
This PowerShell script automates the process of downloading and organizing Google Chrome installers based on specified configurations. It supports downloading both 64-bit and 32-bit versions of Chrome and organizing them into appropriate folders.
|
||||
This PowerShell script automates the process of downloading and organizing Google Chrome and Amazon Workspaces installers based on specified configurations. It supports downloading both 64-bit and 32-bit versions of Chrome and organizing them into appropriate folders. (64-bit only on Amazon Workspaces)
|
||||
|
||||
## Script Overview
|
||||
|
||||
|
@ -12,26 +12,40 @@ The script reads its configuration from a JSON file named config.json located in
|
|||
The `config.json` file should be structured as follows:
|
||||
```json
|
||||
{
|
||||
"options": {
|
||||
"enableRegularVersion": true,
|
||||
"enableForcedVersion": false,
|
||||
"folderNumberedVersion": false,
|
||||
"checkExist": false
|
||||
"chrome":{
|
||||
"options": {
|
||||
"enableRegularVersion": true,
|
||||
"enableForcedVersion": false,
|
||||
"folderNumberedVersion": false,
|
||||
"checkExist": false
|
||||
},
|
||||
"logging": {
|
||||
"fileName": "google_chrome",
|
||||
"fileFormat": "log",
|
||||
"logDateFormat": "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
},
|
||||
"logging": {
|
||||
"fileName": "chrome_downloader",
|
||||
"fileFormat": "log",
|
||||
"logDateFormat": "dd/MM/yyyy HH:mm:ss"
|
||||
|
||||
"amazonWorkspace":{
|
||||
"options": {
|
||||
"download": false,
|
||||
"folderNumberedVersion": false,
|
||||
"checkExist": false
|
||||
},
|
||||
"logging": {
|
||||
"fileName": "amazon_workspace",
|
||||
"fileFormat": "log",
|
||||
"logDateFormat": "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `enableRegularVersion`: A boolean flag to enable downloading and installing the regular version of Chrome.
|
||||
- `enableForcedVersion`: A boolean flag to enable downloading and installing the forced update version of Chrome.
|
||||
- `download`: A boolean flag to enable downloading and installing Amazon Workspaces.
|
||||
- `folderNumberedVersion`: A boolean flag to enable the automatic renaming of the folder to the newest version of Chrome. ⚠️ **This option requires administrative privileges when executing the script!** ⚠️
|
||||
- `checkExist`: A boolean flag to delete old Chrome folders when the script is executed. ⚠️ **This action will delete your Chrome folders, so ensure you have backups if you wish to retain them.** ⚠️
|
||||
- `fileName`: A string defining the name of the log file. The default name is `chrome_downloader`.
|
||||
- `fileName`: A string defining the name of the log file. The default name is `google_chrome` and `amazon_workspace`.
|
||||
- `fileFormat`: A string defining the format of the log file. The default format is `log`.
|
||||
- `logDateFormat`: A string defining the format of timestamps in logs. The default format is `dd/MM/yyyy HH:mm:ss`.
|
||||
|
||||
|
@ -103,6 +117,7 @@ Ensure that `config.json` is present in the same directory as the script.
|
|||
Create the following template folders and populate them with necessary files:
|
||||
- `Template\Chrome-Template`
|
||||
- `Template\Chrome-Template-Forced`
|
||||
- `Template\Amazon-Workspace-Template`
|
||||
|
||||
### 2. Downloading the Script:
|
||||
|
||||
|
@ -112,7 +127,7 @@ You can download the script using `git clone` command. Follow these steps:
|
|||
2. Navigate to the directory where you want to download the script.
|
||||
3. Run the following command:
|
||||
```
|
||||
git clone https://forgejo.olayzen.com/OlaYZen/Chrome-Downloader.git
|
||||
git clone https://forgejo.olayzen.com/OlaYZen/MSI-Downloader.git
|
||||
```
|
||||
|
||||
This command will clone the repository into your current directory.
|
||||
|
@ -122,9 +137,9 @@ This command will clone the repository into your current directory.
|
|||
- Open PowerShell and navigate to the directory containing the script and config.json.
|
||||
- Execute the script:
|
||||
```css
|
||||
& '.\Chrome Downloader.ps1'
|
||||
& '.\Downloader.ps1'
|
||||
```
|
||||
|
||||
### 4. Monitor the Logs:
|
||||
|
||||
- Check `chrome_downloader.log` in the script directory for detailed logs of the execution process, including any errors encountered.
|
||||
- Check `google_chrome.log` or `amazon_workspace.log` in the script directory for detailed logs of the execution process, including any errors encountered.
|
||||
|
|
106
Rename.ps1
106
Rename.ps1
|
@ -1,36 +1,59 @@
|
|||
# Read configuration from JSON file
|
||||
$configPath = "$PSScriptRoot\config.json"
|
||||
$config = Get-Content -Path $configPath | ConvertFrom-Json
|
||||
|
||||
# Get the date format from the configuration, or use the default format if not provided
|
||||
$dateFormat = $config.logging.logDateFormat
|
||||
if (-not $dateFormat) {
|
||||
$dateFormat = "dd/MM/yyyy HH:mm:ss"
|
||||
$chromedateFormat = $config.chrome.logging.logDateFormat
|
||||
if (-not $chromedateFormat) {
|
||||
$chromedateFormat = "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
|
||||
$destinationFolder = Join-Path -Path $PSScriptRoot -ChildPath "Chrome - VERSION"
|
||||
$forceUpdateFolder = Join-Path -Path $PSScriptRoot -ChildPath "Chrome - VERSION_force_update"
|
||||
|
||||
# Function to log messages with the specified date format
|
||||
$logFileName = $config.logging.fileName
|
||||
$logFileFormat = $config.logging.fileFormat
|
||||
if (-not $logFileName) {
|
||||
$logFileName = "chrome_downloader.log"
|
||||
$chromelogFileName = $config.chrome.logging.fileName
|
||||
$chromelogFileFormat = $config.chrome.logging.fileFormat
|
||||
if (-not $chromelogFileName) {
|
||||
$chromelogFileName = "chrome_downloader"
|
||||
}
|
||||
if (-not $logFileFormat) {
|
||||
$logFileFormat = "log"
|
||||
if (-not $chromelogFileFormat) {
|
||||
$chromelogFileFormat = "log"
|
||||
}
|
||||
$logFileNameFormat = $logFileName+"."+$logFileFormat
|
||||
|
||||
function Log-Message {
|
||||
$chromelogFileNameFormat = $chromelogFileName+"."+$chromelogFileFormat
|
||||
|
||||
# Get the date format from the configuration, or use the default format if not provided
|
||||
$amazonworkspacedateFormat = $config.chrome.logging.logDateFormat
|
||||
if (-not $amazonworkspacedateFormat) {
|
||||
$amazonworkspacedateFormat = "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
|
||||
# Function to log messages with the specified date format
|
||||
$amazonworkspacelogFileName = $config.amazonWorkspace.logging.fileName
|
||||
$amazonworkspacelogFileFormat = $config.amazonWorkspace.logging.fileFormat
|
||||
if (-not $amazonworkspacelogFileName) {
|
||||
$amazonworkspacelogFileName = "chrome_downloader"
|
||||
}
|
||||
if (-not $amazonworkspacelogFileFormat) {
|
||||
$amazonworkspacelogFileFormat = "log"
|
||||
}
|
||||
|
||||
$amazonworkspacelogFileNameFormat = $amazonworkspacelogFileName+"."+$amazonworkspacelogFileFormat
|
||||
|
||||
function chrome-Log-Message {
|
||||
param (
|
||||
[string]$message
|
||||
)
|
||||
$timestamp = Get-Date -Format $dateFormat
|
||||
Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileNameFormat" -Encoding utf8
|
||||
$timestamp = Get-Date -Format $chromedateFormat
|
||||
Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$chromelogFileNameFormat" -Encoding utf8
|
||||
}
|
||||
|
||||
if ($config.options.enableRegularVersion -and -not $config.options.enableForcedVersion) {
|
||||
function amazonworkspace-Log-Message {
|
||||
param (
|
||||
[string]$message
|
||||
)
|
||||
$timestamp = Get-Date -Format $amazonworkspacedateFormat
|
||||
Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$amazonworkspacelogFileNameFormat" -Encoding utf8
|
||||
}
|
||||
|
||||
if ($config.chrome.options.enableRegularVersion -and -not $config.chrome.options.enableForcedVersion) {
|
||||
$msiPath = "$PSScriptRoot\Chrome - VERSION\Files\googlechromestandaloneenterprise64.msi"
|
||||
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$msiPath`" /quiet" -Wait
|
||||
$chromeRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||
|
@ -43,15 +66,15 @@ if ($config.options.enableRegularVersion -and -not $config.options.enableForcedV
|
|||
$newFolderName = "Chrome - $chromeVersion"
|
||||
try {
|
||||
Rename-Item -Path $destinationFolder -NewName $newFolderName -ErrorAction Stop
|
||||
Log-Message "Info: Folder renamed to $newFolderName"
|
||||
chrome-Log-Message "Info: Folder renamed to $newFolderName"
|
||||
} catch {
|
||||
Log-Message "Error: Failed to rename folder - $_"
|
||||
chrome-Log-Message "Error: Failed to rename folder - $_"
|
||||
}
|
||||
} else {
|
||||
Log-Message "Warn: Chrome version could not be determined. Folder was not renamed."
|
||||
chrome-Log-Message "Warn: Chrome version could not be determined. Folder was not renamed."
|
||||
}
|
||||
}
|
||||
elseif ($config.options.enableForcedVersion -and -not $config.options.enableRegularVersion) {
|
||||
elseif ($config.chrome.options.enableForcedVersion -and -not $config.chrome.options.enableRegularVersion) {
|
||||
$msiPath = "$PSScriptRoot\Chrome - VERSION_force_update\googlechromestandaloneenterprise64.msi"
|
||||
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$msiPath`" /quiet" -Wait
|
||||
$chromeRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||
|
@ -64,15 +87,15 @@ elseif ($config.options.enableForcedVersion -and -not $config.options.enableRegu
|
|||
$newFolderName = "Chrome - $chromeVersion" + "_force_update"
|
||||
try {
|
||||
Rename-Item -Path $forceUpdateFolder -NewName $newFolderName -ErrorAction Stop
|
||||
Log-Message "Info: Folder renamed to $newFolderName"
|
||||
chrome-Log-Message "Info: Folder renamed to $newFolderName"
|
||||
} catch {
|
||||
Log-Message "Error: Failed to rename folder - $_"
|
||||
chrome-Log-Message "Error: Failed to rename folder - $_"
|
||||
}
|
||||
} else {
|
||||
Log-Message "Warn: Chrome version could not be determined. Folder was not renamed."
|
||||
chrome-Log-Message "Warn: Chrome version could not be determined. Folder was not renamed."
|
||||
}
|
||||
}
|
||||
elseif ($config.options.enableForcedVersion -and $config.options.enableRegularVersion) {
|
||||
elseif ($config.chrome.options.enableForcedVersion -and $config.chrome.options.enableRegularVersion) {
|
||||
$msiPath = "$PSScriptRoot\Chrome - VERSION_force_update\googlechromestandaloneenterprise64.msi"
|
||||
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$msiPath`" /quiet" -Wait
|
||||
|
||||
|
@ -88,21 +111,42 @@ elseif ($config.options.enableForcedVersion -and $config.options.enableRegularVe
|
|||
$newRegularFolderName = "Chrome - $chromeVersion"
|
||||
try {
|
||||
Rename-Item -Path $destinationFolder -NewName $newRegularFolderName -ErrorAction Stop
|
||||
Log-Message "Info: Folder renamed to $newRegularFolderName"
|
||||
chrome-Log-Message "Info: Folder renamed to $newRegularFolderName"
|
||||
} catch {
|
||||
Log-Message "Error: Failed to rename folder - $_"
|
||||
chrome-Log-Message "Error: Failed to rename folder - $_"
|
||||
}
|
||||
|
||||
# Forced version folder
|
||||
$newForcedFolderName = "Chrome - $chromeVersion" + "_force_update"
|
||||
try {
|
||||
Rename-Item -Path $forceUpdateFolder -NewName $newForcedFolderName -ErrorAction Stop
|
||||
Log-Message "Info: Folder renamed to $newForcedFolderName"
|
||||
chrome-Log-Message "Info: Folder renamed to $newForcedFolderName"
|
||||
} catch {
|
||||
Log-Message "Error: Failed to rename folder - $_"
|
||||
chrome-Log-Message "Error: Failed to rename folder - $_"
|
||||
}
|
||||
} else {
|
||||
Log-Message "Warn: Chrome version could not be determined. Folders were not renamed."
|
||||
chrome-Log-Message "Warn: Chrome version could not be determined. Folders were not renamed."
|
||||
}
|
||||
}
|
||||
if ($config.amazonWorkspace.options.download) {
|
||||
$msiPathamazonworkspace = "$PSScriptRoot\Amazon Workspace - VERSION\Files\Amazon+WorkSpaces.msi"
|
||||
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$msiPathamazonworkspace`" /quiet" -Wait
|
||||
$workspacesRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||
$workspacesVersion = Get-ChildItem -Path $workspacesRegPath |
|
||||
Get-ItemProperty |
|
||||
Where-Object { $_.DisplayName -like "*Amazon Workspaces*" } |
|
||||
Select-Object -ExpandProperty DisplayVersion
|
||||
# Rename the folder if the version was retrieved
|
||||
if ($workspacesVersion) {
|
||||
$newFolderNameamazonworkspace = "Amazon Workspace - $workspacesVersion"
|
||||
try {
|
||||
Rename-Item -Path $amazonworkspacedestinationFolder -NewName $newFolderNameamazonworkspace -ErrorAction Stop
|
||||
amazonworkspace-Log-Message "Info: Folder renamed to $newFolderNameamazonworkspace"
|
||||
} catch {
|
||||
amazonworkspace-Log-Message "Error: Failed to rename folder - $_"
|
||||
}
|
||||
} else {
|
||||
amazonworkspace-Log-Message "Warn: Amazon Workspaces version could not be determined. Folder was not renamed."
|
||||
}
|
||||
}
|
||||
Write-Output "For additional logs, please refer to $PSScriptRoot\$logFileName."
|
32
config.json
32
config.json
|
@ -1,13 +1,27 @@
|
|||
{
|
||||
"options": {
|
||||
"enableRegularVersion": true,
|
||||
"enableForcedVersion": false,
|
||||
"folderNumberedVersion": false,
|
||||
"checkExist": false
|
||||
"chrome":{
|
||||
"options": {
|
||||
"enableRegularVersion": true,
|
||||
"enableForcedVersion": false,
|
||||
"folderNumberedVersion": false,
|
||||
"checkExist": false
|
||||
},
|
||||
"logging": {
|
||||
"fileName": "google_chrome",
|
||||
"fileFormat": "log",
|
||||
"logDateFormat": "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
},
|
||||
"logging": {
|
||||
"fileName": "chrome_downloader",
|
||||
"fileFormat": "log",
|
||||
"logDateFormat": "dd/MM/yyyy HH:mm:ss"
|
||||
"amazonWorkspace":{
|
||||
"options": {
|
||||
"download": false,
|
||||
"folderNumberedVersion": false,
|
||||
"checkExist": false
|
||||
},
|
||||
"logging": {
|
||||
"fileName": "amazon_workspace",
|
||||
"fileFormat": "log",
|
||||
"logDateFormat": "dd/MM/yyyy HH:mm:ss"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue