2025-07-06 21:06:04 +02:00
|
|
|
from modules.volta.main import _
|
2025-06-20 23:48:10 +02:00
|
|
|
from modules.globalvars import *
|
|
|
|
import requests
|
2025-06-21 00:01:33 +02:00
|
|
|
import subprocess
|
2025-06-21 00:14:01 +02:00
|
|
|
import sys
|
2025-06-21 00:01:33 +02:00
|
|
|
|
2025-07-07 01:18:51 +02:00
|
|
|
launched = False
|
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Run a shell command and return its output
|
2025-06-21 00:01:33 +02:00
|
|
|
def run_cmd(cmd):
|
|
|
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
|
|
|
return result.stdout.strip()
|
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Check if the remote branch is ahead of the local branch
|
2025-06-21 00:01:33 +02:00
|
|
|
def is_remote_ahead(branch='main', remote='origin'):
|
|
|
|
run_cmd(f'git fetch {remote}')
|
|
|
|
count = run_cmd(f'git rev-list --count HEAD..{remote}/{branch}')
|
|
|
|
return int(count) > 0
|
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Automatically update the local repository if the remote is ahead
|
2025-06-21 00:01:33 +02:00
|
|
|
def auto_update(branch='main', remote='origin'):
|
2025-07-07 01:18:51 +02:00
|
|
|
if launched == True:
|
|
|
|
return
|
2025-06-29 19:44:56 +02:00
|
|
|
if launched == True:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(_("already_started"))
|
2025-06-29 19:44:56 +02:00
|
|
|
return
|
2025-06-21 00:01:33 +02:00
|
|
|
if AUTOUPDATE != "True":
|
2025-06-22 19:07:41 +02:00
|
|
|
pass # Auto-update is disabled
|
2025-06-21 00:01:33 +02:00
|
|
|
if is_remote_ahead(branch, remote):
|
2025-07-06 21:06:04 +02:00
|
|
|
print(_( "remote_ahead").format(remote=remote, branch=branch))
|
2025-06-21 00:01:33 +02:00
|
|
|
pull_result = run_cmd(f'git pull {remote} {branch}')
|
|
|
|
print(pull_result)
|
2025-07-06 21:06:04 +02:00
|
|
|
print(_( "please_restart"))
|
2025-06-21 00:14:01 +02:00
|
|
|
sys.exit(0)
|
2025-06-21 00:01:33 +02:00
|
|
|
else:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(_( "local_ahead").format(remote=remote, branch=branch))
|
2025-06-20 23:48:10 +02:00
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Fetch the latest version info from the update server
|
2025-06-20 23:48:10 +02:00
|
|
|
def get_latest_version_info():
|
|
|
|
try:
|
|
|
|
response = requests.get(UPDATE_URL, timeout=5)
|
|
|
|
if response.status_code == 200:
|
|
|
|
return response.json()
|
|
|
|
else:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(f"{RED}{_( 'version_error')} {response.status_code}{RESET}")
|
2025-06-20 23:48:10 +02:00
|
|
|
return None
|
|
|
|
except requests.RequestException as e:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(f"{RED}{_( 'version_error')} {e}{RESET}")
|
2025-06-20 23:48:10 +02:00
|
|
|
return None
|
2025-06-22 19:07:41 +02:00
|
|
|
|
|
|
|
# Check if an update is available and perform update if needed
|
2025-06-20 23:48:10 +02:00
|
|
|
def check_for_update():
|
2025-06-21 00:01:33 +02:00
|
|
|
if ALIVEPING != "True":
|
2025-07-06 21:06:04 +02:00
|
|
|
return
|
2025-07-07 01:18:51 +02:00
|
|
|
global latest_version, local_version, launched
|
2025-06-22 19:07:41 +02:00
|
|
|
|
2025-06-20 23:48:10 +02:00
|
|
|
latest_version_info = get_latest_version_info()
|
|
|
|
if not latest_version_info:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(f"{_('fetch_update_fail')}")
|
2025-06-22 19:07:41 +02:00
|
|
|
return None, None
|
2025-06-20 23:48:10 +02:00
|
|
|
|
|
|
|
latest_version = latest_version_info.get("version")
|
|
|
|
os.environ['gooberlatest_version'] = latest_version
|
|
|
|
download_url = latest_version_info.get("download_url")
|
|
|
|
|
|
|
|
if not latest_version or not download_url:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(f"{RED}{_(LOCALE, 'invalid_server')}{RESET}")
|
2025-06-22 19:07:41 +02:00
|
|
|
return None, None
|
2025-06-20 23:48:10 +02:00
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Check if local_version is valid
|
2025-06-20 23:48:10 +02:00
|
|
|
if local_version == "0.0.0" or None:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(f"{RED}{_('cant_find_local_version')}{RESET}")
|
2025-06-20 23:48:10 +02:00
|
|
|
return
|
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Compare local and latest versions
|
2025-06-20 23:48:10 +02:00
|
|
|
if local_version < latest_version:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(f"{YELLOW}{_('new_version').format(latest_version=latest_version, local_version=local_version)}{RESET}")
|
|
|
|
print(f"{YELLOW}{_('changelog').format(VERSION_URL=VERSION_URL)}{RESET}")
|
2025-06-21 00:01:33 +02:00
|
|
|
auto_update()
|
2025-07-06 21:06:04 +02:00
|
|
|
elif local_version > latest_version and beta == True:
|
2025-07-07 00:57:54 +02:00
|
|
|
print(f"{YELLOW}You are running an \"unstable\" version of Goober, do not expect it to work properly.\nVersion {local_version}{RESET}")
|
2025-07-06 21:06:04 +02:00
|
|
|
elif local_version > latest_version:
|
|
|
|
print(f"{YELLOW}{_('modification_warning')}{RESET}")
|
2025-06-20 23:48:10 +02:00
|
|
|
elif local_version == latest_version:
|
2025-07-06 21:06:04 +02:00
|
|
|
print(f"{GREEN}{_('latest_version')} {local_version}{RESET}")
|
|
|
|
print(f"{_('latest_version2').format(VERSION_URL=VERSION_URL)}\n\n")
|
2025-07-07 01:18:51 +02:00
|
|
|
launched = True
|
2025-06-23 13:56:23 +02:00
|
|
|
return latest_version
|