param ( [string]$App_Path = "C:\Users\matthes01\Documents\lst", # with this it makes it optional to pass a new parameter over. [string]$Server = "usmcd1vms036", [string]$Token = "test3", [string]$Remote_Path = "E$\LST" ) # imports of the other functions . ".\update-controller-zip" . ".\update-controller-bumpBuild" . ".\update-controller-server" # example string to pass over, you must be in the script dir when you run this script. or it will fail to find the linked scripts # .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Server "usmcd1vms036" -Token "test3" -Remote_Path "E$\LST" $EnvFile = Join-Path $App_Path ".env" if (-Not (Test-Path $EnvFile)) { Write-Error "File not found: $EnvFile" exit 1 } # Read and parse the .env file into a dictionary $envDict = @{} Get-Content $EnvFile | ForEach-Object { if ($_ -match "^\s*#") { return } # skip comments if ([string]::IsNullOrWhiteSpace($_)) { return } # skip blank lines $parts = $_ -split '=', 2 if ($parts.Count -eq 2) { $envDict[$parts[0].Trim()] = $parts[1].Trim() } } # Read the .env file and set each key as a variable Get-Content $EnvFile | ForEach-Object { if ($_ -match "^\s*#") { return } # skip comments if ([string]::IsNullOrWhiteSpace($_)) { return } # skip blank lines $parts = $_ -split '=', 2 if ($parts.Count -eq 2) { $key = $parts[0].Trim() $value = $parts[1].Trim() # Set as PowerShell variable Set-Variable -Name $key -Value $value -Scope Global } } # create the new zip build. # --------------------------------------------------------------------------------- #check it file is there $BuildNumber = "1" $buildfile = Join-Path $App_Path ".controller-build" if (-Not (Test-Path $buildfile)) { Write-Error "File not found: $buildfile, creating it." New-Item -Path $buildfile -ItemType File | Out-Null $BuildNumber = "1" Set-Content -Path $BuildFile -Value $BuildNumber } else { $content = Get-Content $BuildFile -Raw if (![string]::IsNullOrWhiteSpace($content)) { $BuildNumber = $content.Trim() } } # do the same check on the .includeControls file $ControlIncludes = Join-Path $App_Path ".includeControls" if (-Not (Test-Path $ControlIncludes)) { Write-Error "File not found: $ControlIncludes, exiting as we dont want to zip up the entire app." exit 1 } # last one to make sure we have is the build folder $BuildFolder = Join-Path $App_Path "controllerBuilds" if (-Not (Test-Path $BuildFolder)) { write-host "Build folder missing creating it" New-Item -Path $BuildFolder -ItemType Directory | Out-Null } # now we can create the zip Zip-Includes -IncludesFile $ControlIncludes -BuildNumber $BuildNumber -BuildFolder $BuildFolder -AppRoot $App_Path Start-Sleep -Seconds 3 #------------------------------------------------------------------------------------ # Checking to make sure the server is up and online Write-Output "Checking if $($Token) is online to update." $pingResult = Test-Connection -ComputerName $Server -Count 2 -Quiet if (-not $pingResult) { Write-Output "Server $($Server), token $($Token) is NOT reachable. Exiting script." exit 1 # Terminate the script with a non-zero exit code } Write-Output "Server $($Server), token $($Token) is online." # now that the server is up lets update the server with the current build # do the update to the plant. Update-Server -ADM_USER $ADM_USER -ADM_PASS $ADM_PASS -AppRoot $App_Path -Destination $Remote_Path -Server $Server -Token $Token # bump the build number $BuildNumber = Bump-Build -AppRoot $App_Path # function to create the zip controller-1.zip