functional improvements
This commit is contained in:
+19
-19
@@ -2,40 +2,40 @@
|
|||||||
|
|
||||||
function process_debian()
|
function process_debian()
|
||||||
{
|
{
|
||||||
## Update repos
|
## Update repos
|
||||||
apt-get update
|
apt-get update
|
||||||
|
|
||||||
## Upgrade packages
|
## Upgrade packages
|
||||||
apt-get upgrade -y
|
apt-get upgrade -y
|
||||||
|
|
||||||
## Remove unused packages
|
## Remove unused packages
|
||||||
apt autoremove
|
apt autoremove
|
||||||
|
|
||||||
## Remove old cached packages
|
## Remove old cached packages
|
||||||
apt autoclean
|
apt autoclean
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_rhel()
|
function process_rhel()
|
||||||
{
|
{
|
||||||
## Clean cache
|
## Clean cache
|
||||||
yum clean all
|
yum clean all
|
||||||
|
|
||||||
## Update all packages, skipping problematic dependencies
|
## Update all packages, skipping problematic dependencies
|
||||||
yum update --skip-broken
|
yum update --skip-broken
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_fedora()
|
function process_fedora()
|
||||||
{
|
{
|
||||||
## Update Fedora release
|
## Update Fedora release
|
||||||
dnf upgrade --refresh
|
dnf upgrade --refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -n "$(command -v apt-get)" ]; then
|
if [ -n "$(command -v apt-get)" ]; then
|
||||||
process_debian
|
process_debian
|
||||||
elif [ -n "$(command -v yum)" ]; then
|
elif [ -n "$(command -v yum)" ]; then
|
||||||
process_rhel
|
process_rhel
|
||||||
elif [ -n "$(command -v dnf)" ]; then
|
elif [ -n "$(command -v dnf)" ]; then
|
||||||
process_fedora
|
process_fedora
|
||||||
else
|
else
|
||||||
echo "Package manager not found!"
|
echo "Package manager not found!"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -13,19 +13,24 @@ $LogFilePrefix = Get-Date -Format "yyyyMMddHHmmss"
|
|||||||
|
|
||||||
## Make sure all the management directories exist
|
## Make sure all the management directories exist
|
||||||
If ( !(Test-Path $MSPRoot) )
|
If ( !(Test-Path $MSPRoot) )
|
||||||
{ New-Item -Path $MSPRoot -ItemType Directory -Force | Out-Null }
|
{ New-Item -Path $MSPRoot -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||||
If ( !(Test-Path $MSPScripts) )
|
If ( !(Test-Path $MSPScripts) )
|
||||||
{ New-Item -Path $MSPScripts -ItemType Directory -Force | Out-Null }
|
{ New-Item -Path $MSPScripts -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||||
If ( !(Test-Path $MSPTools) )
|
If ( !(Test-Path $MSPTools) )
|
||||||
{ New-Item -Path $MSPTools -ItemType Directory -Force | Out-Null }
|
{ New-Item -Path $MSPTools -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||||
If ( !(Test-Path $MSPLogs) )
|
If ( !(Test-Path $MSPLogs) )
|
||||||
{ New-Item -Path $MSPLogs -ItemType Directory -Force | Out-Null }
|
{ New-Item -Path $MSPLogs -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||||
|
|
||||||
## Function to log activity to the configured log directory
|
## Function to log activity to the configured log directory
|
||||||
Function Log
|
Function Log
|
||||||
{
|
{
|
||||||
param([string]$Message,[string]$LogName)
|
param(
|
||||||
$LogEntry = "{0} - {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message
|
[Parameter(Mandatory=$true)][string]$Message,
|
||||||
|
[Parameter(Mandatory=$false)][switch]$Error,
|
||||||
|
[Parameter(Mandatory=$false)][string]$LogName
|
||||||
|
)
|
||||||
|
If ( $Error ) { $LogEntry = "{0} - Error: {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message }
|
||||||
|
Else { $LogEntry = "{0} - {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message }
|
||||||
If ($LogName )
|
If ($LogName )
|
||||||
{
|
{
|
||||||
$LogFile = "${MSPLogs}\${LogFilePrefix}-${LogName}.log"
|
$LogFile = "${MSPLogs}\${LogFilePrefix}-${LogName}.log"
|
||||||
@@ -50,15 +55,49 @@ If ( $Arguments -eq "null" ) { $Arguments = $null }
|
|||||||
If ( $Name -and $Type )
|
If ( $Name -and $Type )
|
||||||
{
|
{
|
||||||
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
|
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
|
||||||
Write-Output "Retrieving : ${Name}.ps1"
|
Log "Retrieving : ${Name}.ps1"
|
||||||
Try { $Script = (New-Object Net.WebClient).DownloadString($URL) }
|
Try { $Script = (New-Object Net.WebClient).DownloadString($URL) }
|
||||||
Catch { Write-Output $_.Exception.Message }
|
Catch { Log -Message $_.Exception.Message -Error }
|
||||||
Try { $ScriptBlock = [Scriptblock]::Create($Script) }
|
Try { $ScriptBlock = [Scriptblock]::Create($Script) }
|
||||||
Catch { Write-Output $_.Exception.Message }
|
Catch { Log -Message $_.Exception.Message -Error }
|
||||||
Write-Output "Executing: ${Name}.ps1 ${Arguments}"
|
Log "Executing: ${Name}.ps1 ${Arguments}"
|
||||||
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments }
|
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments }
|
||||||
Catch { Write-Output $_.Exception.Message }
|
Catch { Log -Message $_.Exception.Message -Error }
|
||||||
} Else { Write-Output "No script or type was specified" }
|
} Else { Log "No script or type was specified" }
|
||||||
|
}
|
||||||
|
|
||||||
|
## Runs a script local to the endpoint
|
||||||
|
Function Run-LocalInstallScript
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=$true)][string]$Script,
|
||||||
|
[Parameter(Mandatory=$true)][string]$Arguments,
|
||||||
|
[Parameter(Mandatory=$true)][string]$AppName
|
||||||
|
)
|
||||||
|
If ( $AppName -eq "null" ) { $AppName = $false }
|
||||||
|
If ( $Arguments -eq "null" ) { $Arguments = $null }
|
||||||
|
If ( Test-Path "${Script}" )
|
||||||
|
{
|
||||||
|
If ( $AppName )
|
||||||
|
{
|
||||||
|
Log "Checking for running instances of ${AppName}"
|
||||||
|
$RunningInstances = Get-Process | Where { $_.Name -like "${AppName}" }
|
||||||
|
If (! ($RunningInstances) )
|
||||||
|
{
|
||||||
|
Log "Executing: ${Script} ${Arguments}"
|
||||||
|
Try { Start-Process "${Script}" -ArgumentList "{$Arguments}" -Wait }
|
||||||
|
Catch { Log -Message $_.Exception.Message -Error }
|
||||||
|
}
|
||||||
|
Else { Log "${AppName} is currently in use and will not be installed now" }
|
||||||
|
}
|
||||||
|
Else
|
||||||
|
{
|
||||||
|
Log "Executing: ${Script} ${Arguments}"
|
||||||
|
Try { Start-Process "${Script}" -ArgumentList "{$Arguments}" -Wait }
|
||||||
|
Catch { Log -Message $_.Exception.Message -Error }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Else { Log "The specified script does not exist: ${Script}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
## Function to return a Powershell version object from a string
|
## Function to return a Powershell version object from a string
|
||||||
@@ -115,4 +154,4 @@ switch ($PSCmdlet.ParameterSetName)
|
|||||||
'le' { If ( $WindowsBuild -le $le ) { Return $true } Else { Return $false } }
|
'le' { If ( $WindowsBuild -le $le ) { Return $true } Else { Return $false } }
|
||||||
'eq' { If ( $WindowsBuild -eq $eq ) { Return $true } Else { Return $false } }
|
'eq' { If ( $WindowsBuild -eq $eq ) { Return $true } Else { Return $false } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user