diff --git a/core/scripts/utils.sh b/core/scripts/utils.sh index 3e261d8..377d7ce 100644 --- a/core/scripts/utils.sh +++ b/core/scripts/utils.sh @@ -19,4 +19,36 @@ get_system_info() { IP=$(echo "$IP_API_DATA" | jq -r '.ip') CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4 "%"}') RAM=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }') -} \ No newline at end of file +} + +version_greater_equal() { + IFS='.' read -r -a local_version_parts <<< "$1" + IFS='.' read -r -a latest_version_parts <<< "$2" + + for ((i=0; i<${#local_version_parts[@]}; i++)); do + if [[ -z ${latest_version_parts[i]} ]]; then + latest_version_parts[i]=0 + fi + + if ((10#${local_version_parts[i]} > 10#${latest_version_parts[i]})); then + return 0 + elif ((10#${local_version_parts[i]} < 10#${latest_version_parts[i]})); then + return 1 + fi + done + + return 0 +} + +check_version() { + local_version=$(cat /etc/hysteria/VERSION) + latest_version=$(curl -s https://raw.githubusercontent.com/ReturnFI/Hysteria2/Dev/VERSION) + + if version_greater_equal "$local_version" "$latest_version"; then + echo -e "Panel Version: ${cyan}$local_version${NC}" + else + echo -e "Panel Version: ${cyan}$local_version${NC}" + echo -e "Latest Version: ${cyan}$latest_version${NC}" + echo -e "${red}Please update your panel.${NC}" + fi +}