New fixes

This commit is contained in:
2020-09-11 15:05:11 +02:00
parent 426a7a461c
commit 855f82f622
5 changed files with 106 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
# Build 18. Using API 2
# Build 20. Using API 2
param([Int32]$startup=0)
#Write-Host $startup
$srcdir = $PSCommandPath | Split-Path -Parent
@@ -87,18 +87,18 @@ foreach ($CookName in $cooks){
Write-Host "Se salta ya que no esta arrancando/apagandose el equipo..."
continue # Go for next
}
if ($cook.only64bit -eq 1 -and $64bit -eq $false) { # If script is only for 64 bit and system is 32 bit..
if ($cook.only64bit -eq 1 -and $64bit -eq $False) { # If script is only for 64 bit and system is 32 bit..
Write-Host "Se salta ya que es esta receta es solo para 64 bits..."
continue # Go for next
}
if ($cook.only32bit -eq 1 -and $64bit -eq $true) { # If script is only for 32 bit and system is 64 bit..
if ($cook.only32bit -eq 1 -and $64bit -eq $True) { # If script is only for 32 bit and system is 64 bit..
Write-Host "Se salta ya que es esta receta es solo para 32 bits..."
continue # Go for next
}
$err = 0
$exit = 0
$inif = $false
$if = $true
$inif = $False
$if = $True
$filesCopied = New-Object System.Collections.ArrayList # For REPOTOLOCAL, has a list of files copied to delete when finish (Do not store forever in temp)
foreach ($step in $cook.steps){
if ($err -eq 1 -and $noerror -eq 1){$err = 0; $errvar = ""} #If "noerror" is active, do not count errors
@@ -107,7 +107,7 @@ foreach ($CookName in $cooks){
$param = $step[1]
$param2 = $step[2]
Write-Host $step[0] "-" $step[1]
if($inif -eq $true -and $if -eq $false){ # Only can see "ENDIF" if is in IF and is not true
if($inif -eq $True -and $if -eq $False){ # Only can see "ENDIF" if is in IF and is not true
if ($step[0] -ne "ENDIF" -and $step[0] -ne "ELSE"){
Write-Host $step[0] "Not executed, IF not meet"
$step[0] = "" #Disable command
@@ -118,34 +118,44 @@ foreach ($CookName in $cooks){
switch ($step[0].ToUpper()) { #Command
"UNINSTALL" { # Remove program
Get-Package -Name "$param*" -ErrorAction Continue #This will return error if program is not installed, do not see it.
if ($? -eq $true){ #If its True, is that package exists
if ($? -eq $True){ #If its True, is that package exists
Get-Package -Name "$param*" -ErrorVariable errvar | Uninstall-Package -ErrorVariable errvar
if ($? -eq $false){ # If fail then put 1 (When fail, powershell returns False)
if ($? -eq $False){ # If fail then put 1 (When fail, powershell returns False)
$err = 1
}
}
}
"SERV_DISABLE" { # Disable a service
Set-Service $param -StartupType Disabled -Status Stopped -ErrorVariable errvar
if ($? -eq $false){ #If its False, it was a problem
if ($? -eq $False){ #If its False, it was a problem
$err = 1
}
}
"SERV_ENABLE" { # Enable a service
Set-Service $param -StartupType Automatic -Status Running -ErrorVariable errvar
if ($? -eq $false){ #If its False, it was a problem
if ($? -eq $False){ #If its False, it was a problem
$err = 1
}
}
{$_ -in "KILL_PROCESS","KILLPROCESS"} {
$p = Get-Process -Name "$param"
if ($? -eq $true){ # Only do something if exists
if ($? -eq $True){ # Only do something if exists
Stop-Process -InputObject $p -Force -ErrorVariable errvar -ErrorAction Continue
#if ($p.HasExited -eq $false){
# $err = 1
#}
}
}
"CD" { #CHANGE DIR, ITS DANGEROUS. IF PARAM IS EMPTY, GO TO $env:temp
if ($param -eq ""){
Set-Location "$env:temp"
}else{
Set-Location "$param"
}
if ($? -eq $false){ # Location change error
$err = 1
}
}
"CMD" { # Run a cmd command. Note: Runs at high priv.
cmd.exe /c "$param"
if ($LASTEXITCODE -ne 0){ # Error in CMD
@@ -177,15 +187,13 @@ foreach ($CookName in $cooks){
$orig=$parts[0]
$dest=$parts[1]
Copy-Item "$orig" "$dest" -ErrorVariable errvar -Recurse -Force
if ($? -eq $false){ # Error in Copy
if ($? -eq $False){ # Error in Copy
$err = 1
}
}else{ #Doesn't sent right
$err = 1
$errvar = "Param not set right. Exiting..."
}
}
"REMOVE" { # Remove files / folders
Remove-Item "$param" -Recurse -Force -ErrorAction Continue # They not see errors (Because error will be file not found)
@@ -226,12 +234,12 @@ foreach ($CookName in $cooks){
# True -> Exists ; False -> Not exists
}
"IFSOFTWAREINST" { # If with software
$inif = $true #This controls IF start/stop
$inif = $True #This controls IF start/stop
Get-Package -Name "$param*" -ErrorAction SilentlyContinue #This will return error if program is not installed, do not see it.
$if=$? # True -> Exists ; False -> Not exists
}
"IFSOFTWAREVER" { # If with software
$inif = $true #This controls IF start/stop
$inif = $True #This controls IF start/stop
$parts = $param.Split(";")
if ($parts[1] -ne ""){ #Exists uri and filename
$p_name = $parts[0]
@@ -244,27 +252,29 @@ foreach ($CookName in $cooks){
}
}
"IFPATHEXISTS" { # If only if a path exists (File, Folder, Registry Key..)
$inif = $true #This controls IF start/stop
$inif = $True #This controls IF start/stop
Test-Path $param -PathType Any -ErrorAction SilentlyContinue
$if=$?
}
"IFPWCMD" { # If with powershell command
$inif = $true #This controls IF start/stop
$inif = $True #This controls IF start/stop
Invoke-Expression $param #Executes powershell command
$if=$? # True -> Exists ; False -> Not exists
}
"IF64BIT" { # If 64 bit computer
$inif = $True
$if = $64bit # Its true if 64 bit computer
}
"IF32BIT" { # If 32 bit computer
$inif = $True
$if = !$64bit # Its true if 32 bit computer, flipped boolean
}
"ELSE" { # Turn bool $if
$if = !$if
}
"ENDIF"{ # End the if
$inif = $false
$if = $true
$inif = $False
$if = $True
}
"DOWNLOAD" { #Download a file. This is a bit problematic one, will use ; to separate download and filename, and its forced to use it..
$parts = $param.Split(";")
@@ -290,7 +300,9 @@ foreach ($CookName in $cooks){
$exit = 1
}
}
Default {}
Default { ##DEFAULT, SAY COMMAND NOT VALID
Write-Host "Command not valid."
}
}
}
# Send results
@@ -306,6 +318,8 @@ foreach ($CookName in $cooks){
}
Invoke-RestMethod -Method Post -Uri "$server/set/cookstatus?ComputerName=$computerName&UUID=$UUID&CookName=$CookName&Revision=$CookRevision&Error=$err&ErrorDesc=$errvar" | out-null
#Return to $env:temp
Set-Location "$env:temp"
#Delete files copied to temp for saving space
foreach ($element in $filesCopied) {
Remove-Item "$env:temp\$element" -ErrorAction SilentlyContinue -Recurse -Force