@@ -196,18 +196,45 @@ function fn_fail($text) {
196196# Function to check if there are any updates available #
197197function check_project_updates {
198198 # Get the current script version from the local .env file
199- $SCRIPT_VERSION = (Get-Content .\$ENV_FILENAME | Select-String - Pattern " PROJECT_VERSION=" - SimpleMatch).ToString().Split(" =" )[1 ]
199+ $SCRIPT_VERSION_MATCH = (Get-Content .\$ENV_FILENAME | Select-String - Pattern " PROJECT_VERSION=(\d+\.\d+\.\d+)" ).Matches
200+ if ($SCRIPT_VERSION_MATCH.Count -eq 0 ) {
201+ errorprint_and_log " Failed to get the script version from the local .env file."
202+ return
203+ }
204+ $SCRIPT_VERSION = $SCRIPT_VERSION_MATCH [0 ].Groups[1 ].Value
200205
201206 # Get the latest script version from the .env.template file on GitHub
202- $webClient = New-Object System.Net.WebClient
203- $templateContent = $webClient.DownloadString (" $PROJECT_URL /$ENV_TEMPLATE_FILENAME " )
204- $LATEST_SCRIPT_VERSION = ($templateContent | Select-String - Pattern " PROJECT_VERSION=" - SimpleMatch).ToString().Split(" =" )[1 ]
207+ try {
208+ $webClient = New-Object System.Net.WebClient
209+ $templateContent = $webClient.DownloadString (" $PROJECT_URL /$ENV_TEMPLATE_FILENAME " )
210+ $LATEST_SCRIPT_VERSION_MATCH = ($templateContent | Select-String - Pattern " PROJECT_VERSION=(\d+\.\d+\.\d+)" ).Matches
211+ if ($LATEST_SCRIPT_VERSION_MATCH.Count -eq 0 ) {
212+ errorprint_and_log " Failed to get the latest script version from GitHub."
213+ return
214+ }
215+ $LATEST_SCRIPT_VERSION = $LATEST_SCRIPT_VERSION_MATCH [0 ].Groups[1 ].Value
216+ } catch {
217+ errorprint_and_log " Failed to fetch the .env.template file from GitHub: $_ "
218+ return
219+ }
220+
221+ # Split the versions into major, minor, and patch numbers
222+ $SCRIPT_VERSION_SPLIT = $SCRIPT_VERSION.Split (" ." )
223+ $LATEST_SCRIPT_VERSION_SPLIT = $LATEST_SCRIPT_VERSION.Split (" ." )
205224
206225 # Compare the versions and print a message if a newer version is available
207- if ($SCRIPT_VERSION -lt $LATEST_SCRIPT_VERSION ) {
208- print_and_log " GREEN" " A newer version of the script is available. Please consider updating."
226+ for ($i = 0 ; $i -lt 3 ; $i ++ ) {
227+ if ([int ]$SCRIPT_VERSION_SPLIT [$i ] -lt [int ]$LATEST_SCRIPT_VERSION_SPLIT [$i ]) {
228+ print_and_log " Yellow" " A newer version of the script is available. Please consider updating."
229+ return
230+ }
231+ elseif ([int ]$SCRIPT_VERSION_SPLIT [$i ] -gt [int ]$LATEST_SCRIPT_VERSION_SPLIT [$i ]) {
232+ return
233+ }
209234 }
210- Read-Host - Prompt " Press Enter to continue"
235+
236+ # If the loop completes without finding a newer version, print a message indicating that the script is up to date
237+ print_and_log " BLUE" " Script is up to date."
211238}
212239
213240# Function to detect OS
0 commit comments