Skip to content

Commit

Permalink
Install pwnagotchi from local sdist
Browse files Browse the repository at this point in the history
Installing pwnagotchi using the local sdist has a few key benefits:
- We're no longer installing all of the data files twice,
  once in packer and once in the setup.py script.
- The image is built using the code in the current local repo,
  not whatever code is currently pushed to the remote master branch.
  This makes it much easier to create and test custom images.
- Installs pwnagotchi using pip, just like the auto-update plugin does.

Signed-off-by: llamasoft <llamasoft@rm-rf.email>
  • Loading branch information
llamasoft committed Oct 8, 2022
1 parent 2d2ccd8 commit c63cbe0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 116 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PACKER_VERSION := 1.8.3
PWN_HOSTNAME := pwnagotchi
PWN_VERSION := master
PWN_VERSION := $(shell cut -d"'" -f2 < pwnagotchi/_version.py)
PWN_RELEASE := pwnagotchi-raspios-lite-$(PWN_VERSION)

MACHINE_TYPE := $(shell uname -m)
Expand Down Expand Up @@ -43,11 +43,15 @@ $(PACKER):
rm $(PACKER).zip
chmod +x $@

SDIST := dist/pwnagotchi-$(PWN_VERSION).tar.gz
$(SDIST): setup.py pwnagotchi
python3 setup.py sdist

# Building the image requires packer, but don't rebuild the image just because packer updated.
$(PWN_RELEASE).img: | $(PACKER)

# If the packer or ansible files are updated, rebuild the image.
$(PWN_RELEASE).img: builder/pwnagotchi.json builder/pwnagotchi.yml $(shell find builder/data -type f)
$(PWN_RELEASE).img: $(SDIST) builder/pwnagotchi.json builder/pwnagotchi.yml $(shell find builder/data -type f)
sudo $(PACKER) plugins install github.com/solo-io/arm-image
cd builder && sudo $(UNSHARE) $(PACKER) build -var "pwn_hostname=$(PWN_HOSTNAME)" -var "pwn_version=$(PWN_VERSION)" pwnagotchi.json
sudo chown -R $$USER:$$USER builder/output-pwnagotchi
Expand All @@ -65,6 +69,10 @@ $(PWN_RELEASE).zip: $(PWN_RELEASE).img $(PWN_RELEASE).sha256
image: $(PWN_RELEASE).zip

clean:
rm -f $(PACKER)
rm -f $(PWN_RELEASE).*
sudo rm -rf builder/output-pwnagotchi builder/packer_cache
- python3 setup.py clean --all
- rm -rf dist pwnagotchi.egg-info
- rm -f $(PACKER)
- rm -f $(PWN_RELEASE).*
- sudo rm -rf builder/output-pwnagotchi builder/packer_cache


82 changes: 10 additions & 72 deletions builder/pwnagotchi.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,86 +13,24 @@
{
"type": "shell",
"inline": [
"sed -i 's/^\\([^#]\\)/#\\1/g' /etc/ld.so.preload",
"mv /etc/ld.so.preload /etc/ld.so.preload.DISABLED",
"uname -a",
"dpkg-architecture",
"apt-get -y --allow-releaseinfo-change update",
"apt-get install -y ansible"
"mkdir -p /usr/local/src/pwnagotchi"
]
},
{
"type": "file",
"source": "data/usr/bin/pwnlib",
"destination": "/usr/bin/pwnlib"
},
{
"type": "file",
"source": "data/usr/bin/bettercap-launcher",
"destination": "/usr/bin/bettercap-launcher"
},
{
"type": "file",
"source": "data/usr/bin/pwnagotchi-launcher",
"destination": "/usr/bin/pwnagotchi-launcher"
},
{
"type": "file",
"source": "data/usr/bin/monstop",
"destination": "/usr/bin/monstop"
},
{
"type": "file",
"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",
"destination": "/etc/systemd/system/pwngrid-peer.service"
},
{
"type": "file",
"source": "data/etc/systemd/system/pwnagotchi.service",
"destination": "/etc/systemd/system/pwnagotchi.service"
},
{
"type": "file",
"source": "data/etc/systemd/system/bettercap.service",
"destination": "/etc/systemd/system/bettercap.service"
"sources": [
"../dist/pwnagotchi-{{user `pwn_version`}}.tar.gz"
],
"destination": "/usr/local/src/pwnagotchi/"
},
{
"type": "shell",
"inline": [
"chmod +x /usr/bin/*"
"apt-get -y --allow-releaseinfo-change update",
"apt-get install -y --no-install-recommends ansible"
]
},
{
Expand All @@ -104,7 +42,7 @@
{
"type": "shell",
"inline": [
"sed -i 's/^#\\(.+\\)/\\1/g' /etc/ld.so.preload"
"mv /etc/ld.so.preload.DISABLED /etc/ld.so.preload"
]
}
]
Expand Down
55 changes: 16 additions & 39 deletions builder/pwnagotchi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,22 @@
regexp: "#EPD_SIZE=2.0"
line: "EPD_SIZE=2.0"

- name: collect python pip package list
command: "pip3 list"
register: pip_output

- name: set python pip package facts
set_fact:
pip_packages: >
{{ pip_packages | default({}) | combine( { item.split()[0]: item.split()[1] } ) }}
with_items: "{{ pip_output.stdout_lines }}"

- name: acquire python3 pip target
command: "python3 -c 'import sys;print(sys.path.pop())'"
register: pip_target

- name: clone pwnagotchi repository
git:
repo: https://github.com/evilsocket/pwnagotchi.git
dest: /usr/local/src/pwnagotchi
register: pwnagotchigit
# pip v20.3 uses a newer dependency resolver that better handles our unique situation.
# Specifically, it handles mismatches between direct requirements without extras and
# indirect requirements that do want extras (e.g. gym vs stable-baselines->gym[atari]).
- name: Upgrade pip
pip:
name: "pip"
version: ">=20.3"

# We need the --ignore-installed option so that pip simply overwrites/upgrades existing
# packages instead of trying to uninstall them first. While this sounds dangerous,
# this matches the legacy behavior of pip. This is required to prevent pip from trying
# (and failing) to uninstall python packages that were originally installed via apt.
- name: Install pwnagotchi from source archive
pip:
name: /usr/local/src/pwnagotchi/pwnagotchi-{{ pwnagotchi.version }}.tar.gz
extra_args: --verbose --prefer-binary --ignore-installed

- name: create /usr/local/share/pwnagotchi/ folder
file:
Expand All @@ -246,26 +243,6 @@
repo: https://github.com/evilsocket/pwnagotchi-plugins-contrib.git
dest: /usr/local/share/pwnagotchi/availaible-plugins

- name: fetch pwnagotchi version
set_fact:
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:
msg: "{{ pwnagotchi_version }}"

- name: build pwnagotchi wheel
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)

- name: install pwnagotchi wheel and dependencies
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)

- name: download and install pwngrid
unarchive:
src: "{{ packages.pwngrid.url }}"
Expand Down

0 comments on commit c63cbe0

Please sign in to comment.