Skip to content

Commit

Permalink
ADD - script update checker function, new app EARNFM, script version …
Browse files Browse the repository at this point in the history
…patch typo fix
  • Loading branch information
MRColorR committed Oct 26, 2023
1 parent bdd70b6 commit 57fdd10
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
######################################################################
## PROJECT_VERSION
PROJECT_VERSION=2.5.4
PROJECT_VERSION=2.5.1
## PROJECT NAME
COMPOSE_PROJECT_NAME=money4band
DS_PROJECT_SERVER_URL=https://discord.com/invite/Fq8eeazBAD
Expand Down
41 changes: 34 additions & 7 deletions runme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,45 @@ function fn_fail($text) {
# Function to check if there are any updates available #
function check_project_updates {
# Get the current script version from the local .env file
$SCRIPT_VERSION = (Get-Content .\$ENV_FILENAME | Select-String -Pattern "PROJECT_VERSION=" -SimpleMatch).ToString().Split("=")[1]
$SCRIPT_VERSION_MATCH = (Get-Content .\$ENV_FILENAME | Select-String -Pattern "PROJECT_VERSION=(\d+\.\d+\.\d+)").Matches
if ($SCRIPT_VERSION_MATCH.Count -eq 0) {
errorprint_and_log "Failed to get the script version from the local .env file."
return
}
$SCRIPT_VERSION = $SCRIPT_VERSION_MATCH[0].Groups[1].Value

# Get the latest script version from the .env.template file on GitHub
$webClient = New-Object System.Net.WebClient
$templateContent = $webClient.DownloadString("$PROJECT_URL/$ENV_TEMPLATE_FILENAME")
$LATEST_SCRIPT_VERSION = ($templateContent | Select-String -Pattern "PROJECT_VERSION=" -SimpleMatch).ToString().Split("=")[1]
try {
$webClient = New-Object System.Net.WebClient
$templateContent = $webClient.DownloadString("$PROJECT_URL/$ENV_TEMPLATE_FILENAME")
$LATEST_SCRIPT_VERSION_MATCH = ($templateContent | Select-String -Pattern "PROJECT_VERSION=(\d+\.\d+\.\d+)").Matches
if ($LATEST_SCRIPT_VERSION_MATCH.Count -eq 0) {
errorprint_and_log "Failed to get the latest script version from GitHub."
return
}
$LATEST_SCRIPT_VERSION = $LATEST_SCRIPT_VERSION_MATCH[0].Groups[1].Value
} catch {
errorprint_and_log "Failed to fetch the .env.template file from GitHub: $_"
return
}

# Split the versions into major, minor, and patch numbers
$SCRIPT_VERSION_SPLIT = $SCRIPT_VERSION.Split(".")
$LATEST_SCRIPT_VERSION_SPLIT = $LATEST_SCRIPT_VERSION.Split(".")

# Compare the versions and print a message if a newer version is available
if ($SCRIPT_VERSION -lt $LATEST_SCRIPT_VERSION) {
print_and_log "GREEN" "A newer version of the script is available. Please consider updating."
for ($i=0; $i -lt 3; $i++) {
if ([int]$SCRIPT_VERSION_SPLIT[$i] -lt [int]$LATEST_SCRIPT_VERSION_SPLIT[$i]) {
print_and_log "Yellow" "A newer version of the script is available. Please consider updating."
return
}
elseif ([int]$SCRIPT_VERSION_SPLIT[$i] -gt [int]$LATEST_SCRIPT_VERSION_SPLIT[$i]) {
return
}
}
Read-Host -Prompt "Press Enter to continue"

# If the loop completes without finding a newer version, print a message indicating that the script is up to date
print_and_log "BLUE" "Script is up to date."
}

# Function to detect OS
Expand Down
37 changes: 31 additions & 6 deletions runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fi
#read -r -p "Press Enter to continue"

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

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

# Get the latest script version from the .env.template file on GitHub
LATEST_SCRIPT_VERSION=$(curl -s "$PROJECT_URL/$ENV_TEMPLATE_FILENAME" | grep -oP 'PROJECT_VERSION=\K.*')
LATEST_SCRIPT_VERSION=$(curl -fs "$PROJECT_URL/$ENV_TEMPLATE_FILENAME" | grep -oP 'PROJECT_VERSION=\K[^#\r]+')
if [[ -z $LATEST_SCRIPT_VERSION ]]; then
errorprint_and_log "Failed to get the latest script version from GitHub."
return 1
fi

# Split the versions into major, minor, and patch numbers
IFS='.' read -ra SCRIPT_VERSION_SPLIT <<< "$SCRIPT_VERSION"
IFS='.' read -ra LATEST_SCRIPT_VERSION_SPLIT <<< "$LATEST_SCRIPT_VERSION"

# Compare the versions and print a message if a newer version is available
if [[ "$SCRIPT_VERSION" < "$LATEST_SCRIPT_VERSION" ]]; then
print_and_log "GREEN" "A newer version of the script is available. Please consider updating."
fi
for i in "${!SCRIPT_VERSION_SPLIT[@]}"; do
if (( ${SCRIPT_VERSION_SPLIT[i]} < ${LATEST_SCRIPT_VERSION_SPLIT[i]} )); then
print_and_log "YELLOW" "A newer version of the script is available. Please consider updating."
return 0 # Return here to exit the function as soon as a newer version is found
elif (( ${SCRIPT_VERSION_SPLIT[i]} > ${LATEST_SCRIPT_VERSION_SPLIT[i]} )); then
# If any part of the local version is greater, it's not an older version
return 0
fi
done

# If the loop completes without finding a newer version, you're up to date
print_and_log "BLUE" "Script is up to date."
}





# Function to detect OS
detect_os() {
toLog_ifDebug -l "[DEBUG]" -m "Detecting OS..."
Expand Down

0 comments on commit 57fdd10

Please sign in to comment.