feat: Add version checking and display
Integrated version checking into `cli_api.py` and `cli.py`
This commit is contained in:
25
core/cli.py
25
core/cli.py
@ -485,6 +485,31 @@ def get_services_status():
|
||||
click.echo('Error: Services status not available.')
|
||||
except Exception as e:
|
||||
click.echo(f'{e}', err=True)
|
||||
|
||||
|
||||
@cli.command('show-version')
|
||||
def show_version():
|
||||
"""Displays the currently installed version of the panel."""
|
||||
try:
|
||||
if version_info := cli_api.show_version():
|
||||
click.echo(version_info)
|
||||
else:
|
||||
click.echo("Error retrieving version")
|
||||
except Exception as e:
|
||||
click.echo(f"An unexpected error occurred: {e}", err=True)
|
||||
|
||||
|
||||
@cli.command('check-version')
|
||||
def check_version():
|
||||
"""Checks if the current version is up-to-date and displays changelog if not."""
|
||||
try:
|
||||
if version_info := cli_api.check_version():
|
||||
click.echo(version_info)
|
||||
else:
|
||||
click.echo("Error retrieving version")
|
||||
except Exception as e:
|
||||
click.echo(f"An unexpected error occurred: {e}", err=True)
|
||||
|
||||
# endregion
|
||||
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@ class Command(Enum):
|
||||
CONFIGURE_WARP = os.path.join(SCRIPT_DIR, 'warp', 'configure.sh')
|
||||
STATUS_WARP = os.path.join(SCRIPT_DIR, 'warp', 'status.sh')
|
||||
SERVICES_STATUS = os.path.join(SCRIPT_DIR, 'services_status.sh')
|
||||
VERSION = os.path.join(SCRIPT_DIR, 'hysteria2', 'version.sh')
|
||||
|
||||
# region Custom Exceptions
|
||||
|
||||
@ -500,5 +501,16 @@ def get_services_status() -> dict[str, bool] | None:
|
||||
'''Gets the status of all project services.'''
|
||||
if res := run_cmd(['bash', Command.SERVICES_STATUS.value]):
|
||||
return json.loads(res)
|
||||
|
||||
|
||||
def show_version() -> str | None:
|
||||
"""Displays the currently installed version of the panel."""
|
||||
return run_cmd(['bash', Command.VERSION.value, 'show-version'])
|
||||
|
||||
|
||||
def check_version() -> str | None:
|
||||
"""Checks if the current version is up-to-date and displays changelog if not."""
|
||||
return run_cmd(['bash', Command.VERSION.value, 'check-version'])
|
||||
|
||||
# endregion
|
||||
# endregion
|
||||
|
||||
57
core/scripts/hysteria2/version.sh
Normal file
57
core/scripts/hysteria2/version.sh
Normal file
@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
source /etc/hysteria/core/scripts/path.sh
|
||||
|
||||
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 $LOCALVERSION)
|
||||
latest_version=$(curl -s $LATESTVERSION)
|
||||
latest_changelog=$(curl -s $LASTESTCHANGE)
|
||||
|
||||
|
||||
if version_greater_equal "$local_version" "$latest_version"; then
|
||||
echo "Panel Version: $local_version"
|
||||
else
|
||||
echo "Panel Version: $local_version"
|
||||
echo "Latest Version: $latest_version"
|
||||
echo "${yellow}$latest_version Version Change Log:"
|
||||
echo "$latest_changelog"
|
||||
fi
|
||||
}
|
||||
|
||||
show_version() {
|
||||
|
||||
local_version=$(cat "$LOCALVERSION")
|
||||
echo "Panel Version: $local_version"
|
||||
|
||||
}
|
||||
|
||||
|
||||
if [ "$1" == "check-version" ]; then
|
||||
check_version
|
||||
elif [ "$1" == "show-version" ]; then
|
||||
show_version
|
||||
else
|
||||
echo "Usage: $0 [check|show]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user