Skip to content

Commit 3b1d6dc

Browse files
committed
Install pwnagotchi from local sdist
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>
1 parent f6a4dc7 commit 3b1d6dc

3 files changed

Lines changed: 44 additions & 114 deletions

File tree

Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PACKER_VERSION := 1.8.3
22
PWN_HOSTNAME := pwnagotchi
3-
PWN_VERSION := master
3+
PWN_VERSION := $(shell cut -d"'" -f2 < pwnagotchi/_version.py)
44
PWN_RELEASE := pwnagotchi-raspios-lite-$(PWN_VERSION)
55

66
MACHINE_TYPE := $(shell uname -m)
@@ -43,11 +43,15 @@ $(PACKER):
4343
rm $(PACKER).zip
4444
chmod +x $@
4545

46+
SDIST := dist/pwnagotchi-$(PWN_VERSION).tar.gz
47+
$(SDIST): setup.py pwnagotchi
48+
python3 setup.py sdist
49+
4650
# Building the image requires packer, but don't rebuild the image just because packer updated.
4751
$(PWN_RELEASE).img: | $(PACKER)
4852

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

6771
clean:
68-
rm -f $(PACKER)
69-
rm -f $(PWN_RELEASE).*
70-
sudo rm -rf builder/output-pwnagotchi builder/packer_cache
72+
- python3 setup.py clean --all
73+
- rm -rf dist pwnagotchi.egg-info
74+
- rm -f $(PACKER)
75+
- rm -f $(PWN_RELEASE).*
76+
- sudo rm -rf builder/output-pwnagotchi builder/packer_cache
77+
78+

builder/pwnagotchi.json

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,86 +13,24 @@
1313
{
1414
"type": "shell",
1515
"inline": [
16-
"sed -i 's/^\\([^#]\\)/#\\1/g' /etc/ld.so.preload",
16+
"mv /etc/ld.so.preload /etc/ld.so.preload.DISABLED",
17+
"uname -a",
1718
"dpkg-architecture",
18-
"apt-get -y --allow-releaseinfo-change update",
19-
"apt-get install -y ansible"
19+
"mkdir -p /usr/local/src/pwnagotchi"
2020
]
2121
},
2222
{
2323
"type": "file",
24-
"source": "data/usr/bin/pwnlib",
25-
"destination": "/usr/bin/pwnlib"
26-
},
27-
{
28-
"type": "file",
29-
"source": "data/usr/bin/bettercap-launcher",
30-
"destination": "/usr/bin/bettercap-launcher"
31-
},
32-
{
33-
"type": "file",
34-
"source": "data/usr/bin/pwnagotchi-launcher",
35-
"destination": "/usr/bin/pwnagotchi-launcher"
36-
},
37-
{
38-
"type": "file",
39-
"source": "data/usr/bin/monstop",
40-
"destination": "/usr/bin/monstop"
41-
},
42-
{
43-
"type": "file",
44-
"source": "data/usr/bin/monstart",
45-
"destination": "/usr/bin/monstart"
46-
},
47-
{
48-
"type": "file",
49-
"source": "data/usr/bin/hdmion",
50-
"destination": "/usr/bin/hdmion"
51-
},
52-
{
53-
"type": "file",
54-
"source": "data/usr/bin/hdmioff",
55-
"destination": "/usr/bin/hdmioff"
56-
},
57-
{
58-
"type": "file",
59-
"source": "data/etc/network/interfaces.d/lo-cfg",
60-
"destination": "/etc/network/interfaces.d/lo-cfg"
61-
},
62-
{
63-
"type": "file",
64-
"source": "data/etc/network/interfaces.d/wlan0-cfg",
65-
"destination": "/etc/network/interfaces.d/wlan0-cfg"
66-
},
67-
{
68-
"type": "file",
69-
"source": "data/etc/network/interfaces.d/usb0-cfg",
70-
"destination": "/etc/network/interfaces.d/usb0-cfg"
71-
},
72-
{
73-
"type": "file",
74-
"source": "data/etc/network/interfaces.d/eth0-cfg",
75-
"destination": "/etc/network/interfaces.d/eth0-cfg"
76-
},
77-
{
78-
"type": "file",
79-
"source": "data/etc/systemd/system/pwngrid-peer.service",
80-
"destination": "/etc/systemd/system/pwngrid-peer.service"
81-
},
82-
{
83-
"type": "file",
84-
"source": "data/etc/systemd/system/pwnagotchi.service",
85-
"destination": "/etc/systemd/system/pwnagotchi.service"
86-
},
87-
{
88-
"type": "file",
89-
"source": "data/etc/systemd/system/bettercap.service",
90-
"destination": "/etc/systemd/system/bettercap.service"
24+
"sources": [
25+
"../dist/pwnagotchi-{{user `pwn_version`}}.tar.gz"
26+
],
27+
"destination": "/usr/local/src/pwnagotchi/"
9128
},
9229
{
9330
"type": "shell",
9431
"inline": [
95-
"chmod +x /usr/bin/*"
32+
"apt-get -y --allow-releaseinfo-change update",
33+
"apt-get install -y --no-install-recommends ansible"
9634
]
9735
},
9836
{
@@ -104,7 +42,7 @@
10442
{
10543
"type": "shell",
10644
"inline": [
107-
"sed -i 's/^#\\(.+\\)/\\1/g' /etc/ld.so.preload"
45+
"mv /etc/ld.so.preload.DISABLED /etc/ld.so.preload"
10846
]
10947
}
11048
]

builder/pwnagotchi.yml

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -215,25 +215,29 @@
215215
regexp: "#EPD_SIZE=2.0"
216216
line: "EPD_SIZE=2.0"
217217

218-
- name: collect python pip package list
219-
command: "pip3 list"
220-
register: pip_output
221-
222-
- name: set python pip package facts
223-
set_fact:
224-
pip_packages: >
225-
{{ pip_packages | default({}) | combine( { item.split()[0]: item.split()[1] } ) }}
226-
with_items: "{{ pip_output.stdout_lines }}"
227-
228-
- name: acquire python3 pip target
229-
command: "python3 -c 'import sys;print(sys.path.pop())'"
218+
# pip v20.3 uses a newer dependency resolver that better handles our unique situation.
219+
# Specifically, it handles mismatches between direct requirements without extras and
220+
# indirect requirements that do want extras (e.g. gym vs stable-baselines->gym[atari]).
221+
- name: Upgrade pip
222+
pip:
223+
name: "pip"
224+
version: ">=20.3"
225+
226+
# Debian has two different system-level site package directories:
227+
# /usr/local/lib/pythonX.Y/dist-packages for packages installed via "sudo pip3"
228+
# /usr/lib/pythonX.Y/dist-packages for packages installed via "sudo apt-get"
229+
# Most of the time, pip is smart enough to not touch the packages installed by apt.
230+
# Other times, it will try to uninstall the existing apt packages and fail.
231+
- name: Get local site packages path
232+
command: python3 -c "import site; sp=[d for d in site.getsitepackages() if '/local' in d]; print(sp[0])"
230233
register: pip_target
231234

232-
- name: clone pwnagotchi repository
233-
git:
234-
repo: https://github.com/evilsocket/pwnagotchi.git
235-
dest: /usr/local/src/pwnagotchi
236-
register: pwnagotchigit
235+
# Manually specifying pip's --target argument will make pip install only to the target
236+
# directory without attempting to uninstall older package versions from elsewhere.
237+
- name: Install pwnagotchi from source archive
238+
pip:
239+
name: /usr/local/src/pwnagotchi/pwnagotchi-{{ pwnagotchi.version }}.tar.gz
240+
extra_args: --prefer-binary --target={{ pip_target.stdout }}
237241

238242
- name: create /usr/local/share/pwnagotchi/ folder
239243
file:
@@ -245,26 +249,6 @@
245249
repo: https://github.com/evilsocket/pwnagotchi-plugins-contrib.git
246250
dest: /usr/local/share/pwnagotchi/availaible-plugins
247251

248-
- name: fetch pwnagotchi version
249-
set_fact:
250-
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') }}"
251-
252-
- name: pwnagotchi version found
253-
debug:
254-
msg: "{{ pwnagotchi_version }}"
255-
256-
- name: build pwnagotchi wheel
257-
command: "python3 setup.py sdist bdist_wheel"
258-
args:
259-
chdir: /usr/local/src/pwnagotchi
260-
when: (pwnagotchigit.changed) or (pip_packages['pwnagotchi'] is undefined) or (pip_packages['pwnagotchi'] != pwnagotchi_version)
261-
262-
- name: install pwnagotchi wheel and dependencies
263-
pip:
264-
name: "{{ lookup('fileglob', '/usr/local/src/pwnagotchi/dist/pwnagotchi*.whl') }}"
265-
extra_args: "--no-cache-dir"
266-
when: (pwnagotchigit.changed) or (pip_packages['pwnagotchi'] is undefined) or (pip_packages['pwnagotchi'] != pwnagotchi_version)
267-
268252
- name: download and install pwngrid
269253
unarchive:
270254
src: "{{ packages.pwngrid.url }}"

0 commit comments

Comments
 (0)