mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
Auto-Update: pull from github instead of downloading zip-file
Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com> Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
@ -20,27 +20,12 @@ def check(version, repo, native=True):
|
|||||||
'current': version,
|
'current': version,
|
||||||
'available': None,
|
'available': None,
|
||||||
'url': None,
|
'url': None,
|
||||||
'native': native,
|
'native': native
|
||||||
'arch': platform.machine()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = requests.get("https://api.github.com/repos/%s/releases/latest" % repo)
|
resp = requests.get("https://api.github.com/repos/%s/releases/latest" % repo)
|
||||||
latest = resp.json()
|
latest = resp.json()
|
||||||
info['available'] = latest_ver = latest['tag_name'].replace('v', '')
|
info['available'] = latest_ver = latest['tag_name'].replace('v', '')
|
||||||
is_arm = info['arch'].startswith('arm')
|
|
||||||
|
|
||||||
local = version_to_tuple(info['current'])
|
|
||||||
remote = version_to_tuple(latest_ver)
|
|
||||||
if remote > local:
|
|
||||||
if not native:
|
|
||||||
info['url'] = "https://github.com/%s/archive/%s.zip" % (repo, latest['tag_name'])
|
|
||||||
else:
|
|
||||||
# check if this release is compatible with armv8+
|
|
||||||
for asset in latest['assets']:
|
|
||||||
download_url = asset['browser_download_url']
|
|
||||||
if download_url.endswith('.zip'):
|
|
||||||
info['url'] = download_url
|
|
||||||
break
|
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
@ -54,21 +39,17 @@ def make_path_for(name):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def download_and_unzip(name, path, display, update):
|
def pull_github(name, path, display, update):
|
||||||
target = "%s_%s.zip" % (name, update['available'])
|
target = "%s %s" % (name, update['available'])
|
||||||
target_path = os.path.join(path, target)
|
target_path = os.path.join(path, target)
|
||||||
|
|
||||||
logging.info("[update] downloading %s to %s ..." % (update['url'], target_path))
|
logging.info("[update] Pulling %s from Github" % target_path)
|
||||||
display.update(force=True, new_data={'status': 'Downloading %s %s ...' % (name, update['available'])})
|
display.update(force=True, new_data={'status': 'Updating %s %s ...' % (name, update['available'])})
|
||||||
|
|
||||||
os.system('wget -q "%s" -O "%s"' % (update['url'], target_path))
|
os.system('cd %s && git pull' % path)
|
||||||
|
|
||||||
logging.info("[update] extracting %s to %s ..." % (target_path, path))
|
|
||||||
display.update(force=True, new_data={'status': 'Extracting %s %s ...' % (name, update['available'])})
|
|
||||||
|
|
||||||
os.system('unzip "%s" -d "%s"' % (target_path, path))
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
def verify(name, path, source_path, display, update):
|
def verify(name, path, source_path, display, update):
|
||||||
display.update(force=True, new_data={'status': 'Verifying %s %s ...' % (name, update['available'])})
|
display.update(force=True, new_data={'status': 'Verifying %s %s ...' % (name, update['available'])})
|
||||||
|
|
||||||
@ -93,18 +74,18 @@ def verify(name, path, source_path, display, update):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
"""
|
||||||
|
|
||||||
def install(display, update):
|
def install(display, update):
|
||||||
name = update['repo'].split('/')[1]
|
name = update['repo'].split('/')[1]
|
||||||
|
|
||||||
path = make_path_for(name)
|
path = make_path_for(name)
|
||||||
|
|
||||||
download_and_unzip(name, path, display, update)
|
pull_github(name, path, display, update)
|
||||||
|
|
||||||
source_path = os.path.join(path, name)
|
source_path = os.path.join(path, name)
|
||||||
if not verify(name, path, source_path, display, update):
|
# if not verify(name, path, source_path, display, update):
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
logging.info("[update] installing %s ..." % name)
|
logging.info("[update] installing %s ..." % name)
|
||||||
display.update(force=True, new_data={'status': 'Installing %s %s ...' % (name, update['available'])})
|
display.update(force=True, new_data={'status': 'Installing %s %s ...' % (name, update['available'])})
|
||||||
@ -124,6 +105,8 @@ def install(display, update):
|
|||||||
if not os.path.exists(source_path):
|
if not os.path.exists(source_path):
|
||||||
source_path = "%s-%s" % (source_path, update['available'])
|
source_path = "%s-%s" % (source_path, update['available'])
|
||||||
|
|
||||||
|
if "bettercap" or "pwngrid" in source_path:
|
||||||
|
os.system("cd %s && make && make install" % source_path)
|
||||||
# setup.py is going to install data files for us
|
# setup.py is going to install data files for us
|
||||||
os.system("cd %s && pip3 install ." % source_path)
|
os.system("cd %s && pip3 install ." % source_path)
|
||||||
|
|
||||||
@ -189,10 +172,10 @@ class AutoUpdate(plugins.Plugin):
|
|||||||
|
|
||||||
for repo, local_version, is_native, svc_name in to_check:
|
for repo, local_version, is_native, svc_name in to_check:
|
||||||
info = check(local_version, repo, is_native)
|
info = check(local_version, repo, is_native)
|
||||||
if info['url'] is not None:
|
if info['available'] > info['current']:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
"update for %s available (local version is '%s'): %s" % (
|
"update for %s available (local version is '%s'): %s" % (
|
||||||
repo, info['current'], info['url']))
|
repo, info['current'], info['available']))
|
||||||
info['service'] = svc_name
|
info['service'] = svc_name
|
||||||
to_install.append(info)
|
to_install.append(info)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user