commit
ee6c06f306
@ -7,6 +7,7 @@ import platform
|
|||||||
import shutil
|
import shutil
|
||||||
import glob
|
import glob
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
import pwnagotchi
|
import pwnagotchi
|
||||||
import pwnagotchi.plugins as plugins
|
import pwnagotchi.plugins as plugins
|
||||||
@ -150,6 +151,7 @@ class AutoUpdate(plugins.Plugin):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ready = False
|
self.ready = False
|
||||||
self.status = StatusFile('/root/.auto-update')
|
self.status = StatusFile('/root/.auto-update')
|
||||||
|
self.lock = Lock()
|
||||||
|
|
||||||
def on_loaded(self):
|
def on_loaded(self):
|
||||||
if 'interval' not in self.options or ('interval' in self.options and self.options['interval'] is None):
|
if 'interval' not in self.options or ('interval' in self.options and self.options['interval'] is None):
|
||||||
@ -159,60 +161,61 @@ class AutoUpdate(plugins.Plugin):
|
|||||||
logging.info("[update] plugin loaded.")
|
logging.info("[update] plugin loaded.")
|
||||||
|
|
||||||
def on_internet_available(self, agent):
|
def on_internet_available(self, agent):
|
||||||
logging.debug("[update] internet connectivity is available (ready %s)" % self.ready)
|
with self.lock:
|
||||||
|
logging.debug("[update] internet connectivity is available (ready %s)" % self.ready)
|
||||||
|
|
||||||
if not self.ready:
|
if not self.ready:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.status.newer_then_hours(self.options['interval']):
|
if self.status.newer_then_hours(self.options['interval']):
|
||||||
logging.debug("[update] last check happened less than %d hours ago" % self.options['interval'])
|
logging.debug("[update] last check happened less than %d hours ago" % self.options['interval'])
|
||||||
return
|
return
|
||||||
|
|
||||||
logging.info("[update] checking for updates ...")
|
logging.info("[update] checking for updates ...")
|
||||||
|
|
||||||
display = agent.view()
|
display = agent.view()
|
||||||
prev_status = display.get('status')
|
prev_status = display.get('status')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
display.update(force=True, new_data={'status': 'Checking for updates ...'})
|
display.update(force=True, new_data={'status': 'Checking for updates ...'})
|
||||||
|
|
||||||
to_install = []
|
to_install = []
|
||||||
to_check = [
|
to_check = [
|
||||||
('bettercap/bettercap', parse_version('bettercap -version'), True, 'bettercap'),
|
('bettercap/bettercap', parse_version('bettercap -version'), True, 'bettercap'),
|
||||||
('evilsocket/pwngrid', parse_version('pwngrid -version'), True, 'pwngrid-peer'),
|
('evilsocket/pwngrid', parse_version('pwngrid -version'), True, 'pwngrid-peer'),
|
||||||
('evilsocket/pwnagotchi', pwnagotchi.version, False, 'pwnagotchi')
|
('evilsocket/pwnagotchi', pwnagotchi.version, False, 'pwnagotchi')
|
||||||
]
|
]
|
||||||
|
|
||||||
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['url'] is not None:
|
||||||
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['url']))
|
||||||
info['service'] = svc_name
|
info['service'] = svc_name
|
||||||
to_install.append(info)
|
to_install.append(info)
|
||||||
|
|
||||||
num_updates = len(to_install)
|
num_updates = len(to_install)
|
||||||
num_installed = 0
|
num_installed = 0
|
||||||
|
|
||||||
if num_updates > 0:
|
if num_updates > 0:
|
||||||
if self.options['install']:
|
if self.options['install']:
|
||||||
for update in to_install:
|
for update in to_install:
|
||||||
plugins.on('updating')
|
plugins.on('updating')
|
||||||
if install(display, update):
|
if install(display, update):
|
||||||
num_installed += 1
|
num_installed += 1
|
||||||
else:
|
else:
|
||||||
prev_status = '%d new update%c available!' % (num_updates, 's' if num_updates > 1 else '')
|
prev_status = '%d new update%c available!' % (num_updates, 's' if num_updates > 1 else '')
|
||||||
|
|
||||||
logging.info("[update] done")
|
logging.info("[update] done")
|
||||||
|
|
||||||
self.status.update()
|
self.status.update()
|
||||||
|
|
||||||
if num_installed > 0:
|
if num_installed > 0:
|
||||||
display.update(force=True, new_data={'status': 'Rebooting ...'})
|
display.update(force=True, new_data={'status': 'Rebooting ...'})
|
||||||
pwnagotchi.reboot()
|
pwnagotchi.reboot()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("[update] %s" % e)
|
logging.error("[update] %s" % e)
|
||||||
|
|
||||||
display.update(force=True, new_data={'status': prev_status if prev_status is not None else ''})
|
display.update(force=True, new_data={'status': prev_status if prev_status is not None else ''})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user