Skip to content

Commit

Permalink
Update Script
Browse files Browse the repository at this point in the history
  • Loading branch information
herrwinfried committed May 29, 2024
1 parent d0de9f5 commit 5809133
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 161 deletions.
Binary file added assets/image/odt-script.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 86 additions & 66 deletions installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,29 @@ if (-Not (Test-Path "$PSScriptRoot/lang/en-US/$GetScriptName.psd1")) {
}
# language support complete

$Host.UI.RawUI.WindowTitle = "HerrWinfried - $($Language.ScriptTitle)"
$Host.UI.RawUI.WindowTitle = "$($Language.ScriptTitle -f 'herrwinfried')"

[string]$Global:ConfigPath = "$GetScriptDir\Configuration.xml"
[string]$Global:ODTPath = "$GetScriptDir\odt.exe"
[string]$Global:ODTDownloadURL = "https://download.microsoft.com/download/2/7/A/27AF1BE6-DD20-4CB4-B154-EBAB8A7D4A7E/officedeploymenttool_17531-20046.exe"
[string]$Global:SetupPath = "$GetScriptDir\setup.exe"
[string]$Global:ConfigGeneratorURL = "https://config.office.com/deploymentsettings"
[string]$Global:GetOfficePath = "$GetScriptDir\office"

function Invoke-ODTExtraction {
$odtPath = "$GetScriptDir\odt.exe"
$odtDownloadUrl = "https://download.microsoft.com/download/2/7/A/27AF1BE6-DD20-4CB4-B154-EBAB8A7D4A7E/officedeploymenttool_17531-20046.exe"
function Test-Setup {

if (-Not (Test-Path $odtPath)) {
Write-Host "$($Language.NotFoundOdt) $($Language.DownloadInternet)"
Write-Information "$odtDownloadUrl"

try {
Invoke-WebRequest -Uri $odtDownloadUrl -OutFile $odtPath
Write-Host -ForegroundColor Green "$($Language.OdtDownload)"
} catch {
Write-Host -ForegroundColor Red "$($Language.OdtDownloadNot)"
if (-Not (Test-Path $SetupPath)) {
Write-Host "$($Language.TestSetup)"
if (-Not (Invoke-ODTExtraction)) {
return $false
}
}

Write-Host -ForegroundColor Cyan "$($Language.OdtSetupExeExt)"
& $odtPath /extract:$GetScriptDir /quiet
if ($LASTEXITCODE -eq 0) {
Write-Host -ForegroundColor Green "$($Language.OdtSetupExe)"
return $true
} else {
Write-Host -ForegroundColor Red "$($Language.OdtSetupExeNot)"
return $false
}
return $true
}

function Test-SetupExe {
$SetupPath = "$GetScriptDir\setup.exe"
if (-Not (Test-Path $SetupPath)) {
Write-Host "$($Language.TestSetupExe)"
function Test-ODT {

if (-Not (Test-Path $ODTPath)) {
if (-Not (Invoke-ODTExtraction)) {
return $false
}
Expand All @@ -59,71 +46,93 @@ function Test-SetupExe {
}

function Test-ConfigFile {
if (-Not (Test-Path $Global:ConfigPath)) {
Write-Host -ForegroundColor Red "$($Language.TestConfigFileInfo -f $Global:ConfigPath)"
Write-Host -ForegroundColor DarkBlue "https://config.office.com/deploymentsettings"
Write-Host -ForegroundColor DarkBlue "$($Language.TestConfigFileInfoHelp)"
if (-Not (Test-Path $ConfigPath)) {
Write-Host -ForegroundColor Red "$($Language.ConfigFile1 -f $ConfigPath)"
Write-Host -ForegroundColor DarkBlue "$ConfigGeneratorURL"
Write-Host -ForegroundColor DarkBlue "$($Language.ConfigFile2)"
Show-Menu
return $false
}
return $true
}

function Invoke-Office {
if (-Not (Test-SetupExe)) {
Write-Host -ForegroundColor Red "$($Language.InvokeOfficeNotFoundSetupExe)"
return
function Invoke-ODTExtraction {

if (-Not (Test-Path $ODTPath)) {
Write-Host "$($Language.NotFound -f $ODTPath) $($Language.DownloadInternet)"
Write-Information "$ODTDownloadURL"

try {
Invoke-WebRequest -Uri $ODTDownloadURL -OutFile $ODTPath
Write-Host -ForegroundColor Green "$($Language.DownloadSuccess -f 'odt.exe')"
} catch {
Write-Host -ForegroundColor Red "$($Language.DownloadFailed -f 'odt.exe')"
return $false
}
}

if (Test-Path "$GetScriptDir\office.old") {
Write-Host -ForegroundColor Yellow "$($Language.InvokeOfficeFoundOffice_old -f "$GetScriptDir\office.old" )"
Remove-Item -Path "$GetScriptDir\office.old" -Force -Recurse
Write-Host -ForegroundColor Cyan "$($Language.Extracting -f 'odt.exe')"
& $ODTPath /extract:$GetScriptDir /quiet
if ($LASTEXITCODE -eq 0) {
Write-Host -ForegroundColor Green "$($Language.AddedSuccess -f 'setup.exe')"
return $true
} else {
Write-Host -ForegroundColor Red "$($Language.ExtractingFailed -f 'setup.exe')"
return $false
}
}

if (Test-Path "$GetScriptDir\office") {
Write-Host -ForegroundColor Yellow ($Language.InvokeOfficeFoundOffice -f "$GetScriptDir\office", "$GetScriptDir\office.old")
Move-Item -Path "$GetScriptDir\office" -Destination "$GetScriptDir\office.old" -Force
function Invoke-Office {

if (-Not (Test-ODT)) {
return
}

if (-Not (Test-ConfigFile)) {
if (-Not (Test-Setup)) {
return
}

$SetupPath = "$GetScriptDir\setup.exe"
Write-Host -ForegroundColor Green "$($Language.Starting -f $SetupPath) [Download]"
if (-Not (Test-ConfigFile)) {
return
}
Write-Host -ForegroundColor Green "$($Language.Starting -f $SetupPath)"
Write-Host -ForegroundColor Yellow "$($Language.InvokeOfficeInfo)"
Write-Host -ForegroundColor Yellow "$($Language.InvokeOfficeInfo1 -f "$GetScriptDir\office")"
& $SetupPath /download $Global:ConfigPath
Write-Host -ForegroundColor Yellow "$($Language.InvokeOfficeInfo1 -f "$GetOfficePath")"
& $SetupPath /download $ConfigPath
if ($LASTEXITCODE -eq 0) {
Write-Host -ForegroundColor Green "$($Language.InvokeOfficeDownload)"
Write-Host -ForegroundColor Green "$($Language.DownloadSuccessOffice -f 'office')"
} else {
Write-Host -ForegroundColor Red "$($Language.InvokeOfficeDownloadNot)"
Write-Host -ForegroundColor Red "$($Language.DownloadFailedOffice -f 'office')"
}
Write-Host "`a"
}

function Install-Office {
if (-Not (Test-SetupExe)) {
Write-Host -ForegroundColor Red "$($Language.TestSetupExe)"
if (-Not (Test-ODT)) {
return
}

if (-Not (Test-Setup)) {
return
}

if (-Not (Test-ConfigFile)) {
return
}

if (-Not (Test-Path "$GetScriptDir\office")) {
Write-Host -ForegroundColor Yellow "$($Language.InstallOfficeFoundOfficeNot)"
Invoke-Office
if (-Not (Test-Path "$GetOfficePath")) {
Write-Host -ForegroundColor Yellow "$($Language.NotFound -f "$GetOfficePath")"
return
}

$SetupPath = "$GetScriptDir\setup.exe"
Write-Host -ForegroundColor Green "$($Language.Starting -f $SetupPath) [Install]"
& $SetupPath /configure $Global:ConfigPath
Write-Host -ForegroundColor Green "$($Language.Starting -f $SetupPath)"
& $SetupPath /configure $ConfigPath
if ($LASTEXITCODE -eq 0) {
Write-Host -ForegroundColor Green "$($Language.InstallOfficeDownload)"
Write-Host -ForegroundColor Green "$($Language.InstallSuccessOffice -f 'office')"
} else {
Write-Host -ForegroundColor Red "$($Language.InstallOfficeDownloadNot)"
Write-Host -ForegroundColor Red "$($Language.InstallFailedOffice -f 'office')"
}
Write-Host "`a"
}

function Set-ConfigPath {
Expand All @@ -135,7 +144,7 @@ function Set-ConfigPath {
$newConfigPath = $OpenFileDialog.FileName
if (Test-Path $newConfigPath) {
$Global:ConfigPath = $newConfigPath
Write-Host -ForegroundColor Green "$($Language.SetConfigSuccessPath -f $Global:ConfigPath)"
Write-Host -ForegroundColor Green "$($Language.SetConfigSuccessPath -f $ConfigPath)"
Write-Warning "$($Language.SetConfigSuccessWarn)"
Write-host
} else {
Expand All @@ -146,29 +155,40 @@ function Set-ConfigPath {
}

function Show-Menu {
Write-Host -ForegroundColor Green "$($Language.ShowMenuConfigPath) $Global:ConfigPath"
Write-Host -ForegroundColor Cyan "$($Language.ShowMenuOfficePath) $GetScriptDir\office"
Write-Host -ForegroundColor Magenta "Github: https://github.com/herrwinfried/odt-script"
Write-Host -ForegroundColor Green "$($Language.ShowMenuConfigPath -f $ConfigPath)"
Write-Host -ForegroundColor Cyan "$($Language.ShowMenuOfficePath -f $GetOfficePath)"
Write-Host ""
Write-Host -ForegroundColor DarkYellow "$($Language.ShowMenuSelection)`n"
Write-Host -ForegroundColor Red "[0] $($Language.ShowMenuZero)"
Write-Host -ForegroundColor DarkGray "[1] $($Language.ShowMenuOne)"
Write-Host -ForegroundColor DarkCyan "[1] $($Language.ShowMenuOne)"
Write-Host -ForegroundColor DarkBlue "[2] $($Language.ShowMenuTwo)"
Write-Host -ForegroundColor DarkRed "[3] $($Language.ShowMenuFour)"
$choice = Read-Host "$($Language.ShowMenuInput) (1, 2 or 3)"
Write-Host -ForegroundColor DarkBlue "[3] $($Language.ShowMenuThree)"
Write-Host -ForegroundColor DarkMagenta "[4] $($Language.ShowMenuFour)"
$choice = Read-Host "$($Language.ShowMenuInput)"

switch ($choice) {
0 {
Exit 0
}
1 {
Write-Host -ForegroundColor DarkGreen "`n$($Language.Starting -f $Language.ShowMenuTwo)`n"
Invoke-Office
Write-Host -ForegroundColor DarkGreen "`n$($Language.Starting -f $Language.ShowMenuThree)`n"
Install-Office
Show-Menu
}
2 {
Install-Office
Write-Host -ForegroundColor DarkGreen "`n$($Language.Starting -f $Language.ShowMenuTwo)`n"
Invoke-Office
Show-Menu
}
3 {
Write-Host -ForegroundColor DarkGreen "`n$($Language.Starting -f $Language.ShowMenuThree)`n"
Install-Office
Show-Menu
}
4 {
Set-ConfigPath
Show-Menu
}
Expand All @@ -181,4 +201,4 @@ function Show-Menu {
}
}

Show-Menu
Show-Menu
93 changes: 47 additions & 46 deletions lang/en-US/installer.psd1
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
@{
# HerrWinfried - Office Installer
ScriptTitle = 'Office Installer'
# odt.exe not found. Downloading from the internet...
NotFoundOdt = 'odt.exe not found.'
DownloadInternet = 'Downloading from the internet...'
# odt.exe was downloaded successfully.
OdtDownload = 'odt.exe was downloaded successfully.'
# odt.exe could not be downloaded. Please check the URL and your internet connection.
OdtDownloadNot = 'odt.exe could not be downloaded. Please check the URL and your internet connection.'
# Extracting odt.exe
OdtSetupExeExt = 'Extracting odt.exe'
# setup.exe has been added successfully.
OdtSetupExe = 'setup.exe has been added successfully.'
# setup.exe extraction failed.
OdtSetupExeNot = 'setup.exe extraction failed.'
ScriptTitle = '{0} - Office Installer'
# setup.exe not found. Extracting from odt.exe...
TestSetupExe = 'setup.exe not found. Extracting from odt.exe...'
# $Global:ConfigPath not found. Please check the existence of the file.
TestConfigFileInfo = '{0} not found. Please check the existence of the file.'
TestSetup = 'setup.exe not found. Extracting from odt.exe...'
# <COMMAND> Not Found.
NotFound = '{0} Not Found.'
# Downloading from the internet...
DownloadInternet = 'Downloading from the internet...'
# <COMMAND.EXE> was downloaded successfully.
DownloadSuccess = '{0} was downloaded successfully.'
# <COMMAND.EXE> could not be downloaded. Please check the URL and your internet connection.
DownloadFailed = '{0} could not be downloaded. Please check the URL and your internet connection.'
# Extracting <COMMAND.EXE/FILE>
Extracting = 'Extracting {0}'
# <COMMAND.EXE/FILE> has been added successfully.
ExtractingSuccess = '{0} has been added successfully.'
# <COMMAND.EXE/FILE> extraction failed.
ExtractingFailed = '{0} setup.exe extraction failed.'
# <FILE PATH> not found. Please check the existence of the file.
ConfigFile1 = '{0} not found. Please check the existence of the file.'
# Export > Default File Format > Office Open XML Formats
TestConfigFileInfoHelp = 'Export > Default File Format > Office Open XML Formats'
# Not found setup.exe
InvokeOfficeNotFoundSetupExe = 'Not found setup.exe'
# Found $GetScriptDir\office.old. Deleting...
InvokeOfficeFoundOffice_old = 'Found {0}. Deleting...'
# Found $GetScriptDir\office. Renaming to $GetScriptDir\office.old
InvokeOfficeFoundOffice = 'Found {0}. Renaming to {1}'
# Starting $SetupPath
ConfigFile2 = 'Export > Default File Format > Office Open XML Formats'
# Starting <COMMAND.EXE>
Starting = 'Starting {0}'
# Nothing will change until the process is completed.
InvokeOfficeInfo = 'Nothing will change until the process is completed.'
#You can monitor the download by checking $GetScriptDir\office or your internet status in the task manager.
InvokeOfficeInfo1 = 'You can monitor the download by checking {0} or your internet status in the task manager.'
# Office was downloaded successfully.
DownloadSuccessOffice = '{0} was downloaded successfully.'
# Office could not be downloaded. Please check the URL and your internet connection.
DownloadFailedOffice = '{0} could not be downloaded. Please check the URL and your internet connection.'
# Office successfully downloaded.
InvokeOfficeDownload = 'Office successfully downloaded.'
# Office download failed.
InvokeOfficeDownloadNot = 'Office download failed.'
# Office folder not found. Downloading...
InstallOfficeFoundOfficeNot = 'Office folder not found. Downloading...'
# Office successfully downloaded.
InstallOfficeDownload = 'Office successfully installed.'
InstallSuccessOffice = '{0} successfully installed.'
# Office download failed.
InstallOfficeDownloadNot = 'Office installation failed.'
InstallFailedOffice = '{0} installation failed.'
# Select the Configuration XML File
OpenFileDialogTitle = 'Select the Configuration XML File'
# Configuration path set to $Global:ConfigPath
SetConfigSuccessPath= 'Configuration path set to {0}'
# Configuration path set to <FILE PATH>
SetConfigSuccessPath = 'Configuration path set to {0}'
# This setting will be reset when you reopen the program.
SetConfigSuccessWarn= 'This setting will be reset when you reopen the program.'
# File not found at $newConfigPath. Please check the path and try again.
SetConfigFailedPath= 'File not found at {0}. Please check the path and try again.'
# Configuration Path:
ShowMenuConfigPath = 'Configuration Path:'
# Office Path:
ShowMenuOfficePath = 'Office Path:'
# Please make a selection:
ShowMenuSelection = 'Please make a selection:'
SetConfigSuccessWarn = 'This setting will be reset when you reopen the program.'
# File not found at <FILE PATH>. Please check the path and try again.
SetConfigFailedPath = 'File not found at {0}. Please check the path and try again.'

# Configuration Path: <PATH>
ShowMenuConfigPath = 'Configuration Path: {0}'
# Office Path: <PATH>
ShowMenuOfficePath = 'Office Path: {0}'
# Please make a selection:
ShowMenuSelection = 'Please make a selection'
# Enter your choice
ShowMenuInput = 'Enter your choice'
# Exit Script
ShowMenuZero = 'Exit Script'
ShowMenuOne = 'Download Office'
ShowMenuTwo = 'Install Office'
# Download and Install
ShowMenuOne = 'Download Office and Install Office'
# Download Office
ShowMenuTwo = 'Download Office'
# Install Office
ShowMenuThree = 'Install Office'
# Change Configuration
ShowMenuFour = 'Change Configuration'
# You made an invalid selection.
ShowMenuInvalid = 'You made an invalid selection.'
}
Loading

0 comments on commit 5809133

Please sign in to comment.