Skip to content

Commit 57fdd10

Browse files
committed
ADD - script update checker function, new app EARNFM, script version patch typo fix
1 parent bdd70b6 commit 57fdd10

3 files changed

Lines changed: 66 additions & 14 deletions

File tree

.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313
######################################################################
1414
## PROJECT_VERSION
15-
PROJECT_VERSION=2.5.4
15+
PROJECT_VERSION=2.5.1
1616
## PROJECT NAME
1717
COMPOSE_PROJECT_NAME=money4band
1818
DS_PROJECT_SERVER_URL=https://discord.com/invite/Fq8eeazBAD

runme.ps1

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,45 @@ function fn_fail($text) {
196196
# Function to check if there are any updates available #
197197
function 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

runme.sh

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fi
3737
#read -r -p "Press Enter to continue"
3838

3939
# Script version getting it from ${ENV_FILENAME} file #
40-
readonly SCRIPT_VERSION=$(grep -oP 'PROJECT_VERSION=\K[^#\r]+' ${ENV_FILENAME})
40+
SCRIPT_VERSION=$(grep -oP 'PROJECT_VERSION=\K[^#\r]+' ${ENV_FILENAME})
4141

4242
# Script name #
4343
readonly SCRIPT_NAME=$(basename "$0") # save the script name in a variable not the full path
@@ -197,17 +197,42 @@ fn_fail() {
197197
# Function to check if there are any updates available #
198198
check_project_updates() {
199199
# Get the current script version from the local .env file
200-
SCRIPT_VERSION=$(grep -oP 'PROJECT_VERSION=\K.*' "./\$ENV_FILENAME")
200+
SCRIPT_VERSION=$(grep -oP 'PROJECT_VERSION=\K[^#\r]+' "./${ENV_FILENAME}")
201+
if [[ -z $SCRIPT_VERSION ]]; then
202+
errorprint_and_log "Failed to get the script version from the local .env file."
203+
return 1
204+
fi
201205

202206
# Get the latest script version from the .env.template file on GitHub
203-
LATEST_SCRIPT_VERSION=$(curl -s "$PROJECT_URL/$ENV_TEMPLATE_FILENAME" | grep -oP 'PROJECT_VERSION=\K.*')
207+
LATEST_SCRIPT_VERSION=$(curl -fs "$PROJECT_URL/$ENV_TEMPLATE_FILENAME" | grep -oP 'PROJECT_VERSION=\K[^#\r]+')
208+
if [[ -z $LATEST_SCRIPT_VERSION ]]; then
209+
errorprint_and_log "Failed to get the latest script version from GitHub."
210+
return 1
211+
fi
212+
213+
# Split the versions into major, minor, and patch numbers
214+
IFS='.' read -ra SCRIPT_VERSION_SPLIT <<< "$SCRIPT_VERSION"
215+
IFS='.' read -ra LATEST_SCRIPT_VERSION_SPLIT <<< "$LATEST_SCRIPT_VERSION"
204216

205217
# Compare the versions and print a message if a newer version is available
206-
if [[ "$SCRIPT_VERSION" < "$LATEST_SCRIPT_VERSION" ]]; then
207-
print_and_log "GREEN" "A newer version of the script is available. Please consider updating."
208-
fi
218+
for i in "${!SCRIPT_VERSION_SPLIT[@]}"; do
219+
if (( ${SCRIPT_VERSION_SPLIT[i]} < ${LATEST_SCRIPT_VERSION_SPLIT[i]} )); then
220+
print_and_log "YELLOW" "A newer version of the script is available. Please consider updating."
221+
return 0 # Return here to exit the function as soon as a newer version is found
222+
elif (( ${SCRIPT_VERSION_SPLIT[i]} > ${LATEST_SCRIPT_VERSION_SPLIT[i]} )); then
223+
# If any part of the local version is greater, it's not an older version
224+
return 0
225+
fi
226+
done
227+
228+
# If the loop completes without finding a newer version, you're up to date
229+
print_and_log "BLUE" "Script is up to date."
209230
}
210231

232+
233+
234+
235+
211236
# Function to detect OS
212237
detect_os() {
213238
toLog_ifDebug -l "[DEBUG]" -m "Detecting OS..."

0 commit comments

Comments
 (0)