From 7cc82bccb856b8d7773c16373d70c8f16afd32b5 Mon Sep 17 00:00:00 2001
From: swedishmike <mike@swedishmike.org>
Date: Sat, 5 Oct 2019 18:11:05 +0100
Subject: [PATCH 1/2] More documentation updates for languages

---
 docs/configure.md                        | 1 +
 sdcard/rootfs/root/pwnagotchi/config.yml | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/docs/configure.md b/docs/configure.md
index d69bc9a..d2bb0f5 100644
--- a/docs/configure.md
+++ b/docs/configure.md
@@ -41,6 +41,7 @@ For instance, you can change `main.lang` to one of the supported languages:
 - italian
 - french
 - russian
+- swedish
 
 ## Display Selection
 
diff --git a/sdcard/rootfs/root/pwnagotchi/config.yml b/sdcard/rootfs/root/pwnagotchi/config.yml
index ae470ad..a93a7e8 100644
--- a/sdcard/rootfs/root/pwnagotchi/config.yml
+++ b/sdcard/rootfs/root/pwnagotchi/config.yml
@@ -1,6 +1,6 @@
 # main algorithm configuration
 main:
-    # currently implemented: en (default), de, el, fr, it, mk, nl, se
+    # currently implemented: en (default), de, el, fr, it, mk, nl, ru, se
     lang: en
     # custom plugins path, if null only default plugins with be loaded
     custom_plugins:

From 75b1e78e399ec641e3b36a3a1ee39a5c91731336 Mon Sep 17 00:00:00 2001
From: dadav <33197631+dadav@users.noreply.github.com>
Date: Sat, 5 Oct 2019 18:51:20 +0200
Subject: [PATCH 2/2] Refracture ansible playbook

---
 builder/pwnagotchi.yml | 270 ++++++++++++++++++++---------------------
 1 file changed, 133 insertions(+), 137 deletions(-)

diff --git a/builder/pwnagotchi.yml b/builder/pwnagotchi.yml
index 77a5cdf..a8dca14 100644
--- a/builder/pwnagotchi.yml
+++ b/builder/pwnagotchi.yml
@@ -3,29 +3,135 @@
     - 127.0.0.1
   become: yes
   vars:
-    pwn_hostname: "{{ lookup('env', 'PWN_HOSTNAME') | default('pwnagotchi', true) }}"
-    pwn_version: "{{ lookup('env', 'PWN_VERSION') | default('master', true) }} "
-    bettercap_query: "assets[?contains(name, 'armv6l')].browser_download_url"
+    pwnagotchi:
+      hostname: "{{ lookup('env', 'PWN_HOSTNAME') | default('pwnagotchi', true) }}"
+      version: "{{ lookup('env', 'PWN_VERSION') | default('master', true) }} "
+    system:
+      boot_options:
+        - "dtoverlay=dwc2"
+        - "dtparam=spi=on"
+        - "dtoverlay=spi1-3cs"
+        - "dtoverlay=pi3-disable-bt"
+        - "dtparam=audio=off"
+    services:
+      enable:
+        - dphys-swapfile.service
+        - getty@ttyGS0.service
+      disable:
+        - apt-daily.timer
+        - apt-daily.service
+        - apt-daily-upgrade.timer
+        - apt-daily-upgrade.service
+        - wpa_supplicant.service
+        - bluetooth.service
+        - triggerhappy.service
+        - ifup@wlan0.service
+    packages:
+      pip:
+        install:
+          - inky
+          - smbus2
+          - absl-py>=0.1.6
+          - enum34
+          - gast==0.2.2
+          - google_pasta
+          - opt_einsum
+          - scapy
+          - gym
+          - keras_applications>=1.0.6
+          - keras_preprocessing>=1.0.5
+          - stable-baselines
+          - file_read_backwards
+          - tensorflow_estimator>=1.14.0,<1.15.0
+          - tensorboard>=1.13.0,<1.14.0
+      apt:
+        remove:
+          - rasberrypi-net-mods
+          - dhcpcd5
+          - triggerhappy
+          - wpa_supplicant
+          - nfs-common
+        install:
+          - vim
+          - screen
+          - golang
+          - git
+          - build-essential
+          - python3-pip
+          - unzip
+          - gawk
+          - libopenmpi-dev
+          - libatlas-base-dev
+          - libjasper-dev
+          - libqtgui4
+          - libqt4-test
+          - libopenjp2-7
+          - tcpdump
+          - lsof
+          - libilmbase23
+          - libopenexr23
+          - libgstreamer1.0-0
+          - libavcodec58
+          - libavformat58
+          - libswscale5
+          - libpcap-dev
+          - libusb-1.0-0-dev
+          - libnetfilter-queue-dev
+          - dphys-swapfile
+          - kalipi-kernel
+          - kalipi-bootloader
+          - kalipi-re4son-firmware
+          - kalipi-kernel-headers
+          - libraspberrypi0
+          - libraspberrypi-dev
+          - libraspberrypi-doc
+          - libraspberrypi-bin
+          - fonts-dejavu
+          - fonts-dejavu-core
+          - fonts-dejavu-extra
+          - python3-crypto
+          - python3-requests
+          - python3-yaml
+          - python3-smbus
+          - python3-inkyphat
+          - python3-numpy
+          - python3-pil
+          - python3-tweepy
+          - python3-opencv
+          - python3-termcolor
+          - python3-astor
+          - python3-backports.weakref
+          - python3-h5py
+          - python3-six
+          - python3-protobuf
+          - python3-wrapt
+          - python3-wheel
+          - python3-mock
+          - python3-scipy
+          - python3-cloudpickle
+
+    bettercap:
+      query: "assets[?contains(name, 'armv6l')].browser_download_url"
 
   tasks:
 
   - name: selected hostname
     debug:
-      msg: "{{ pwn_hostname }}"
+      msg: "{{ pwnagotchi.hostname }}"
 
   - name: build version
     debug:
-      msg: "{{ pwn_version }}"
+      msg: "{{ pwnagotchi.version }}"
 
   - name: change hostname
     hostname:
-      name: "{{pwn_hostname}}"
+      name: "{{pwnagotchi.hostname}}"
 
   - name: add hostname to /etc/hosts
     lineinfile:
       dest: /etc/hosts
       regexp: '^127\.0\.0\.1[ \t]+localhost'
-      line: '127.0.0.1 localhost {{pwn_hostname}} {{pwn_hostname}}.local'
+      line: '127.0.0.1 localhost {{pwnagotchi.hostname}} {{pwnagotchi.hostname}}.local'
       state: present
 
   - name: Add re4son-kernel repo key
@@ -44,16 +150,9 @@
 
   - name: remove unecessary apt packages
     apt:
-      name: "{{ packages }}"
+      name: "{{ packages.apt.remove }}"
       state: absent
       purge: yes
-    vars:
-      packages:
-        - rasberrypi-net-mods
-        - dhcpcd5
-        - triggerhappy
-        - wpa_supplicant
-        - nfs-common
 
   - name: upgrade apt distro
     apt:
@@ -61,126 +160,22 @@
 
   - name: install packages
     apt:
-      name: "{{ packages }}"
+      name: "{{ packages.apt.install }}"
       state: present
-    vars:
-      packages:
-        - vim
-        - screen
-        - golang
-        - git
-        - build-essential
-        - python3-pip
-        - unzip
-        - gawk
-        - libopenmpi-dev
-        - libatlas-base-dev
-        - libjasper-dev
-        - libqtgui4
-        - libqt4-test
-        - libopenjp2-7
-        - tcpdump
-        - lsof
-        - libilmbase23
-        - libopenexr23
-        - libgstreamer1.0-0
-        - libavcodec58
-        - libavformat58
-        - libswscale5
-        - libpcap-dev
-        - libusb-1.0-0-dev
-        - libnetfilter-queue-dev
-        - dphys-swapfile
-        - kalipi-kernel
-        - kalipi-bootloader
-        - kalipi-re4son-firmware
-        - kalipi-kernel-headers
-        - libraspberrypi0
-        - libraspberrypi-dev
-        - libraspberrypi-doc
-        - libraspberrypi-bin
-        - fonts-dejavu
-        - fonts-dejavu-core
-        - fonts-dejavu-extra
-        - python3-crypto
-        - python3-requests
-        - python3-yaml
-        - python3-smbus
-        - python3-inkyphat
-        - python3-numpy
-        - python3-pil
-        - python3-tweepy
-        - python3-opencv
-        - python3-termcolor
-        - python3-astor
-        - python3-backports.weakref
-        - python3-h5py
-        - python3-six
-        - python3-protobuf
-        - python3-wrapt
-        - python3-wheel
-        - python3-mock
-        - python3-scipy
-        - python3-cloudpickle
 
   - name: configure dphys-swapfile
     file:
       path: /etc/dphys-swapfile
       content: "CONF_SWAPSIZE=1024"
 
-  - name: disable unecessary services
-    systemd:
-      name: "{{services}}"
-      state: stopped
-      enabled: no
-    vars:
-      services:
-        - apt-daily.timer
-        - apt-daily.service
-        - apt-daily-upgrade.timer
-        - apt-daily-upgrade.service
-        - wpa_supplicant.service
-        - bluetooth.service
-        - triggerhappy.service
-        - ifup@wlan0.service
-
-  - name: enable dphys-swapfile service
-    systemd:
-      name: dphys-swapfile.service
-      state: started
-      enabled: yes
-
-  - name: enable gadget serial port service
-    systemd:
-      name: getty@ttyGS0.service
-      state: started
-      enabled: yes
-
   - name: acquire python3 pip target
     command: "python3 -c 'import sys;print(sys.path.pop())'"
     register: pip_target
 
   - name: install pip packages
     pip:
-      name: "{{ packages }}"
+      name: "{{packages.pip.install}}"
       extra_args: "--no-deps --extra-index-url=https://www.piwheels.hostedpi.com/simple/ --prefer-binary --no-cache-dir --platform=armv6l --target={{ pip_target.stdout }}"
-    vars:
-      packages:
-        - inky
-        - smbus2
-        - absl-py>=0.1.6
-        - enum34
-        - gast==0.2.2
-        - google_pasta
-        - opt_einsum
-        - scapy
-        - gym
-        - keras_applications>=1.0.6
-        - keras_preprocessing>=1.0.5
-        - stable-baselines
-        - file_read_backwards
-        - tensorflow_estimator>=1.14.0,<1.15.0
-        - tensorboard>=1.13.0,<1.14.0
 
   - name: install grpcio
     command: "pip3 install --no-deps --extra-index-url=https://www.piwheels.hostedpi.com/simple/ --no-cache-dir --prefer-binary --platform=armv6l --only-binary=:all: --target={{ pip_target.stdout }} https://www.piwheels.hostedpi.com/simple/grpcio/grpcio-1.24.1-cp37-cp37m-linux_armv6l.whl"
@@ -196,7 +191,7 @@
 
   - name: download and install bettercap
     unarchive:
-      src: "{{ bettercap_release.content | from_json | json_query(bettercap_query) | first }}"
+      src: "{{ bettercap_release.content | from_json | json_query(bettercap.query) | first }}"
       dest: /usr/bin
       remote_src: yes
       exclude:
@@ -324,11 +319,7 @@
       insertafter: EOF
       line: '{{ item }}'
     with_items:
-      - "dtoverlay=dwc2"
-      - "dtparam=spi=on"
-      - "dtoverlay=spi1-3cs"
-      - "dtoverlay=pi3-disable-bt"
-      - "dtparam=audio=off"
+      - "{{system.boot_options}}"
 
   - name: change root partition
     replace:
@@ -356,7 +347,7 @@
   - name: configure motd
     copy:
       dest: /etc/motd
-      content: "(◕‿‿◕) {{pwn_hostname}} (pwnagotchi-{{pwn_version}})"
+      content: "(◕‿‿◕) {{pwnagotchi.hostname}} (pwnagotchi-{{pwnagotchi.version}})"
 
   - name: clean apt cache
     apt:
@@ -366,16 +357,21 @@
     apt:
       autoremove: yes
 
+  - name: enable services
+    systemd:
+      name: "{{services.enable}}"
+      state: started
+      enabled: yes
+
+  - name: disable unecessary services
+    systemd:
+      name: "{{services.disable}}"
+      state: stopped
+      enabled: no
+
   - name: remove ssh keys
     file:
       state: absent
       path: "{{item}}"
-    with_items:
-      - /etc/ssh/ssh_host_rsa_key
-      - /etc/ssh/ssh_host_rsa_key.pub
-      - /etc/ssh/ssh_host_dsa_key
-      - /etc/ssh/ssh_host_dsa_key.pub
-      - /etc/ssh/ssh_host/ecdsa_key
-      - /etc/ssh/ssh_host/ecdsa_key.pub
-      - /etc/ssh/ssh_host_ed25519_key
-      - /etc/ssh/ssh_host_ed25519_key.pub
+    with_fileglob:
+      - "/etc/ssh/ssh_host*_key*"