From afc36369392928ad5dac63c5bac33797b589be8e Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Thu, 16 Jan 2020 18:52:40 +0100 Subject: [PATCH 1/3] fix version parsing --- bin/pwnagotchi | 2 +- builder/pwnagotchi.yml | 2 +- pwnagotchi/__init__.py | 2 +- pwnagotchi/_version.py | 1 + pwnagotchi/agent.py | 2 +- pwnagotchi/grid.py | 2 +- pwnagotchi/mesh/utils.py | 2 +- pwnagotchi/plugins/default/auto-update.py | 2 +- pwnagotchi/ui/view.py | 2 +- setup.py | 16 ++++++++++++++-- 10 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 pwnagotchi/_version.py diff --git a/bin/pwnagotchi b/bin/pwnagotchi index a30fceac..f59e467b 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -115,7 +115,7 @@ if __name__ == '__main__': args = parser.parse_args() if args.version: - print(pwnagotchi.version) + print(pwnagotchi.__version__) sys.exit(0) config = utils.load_config(args) diff --git a/builder/pwnagotchi.yml b/builder/pwnagotchi.yml index be48177b..d4b0e62c 100644 --- a/builder/pwnagotchi.yml +++ b/builder/pwnagotchi.yml @@ -218,7 +218,7 @@ - name: fetch pwnagotchi version set_fact: - pwnagotchi_version: "{{ lookup('file', '/usr/local/src/pwnagotchi/pwnagotchi/__init__.py') | replace('\n', ' ') | regex_replace('.*version.*=.*''([0-9]+\\.[0-9]+\\.[0-9]+[A-Za-z0-9]*)''.*', '\\1') }}" + pwnagotchi_version: "{{ lookup('file', '/usr/local/src/pwnagotchi/pwnagotchi/_version.py') | regex_replace('.*__version__.*=.*''([0-9]+\\.[0-9]+\\.[0-9]+[A-Za-z0-9]*)''.*', '\\1') }}" - name: pwnagotchi version found debug: diff --git a/pwnagotchi/__init__.py b/pwnagotchi/__init__.py index 89fe3fee..211fa507 100644 --- a/pwnagotchi/__init__.py +++ b/pwnagotchi/__init__.py @@ -6,7 +6,7 @@ import re import pwnagotchi.ui.view as view import pwnagotchi -version = '1.4.3' +from _version import __version__ _name = None diff --git a/pwnagotchi/_version.py b/pwnagotchi/_version.py new file mode 100644 index 00000000..4e7c72a5 --- /dev/null +++ b/pwnagotchi/_version.py @@ -0,0 +1 @@ +__version__ = '1.4.3' diff --git a/pwnagotchi/agent.py b/pwnagotchi/agent.py index bfaf1db4..71223a49 100644 --- a/pwnagotchi/agent.py +++ b/pwnagotchi/agent.py @@ -49,7 +49,7 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer): if not os.path.exists(config['bettercap']['handshakes']): os.makedirs(config['bettercap']['handshakes']) - logging.info("%s@%s (v%s)", pwnagotchi.name(), self.fingerprint(), pwnagotchi.version) + logging.info("%s@%s (v%s)", pwnagotchi.name(), self.fingerprint(), pwnagotchi.__version__) for _, plugin in plugins.loaded.items(): logging.debug("plugin '%s' v%s", plugin.__class__.__name__, plugin.__version__) diff --git a/pwnagotchi/grid.py b/pwnagotchi/grid.py index 0cac9de6..a76c269d 100644 --- a/pwnagotchi/grid.py +++ b/pwnagotchi/grid.py @@ -85,7 +85,7 @@ def update_data(last_session): }, 'uname': subprocess.getoutput("uname -a"), 'brain': brain, - 'version': pwnagotchi.version + 'version': pwnagotchi.__version__ } logging.debug("updating grid data: %s" % data) diff --git a/pwnagotchi/mesh/utils.py b/pwnagotchi/mesh/utils.py index ca0cc0ae..c46bae5d 100644 --- a/pwnagotchi/mesh/utils.py +++ b/pwnagotchi/mesh/utils.py @@ -17,7 +17,7 @@ class AsyncAdvertiser(object): self._keypair = keypair self._advertisement = { 'name': pwnagotchi.name(), - 'version': pwnagotchi.version, + 'version': pwnagotchi.__version__, 'identity': self._keypair.fingerprint, 'face': faces.FRIEND, 'pwnd_run': 0, diff --git a/pwnagotchi/plugins/default/auto-update.py b/pwnagotchi/plugins/default/auto-update.py index 8a0db9e3..5f996c46 100644 --- a/pwnagotchi/plugins/default/auto-update.py +++ b/pwnagotchi/plugins/default/auto-update.py @@ -183,7 +183,7 @@ class AutoUpdate(plugins.Plugin): to_check = [ ('bettercap/bettercap', parse_version('bettercap -version'), True, 'bettercap'), ('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: diff --git a/pwnagotchi/ui/view.py b/pwnagotchi/ui/view.py index e2207afa..031ed8e1 100644 --- a/pwnagotchi/ui/view.py +++ b/pwnagotchi/ui/view.py @@ -136,7 +136,7 @@ class View(object): return self._state.get(key) def on_starting(self): - self.set('status', self._voice.on_starting() + ("\n(v%s)" % pwnagotchi.version)) + self.set('status', self._voice.on_starting() + ("\n(v%s)" % pwnagotchi.__version__)) self.set('face', faces.AWAKE) def on_ai_ready(self): diff --git a/setup.py b/setup.py index 7abebe83..89de8782 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ from setuptools import setup, find_packages import os import glob import shutil +import re def install_file(source_filename, dest_filename): @@ -42,16 +43,27 @@ def installer(): # for people updating https://github.com/evilsocket/pwnagotchi/pull/551/files os.system("systemctl enable fstrim.timer") +def version(version_file): + with open(version_file, 'rt') as vf: + version_file_content = vf.read() + + version_match = re.search(r"__version__\s*=\s*[\"\']([^\"\']+)", version_file_content) + if version_match: + return version_match.groups()[0] + + return None + installer() with open('requirements.txt') as fp: required = [line.strip() for line in fp if line.strip() != ""] -import pwnagotchi +VERSION_FILE = 'pwnagotchi/_version.py' +pwnagotchi_version = version(VERSION_FILE) setup(name='pwnagotchi', - version=pwnagotchi.version, + version=pwnagotchi_version, description='(⌐■_■) - Deep Reinforcement Learning instrumenting bettercap for WiFI pwning.', author='evilsocket && the dev team', author_email='evilsocket@gmail.com', From 5ccd65e46eb4ddbb901e6b73758e2a75a51a7774 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Thu, 16 Jan 2020 19:19:58 +0100 Subject: [PATCH 2/3] fix typo --- builder/pwnagotchi.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/pwnagotchi.yml b/builder/pwnagotchi.yml index d4b0e62c..2e79f5cf 100644 --- a/builder/pwnagotchi.yml +++ b/builder/pwnagotchi.yml @@ -228,7 +228,7 @@ command: "python3 setup.py sdist bdist_wheel" args: chdir: /usr/local/src/pwnagotchi - when: (pwnagotchigit.changed) or (pip_packages['pwnagotchi'] is undefined) or (pip_packages['pwnagotchi'] != pwnagotchi.version) + when: (pwnagotchigit.changed) or (pip_packages['pwnagotchi'] is undefined) or (pip_packages['pwnagotchi'] != pwnagotchi_version) - name: install opencv-python pip: @@ -246,7 +246,7 @@ pip: name: "{{ lookup('fileglob', '/usr/local/src/pwnagotchi/dist/pwnagotchi*.whl') }}" extra_args: "--no-cache-dir" - when: (pwnagotchigit.changed) or (pip_packages['pwnagotchi'] is undefined) or (pip_packages['pwnagotchi'] != pwnagotchi.version) + when: (pwnagotchigit.changed) or (pip_packages['pwnagotchi'] is undefined) or (pip_packages['pwnagotchi'] != pwnagotchi_version) - name: download and install pwngrid unarchive: From cdc0e0fa3e4d793fdeb06e5f7cac4f1b6527da89 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Thu, 16 Jan 2020 19:25:58 +0100 Subject: [PATCH 3/3] adjust release script --- scripts/release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index fafb08f5..abe406d2 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,7 +1,7 @@ #!/bin/bash # nothing to see here, just a utility i use to create new releases ^_^ -VERSION_FILE=$(dirname "${BASH_SOURCE[0]}")/../pwnagotchi/__init__.py +VERSION_FILE=$(dirname "${BASH_SOURCE[0]}")/../pwnagotchi/_version.py echo "version file is $VERSION_FILE" CURRENT_VERSION=$(cat $VERSION_FILE | grep version | cut -d"'" -f2) TO_UPDATE=( @@ -25,4 +25,4 @@ git tag -a v$NEW_VERSION -m "release v$NEW_VERSION" git push origin v$NEW_VERSION echo -echo "All done, v$NEW_VERSION released ^_^" \ No newline at end of file +echo "All done, v$NEW_VERSION released ^_^"