Skip to content

Commit

Permalink
Release 1.0.1
Browse files Browse the repository at this point in the history
fix(check-update): Fixed check_update function
  • Loading branch information
jordantrizz committed Jun 15, 2023
1 parent 66fd8c6 commit 658e2a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
26 changes: 12 additions & 14 deletions lib/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,31 @@ _checkroot () {

# -- check_for_updates
help_cmd[check-update]="Check for updates to wpst"
function tool_check-update () {
local script_name="$1"
local github_url="$2"

function wpst_check_update () {
# Get the local version from the VERSION file
local local_version
local LOCAL_VERSION
if [[ -f "VERSION" ]]; then
local_version=$(cat "VERSION")
LOCAL_VERSION=$(cat "VERSION")
else
echo "ERROR: VERSION file not found."
return 1
fi

# Get the remote version from GitHub
local remote_version
remote_version=$(curl -sSL "$github_url/VERSION")
if [[ -z "$remote_version" ]]; then
local REMOTE_VERSION
REMOTE_VERSION=$(curl -sSL "$GITHUB_URL/VERSION")
if [[ -z "$REMOTE_VERSION" ]]; then
echo "ERROR: Failed to retrieve remote version from GitHub."
return 1
fi

# Compare local and remote versions
if [[ "$local_version" == "$remote_version" ]]; then
echo "Your script ($script_name) is up to date."
if [[ "$LOCAL_VERSION" == "$REMOTE_VERSION" ]]; then
echo "Up to date. Local:$LOCAL_VERSION - Latest: $REMOTE_VERSION"
# Check if local version is higher than remote version
elif [[ "$LOCAL_VERSION" > "$REMOTE_VERSION" ]]; then
echo "Local version ($LOCAL_VERSION) is higher than latest version ($REMOTE_VERSION)."
else
echo "Your script ($script_name) is out of date."
echo "Local version: $local_version"
echo "Remote version: $remote_version"
echo "Out of date. Local:$LOCAL_VERSION - Latest: $REMOTE_VERSION"
fi
}
5 changes: 3 additions & 2 deletions wpst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
SCRIPT_DIR="$( dirname "${BASH_SOURCE[0]}" )"
WPST_VERSION="$(cat ${SCRIPT_DIR}/VERSION)"
SCRIPT_NAME="wpst"
GITHUB_URL="https://raw.githubusercontent.com/managingwp/wp-shelltools/main/"

source $SCRIPT_DIR/lib/functions.sh # Core Functions
source $SCRIPT_DIR/lib/functions-gp.sh # GP Functions
Expand Down Expand Up @@ -77,8 +78,8 @@ elif [[ $ACTION = "ajaxlog" ]]; then

elif [[ $ACTION = gp-* ]]; then
cmd_$@
elif [[ $ACTION = "check-updates" ]]; then
wpst_check_updates
elif [[ $ACTION = "check-update" ]]; then
wpst_check_update
else
usage
exit 1
Expand Down

0 comments on commit 658e2a0

Please sign in to comment.