From 783ac615941d4ec155dde384ff1fe9a640fe1480 Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Thu, 31 Oct 2019 12:48:15 +0100 Subject: [PATCH] fix: the auto-update plugin now also installs launchers and service files via setup.py (closes #470) --- .../data/etc/network/interfaces.d/eth0-cfg | 2 + builder/data/etc/network/interfaces.d/lo-cfg | 2 + .../data/etc/network/interfaces.d/usb0-cfg | 7 +++ .../data/etc/network/interfaces.d/wlan0-cfg | 2 + builder/data/usr/bin/hdmioff | 2 + builder/data/usr/bin/hdmion | 2 + builder/pwnagotchi.json | 30 ++++++++++++ builder/pwnagotchi.yml | 49 ------------------- pwnagotchi/plugins/default/auto-update.py | 13 +---- setup.py | 26 +++++++++- 10 files changed, 73 insertions(+), 62 deletions(-) create mode 100644 builder/data/etc/network/interfaces.d/eth0-cfg create mode 100644 builder/data/etc/network/interfaces.d/lo-cfg create mode 100644 builder/data/etc/network/interfaces.d/usb0-cfg create mode 100644 builder/data/etc/network/interfaces.d/wlan0-cfg create mode 100755 builder/data/usr/bin/hdmioff create mode 100755 builder/data/usr/bin/hdmion diff --git a/builder/data/etc/network/interfaces.d/eth0-cfg b/builder/data/etc/network/interfaces.d/eth0-cfg new file mode 100644 index 0000000..2166051 --- /dev/null +++ b/builder/data/etc/network/interfaces.d/eth0-cfg @@ -0,0 +1,2 @@ +allow-hotplug eth0 +iface eth0 inet dhcp \ No newline at end of file diff --git a/builder/data/etc/network/interfaces.d/lo-cfg b/builder/data/etc/network/interfaces.d/lo-cfg new file mode 100644 index 0000000..18ff476 --- /dev/null +++ b/builder/data/etc/network/interfaces.d/lo-cfg @@ -0,0 +1,2 @@ +auto lo +iface lo inet loopback \ No newline at end of file diff --git a/builder/data/etc/network/interfaces.d/usb0-cfg b/builder/data/etc/network/interfaces.d/usb0-cfg new file mode 100644 index 0000000..445ed90 --- /dev/null +++ b/builder/data/etc/network/interfaces.d/usb0-cfg @@ -0,0 +1,7 @@ +allow-hotplug usb0 +iface usb0 inet static + address 10.0.0.2 + netmask 255.255.255.0 + network 10.0.0.0 + broadcast 10.0.0.255 + gateway 10.0.0.1 \ No newline at end of file diff --git a/builder/data/etc/network/interfaces.d/wlan0-cfg b/builder/data/etc/network/interfaces.d/wlan0-cfg new file mode 100644 index 0000000..f542569 --- /dev/null +++ b/builder/data/etc/network/interfaces.d/wlan0-cfg @@ -0,0 +1,2 @@ +allow-hotplug wlan0 +iface wlan0 inet static \ No newline at end of file diff --git a/builder/data/usr/bin/hdmioff b/builder/data/usr/bin/hdmioff new file mode 100755 index 0000000..8f272bf --- /dev/null +++ b/builder/data/usr/bin/hdmioff @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +sudo /opt/vc/bin/tvservice -o \ No newline at end of file diff --git a/builder/data/usr/bin/hdmion b/builder/data/usr/bin/hdmion new file mode 100755 index 0000000..3bd2188 --- /dev/null +++ b/builder/data/usr/bin/hdmion @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +sudo /opt/vc/bin/tvservice -p \ No newline at end of file diff --git a/builder/pwnagotchi.json b/builder/pwnagotchi.json index 7698f0b..56daeaf 100644 --- a/builder/pwnagotchi.json +++ b/builder/pwnagotchi.json @@ -44,6 +44,36 @@ "source": "data/usr/bin/monstart", "destination": "/usr/bin/monstart" }, + { + "type": "file", + "source": "data/usr/bin/hdmion", + "destination": "/usr/bin/hdmion" + }, + { + "type": "file", + "source": "data/usr/bin/hdmioff", + "destination": "/usr/bin/hdmioff" + }, + { + "type": "file", + "source": "data/etc/network/interfaces.d/lo-cfg", + "destination": "/etc/network/interfaces.d/lo-cfg" + }, + { + "type": "file", + "source": "data/etc/network/interfaces.d/wlan0-cfg", + "destination": "/etc/network/interfaces.d/wlan0-cfg" + }, + { + "type": "file", + "source": "data/etc/network/interfaces.d/usb0-cfg", + "destination": "/etc/network/interfaces.d/usb0-cfg" + }, + { + "type": "file", + "source": "data/etc/network/interfaces.d/eth0-cfg", + "destination": "/etc/network/interfaces.d/eth0-cfg" + }, { "type": "file", "source": "data/etc/systemd/system/pwngrid-peer.service", diff --git a/builder/pwnagotchi.yml b/builder/pwnagotchi.yml index 10fda9a..0164502 100644 --- a/builder/pwnagotchi.yml +++ b/builder/pwnagotchi.yml @@ -280,22 +280,6 @@ remote_src: yes mode: 0755 - - name: create hdmion script - copy: - dest: /usr/bin/hdmion - mode: 0755 - content: | - #!/usr/bin/env bash - sudo /opt/vc/bin/tvservice -p - - - name: create hdmioff script - copy: - dest: /usr/bin/hdmioff - mode: 0755 - content: | - #!/usr/bin/env bash - sudo /opt/vc/bin/tvservice -o - - name: add HDMI powersave to rc.local blockinfile: path: /etc/rc.local @@ -329,39 +313,6 @@ # when: not user_config.stat.exists - - name: configure lo interface - copy: - dest: /etc/network/interfaces.d/lo-cfg - content: | - auto lo - iface lo inet loopback - - - name: configure wlan interface - copy: - dest: /etc/network/interfaces.d/wlan0-cfg - content: | - allow-hotplug wlan0 - iface wlan0 inet static - - - name: configure usb interface - copy: - dest: /etc/network/interfaces.d/usb0-cfg - content: | - allow-hotplug usb0 - iface usb0 inet static - address 10.0.0.2 - netmask 255.255.255.0 - network 10.0.0.0 - broadcast 10.0.0.255 - gateway 10.0.0.1 - - - name: configure eth0 interface (pi2/3/4) - copy: - dest: /etc/network/interfaces.d/eth0-cfg - content: | - allow-hotplug eth0 - iface eth0 inet dhcp - - name: enable ssh on boot file: path: /boot/ssh diff --git a/pwnagotchi/plugins/default/auto-update.py b/pwnagotchi/plugins/default/auto-update.py index ba7f55c..3365490 100644 --- a/pwnagotchi/plugins/default/auto-update.py +++ b/pwnagotchi/plugins/default/auto-update.py @@ -143,20 +143,9 @@ def install(display, update): if not os.path.exists(source_path): source_path = "%s-%s" % (source_path, update['available']) + # setup.py is going to install data files for us os.system("cd %s && pip3 install ." % source_path) - data_path = os.path.join(source_path, "builder/data") - for source in glob.glob("%s/**" % data_path, recursive=True): - if os.path.isfile(source): - dest = source.replace(data_path, '') - dest_path = os.path.dirname(dest) - if not os.path.isdir(dest_path): - os.makedirs(dest_path) - logging.info("[update] installing %s to %s ..." % (source, dest)) - os.system("mv '%s' '%s'" % (source, dest)) - - os.system("systemctl daemon-reload") - return True diff --git a/setup.py b/setup.py index dab1f93..fe58a73 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,29 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- from setuptools import setup, find_packages -import pwnagotchi +import os +import glob +import shutil + +setup_path = os.path.dirname(__file__) +data_path = os.path.join(setup_path, "builder/data") + +for source_filename in glob.glob("%s/**" % data_path, recursive=True): + if os.path.isfile(source_filename): + dest_filename = source_filename.replace(data_path, '') + dest_folder = os.path.dirname(dest_filename) + + print("installing %s to %s ..." % (source_filename, dest_filename)) + try: + if not os.path.isdir(dest_folder): + os.makedirs(dest_folder) + + shutil.copyfile(source_filename, dest_filename) + except Exception as e: + print("error installing %s: %s" % (source_filename, e)) + +# reload systemd units +os.system("systemctl daemon-reload") required = [] with open('requirements.txt') as fp: @@ -10,6 +32,8 @@ with open('requirements.txt') as fp: if line != "": required.append(line) +import pwnagotchi + setup(name='pwnagotchi', version=pwnagotchi.version, description='(⌐■_■) - Deep Reinforcement Learning instrumenting bettercap for WiFI pwning.',