Skip to content

Instantly share code, notes, and snippets.

@OddBloke
Created September 13, 2021 12:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OddBloke/bc0c13f7b65095ae52ed23d94e659fbf to your computer and use it in GitHub Desktop.
Save OddBloke/bc0c13f7b65095ae52ed23d94e659fbf to your computer and use it in GitHub Desktop.
Ansible playbook to setup headless jackd+guitarix (used on Debian bullseye)
---
- name: Set up RPi as a basic headless Guitarix amp
hosts: mirror
become_method: sudo
become: yes
tasks:
- name: Install required packages
apt:
name:
- guitarix
- jackd
# Recommends pulls in a bunch of GNOME that we don't want
install_recommends: false
- name: Write DBUS config to allow JACK to reserve USB sound card
copy:
dest: /etc/dbus-1/system.d/amp.conf
owner: root
group: root
mode: 0444
content: |
<?xml version="1.0"?> <!--*-nxml-*-->
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="amp">
<allow own="org.freedesktop.ReserveDevice1.Audio0"/>
<allow own="org.freedesktop.ReserveDevice1.Audio1"/>
<allow own="org.freedesktop.ReserveDevice1.Audio2"/>
</policy>
</busconfig>
- name: Create amp user
user:
name: amp
system: true
home: /opt/amp
create_home: true
groups:
- amp
- audio
- name: Write systemd unit file for jackd
copy:
dest: /etc/systemd/system/jackd.service
owner: root
group: root
mode: 0440
content: |
[Unit]
Description=Run jackd
[Service]
LimitRTPRIO=infinity
LimitMEMLOCK=infinity
ExecStart=/usr/bin/jackd -d alsa -r 48000 -p 256 -C hw:2,0 -P hw:2,0
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/dbus/system_bus_socket
User=amp
# Wait for startup, then connect capture_1 to left/right playback,
# for (downmixed-to-mono) practice input
ExecStartPost=/bin/sleep 5
ExecStartPost=/usr/bin/jack_connect system:capture_1 system:playback_1
ExecStartPost=/usr/bin/jack_connect system:capture_1 system:playback_2
[Install]
WantedBy=multi-user.target
- name: Create .config directory so Guitarix can write config
file:
path: /opt/amp/.config
state: directory
mode: 0755
owner: amp
group: amp
- name: Write systemd unit file for guitarix
copy:
dest: /etc/systemd/system/guitarix.service
owner: root
group: root
mode: 0440
content: |
[Unit]
Description=Run guitarix
Wants=jackd.service
After=jackd.service
[Service]
LimitRTPRIO=infinity
LimitMEMLOCK=infinity
ExecStart=/usr/bin/guitarix -N --log-terminal -i system:capture_2 -o system:playback_1 -o system:playback_2 --rpcport 7000
User=amp
[Install]
WantedBy=multi-user.target
- name: Set up Guitarix WebUI
hosts: mirror
become_method: sudo
become: yes
tasks:
- name: Install required packages
apt:
name:
- git
- nodejs
- name: Clone guitarix repo (for webui source) at the version in Debian
git:
name: https://github.com/brummer10/guitarix/
dest: /opt/amp/guitarix
version: V0.42.1
update: false
depth: 1
recursive: true
- name: Write diff required to make vendored websockify Py3-compatible
copy:
dest: /opt/amp/guitarix/diff
owner: amp
group: amp
mode: 0440
content: |
diff --git a/trunk/webui/websockify/websocket.py b/trunk/webui/websockify/websocket.py
index 06f4c2b5..c773c020 100644
--- a/trunk/webui/websockify/websocket.py
+++ b/trunk/webui/websockify/websocket.py
@@ -259,10 +259,10 @@ Sec-WebSocket-Accept: %s\r
mask = buf[hlen:hlen+4]
data = array.array('B')
mask = s2a(mask)
- data.fromstring(buf[pstart:pend])
+ data.frombytes(buf[pstart:pend])
for i in range(len(data)):
data[i] ^= mask[i % 4]
- return data.tostring()
+ return data.tobytes()
@staticmethod
def encode_hybi(buf, opcode, base64=False):
diff --git a/trunk/webui/websockify/websocketproxy.py b/trunk/webui/websockify/websocketproxy.py
index 41c757c2..8e6bc364 100755
--- a/trunk/webui/websockify/websocketproxy.py
+++ b/trunk/webui/websockify/websocketproxy.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
'''
A WebSocket to TCP socket proxy with support for "wss://" encryption.
@@ -239,7 +239,7 @@ Traffic Legend:
"""
Proxy client WebSocket to normal target socket.
"""
- tail = ""
+ tail = b""
cqueue = []
c_pend = 0
tqueue = []
@@ -273,10 +273,10 @@ Traffic Legend:
if target in outs:
# Send queued client data to the target
- dat = tqueue.pop(0)+"\n"
+ dat = tqueue.pop(0)+b"\n"
sent = target.send(dat)
if self.verbose:
- sys.stdout.write("> " + dat[:sent]); sys.stdout.flush()
+ sys.stdout.write("> " + dat[:sent].decode('utf-8')); sys.stdout.flush()
if sent == len(dat):
self.traffic(">")
else:
@@ -289,12 +289,12 @@ Traffic Legend:
# Receive target data, encode it and queue for client
buf = target.recv(self.buffer_size)
if self.verbose:
- sys.stdout.write("< " + buf); sys.stdout.flush()
+ sys.stdout.write("< " + buf.decode('utf-8')); sys.stdout.flush()
if len(buf) == 0:
self.vmsg("%s:%s: Target closed connection" %(
self.target_host, self.target_port))
raise self.CClose(1000, "Target closed")
- lines = (tail+buf).split("\n")
+ lines = (tail+buf).split(b"\n")
tail = lines.pop()
for line in lines:
if line:
- name: Apply patch to make vendored websockify work under Python 3
patch:
src: /opt/amp/guitarix/diff
remote_src: true
basedir: /opt/amp/guitarix
strip: 1
- name: Change permissions to amp
command: chown -R amp:amp /opt/amp/guitarix
- name: Write systemd unit file for guitarix webui
copy:
dest: /etc/systemd/system/guitarix-webui.service
owner: root
group: root
mode: 0440
content: |
[Unit]
Description=Run guitarix web UI
Wants=guitarix.service
After=guitarix.service
[Service]
LimitRTPRIO=infinity
LimitMEMLOCK=infinity
WorkingDirectory=/opt/amp/guitarix/trunk/webui
ExecStart=/usr/bin/python3 websockify/websocketproxy.py --web=. '*':8000 localhost:7000
User=amp
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment