Skip to content

Commit

Permalink
Working template for rhasspy based voice-assistant without any site-s…
Browse files Browse the repository at this point in the history
…pecific settings
  • Loading branch information
aniongithub committed Aug 23, 2021
1 parent cc48363 commit 9d6dc0d
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Initialize any environment variables here
# Note that env. substitution takes place on the host.

BOOTSTRAP_HOSTNAME="pi-bootstrap"
BOOTSTRAP_HOSTNAME="rhasspy"
2 changes: 1 addition & 1 deletion .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
inputs:
pifile:
description: "path/to/pifile (without extension)"
default: bootstrap
default: rhasspy
required: true

jobs:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ jobs:
- name: Write secrets.env
env:
SECRETS: ${{ secrets.SECRETS_ENV }}
PIFILE: bootstrap.Pifile
PIFILE: rhasspy.Pifile
run: |
echo $SECRETS > $(dirname $PIFILE)/secrets.env
- name: Build image
uses: Nature40/[email protected]
with:
pifile: bootstrap.Pifile
pifile: rhasspy.Pifile

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ github.workflow }}-${{ github.event.release.tag_name }}.zip
path: bootstrap.img
path: rhasspy.img
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"*.yaml": "home-assistant"
}
}
40 changes: 3 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
# pi-bootstrap
# rhasspy appliance

A repository that shows how to use Pi-Gen and Github Actions to create a ready-to-use Raspberry Pi image that includes connectivity to your home Wi-Fi, custom packages and build steps without opening a terminal or any manual setup. You can do all of this directly within the Github UI, which significantly lowers the barrier of entry for novice users, who don't need to understand a lot of the technical details.
A repository that shows how to use Pi-Bootstrap ready-to-use Raspberry Pi image that has Rhasspy, HomeAssistant and Node-RED ready to use as a voice assistant, including drivers for the [seeed-voicecard](https://github.com/respeaker/seeed-voicecard) based Raspberry Pi hats.

Youtube video explaining the what, why and how.

[![Bootstrapping the Raspberry Pi using GitHub Actions](http://img.youtube.com/vi/Lc6wvHgMYH4/0.jpg)](http://www.youtube.com/watch?v=Lc6wvHgMYH4 "Bootstrapping the Raspberry Pi using GitHub Actions ")

:gear: This repository is intended as a basic template for developers who wish to create ready-to-use bootstrap repositories meant for novice users. See [aniongithub/raspotify-appliance](https://github.com/aniongithub/raspotify-appliance) for an example of a repository meant for novice end-users to use directly

## Module environment variables

The table below lists variables for each module in pi-bootstrap, confidential variables are marked by 🔑 and should be set in Github repository secret ```SECRET_ENV``` (or ```secrets.env``` if developing locally) while others can be committed to git in ```.env```


| Module | Variable | Description | Default |
| :--------------: | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| ```core``` | | Sets up core functions, software, environment, etc. Required to use pi-bootstrap modules | |
| ```hostname``` | | Changes the hostname of your Raspberry Pi | |
| | **BOOTSTRAP_HOSTNAME** | The name with which your Pi will identify itself to any networks | *pi-bootstrap* |
| ```ssh``` | | Enables SSH access | |
| ```password``` | | Changes the password for a specified user for more security | |
| | **BOOTSTRAP_USER** 🔑 | Name of the user to change the password for | *pi* |
| | **BOOTSTRAP_PASSWORD** 🔑 | The password for**${BOOTSTRAP_USER}** on the generated image | *b00tstrap* |
| ```timezone``` | | Sets the timezone of your Raspberry Pi | |
| | **BOOTSTRAP_TIMEZONE** | The[TZ database name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) (timezone) where your Raspberry Pi will run | *America/Los_Angeles* |
| ```camera``` | | Enables the Raspberry Pi camera module | |
| | **BOOTSTRAP_GPU_MEM** | Amount of GPU memory (MB) to reserve for camera operation | 128 |
| ```wifi``` | | | |
| | **BOOTSTRAP_WPA_SSID** 🔑 | SSID of your Wi-Fi network | *None* |
| | **BOOTSTRAP_WPA_PASSPHRASE** 🔑 | Passphrase of your Wi-Fi network | *None* |
| | **BOOTSTRAP_WPA_COUNTRY** | Two-character ISO-3166-1 alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) for your country. | *None* |
| ```docker``` | | Sets up docker and docker-compose | |

## Usage

The flowchart below shows simple usage of pi-bootstrap.

![Usage](assets/pi-bootstrap usage.svg)
:gear: This repository is intended as a template for users who wish to create ready-to-use voice assistants customized for their homes, intents, networking and hardware setup.
11 changes: 11 additions & 0 deletions configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# assuming you have only one non-system user
homeassistant:
auth_providers:
- type: homeassistant
- type: trusted_networks
trusted_networks:
- 192.168.68.0/24
- 127.0.0.1
- ::1
allow_bypass_login: true
http:
4 changes: 4 additions & 0 deletions etc/rhasspy/bootstrap.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Any environment vars we need for our startup/shutdown steps
CONFIG_PATH=
RHASSPY_PROFILES_PATH=
HOMEASSISTANT_CONFIG_PATH=
45 changes: 45 additions & 0 deletions etc/rhasspy/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -e

export SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Ensure we're running in our current directory
pushd $SCRIPT_DIR
trap "popd; exit" INT TERM EXIT

# Set up environment configured in our env file
# https://unix.stackexchange.com/a/79077/358706
set -o allexport
. ./bootstrap.conf
set +o allexport

# Parse options using getopt
# https://www.codebyamir.com/blog/parse-command-line-arguments-using-getopt
opts=$(getopt \
--longoptions "start,stop" \
--name "$(basename "$0")" \
--options "" \
-- "$@"
)
eval set --$opts

while [[ $# -gt 0 ]]; do
case "$1" in
--start)
# Run (in lexical sort-order) all executable scripts within init.d for startup
run-parts --exit-on-error init.d
shift
;;

--stop)
# Run (in lexical sort-order) all executable scripts within shutdown.d for shutdown
run-parts --exit-on-error shutdown.d
shift
;;

*)
break
;;
esac
done
22 changes: 22 additions & 0 deletions etc/rhasspy/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3"
services:
nodered:
image: nodered/node-red
network_mode: host
environment:
TZ: "America/Los_Angeles"
volumes:
- /home/pi/.config/node-red:/data
- /etc/localtime:/etc/localtime:ro
- /etc/TZ:/etc/timezone:ro
- /usr/share/zoneinfo:/usr/share/zoneinfo:ro
rhasspy:
depends_on:
- nodered
image: rhasspy/rhasspy
network_mode: host
volumes:
- /home/pi/.config/rhasspy/profiles:/rhasspy/profiles
devices:
- /dev/snd:/dev/snd
entrypoint: ["/usr/lib/rhasspy/bin/rhasspy-voltron", "--user-profiles", "/rhasspy/profiles", "--profile", "en"]
13 changes: 13 additions & 0 deletions etc/rhasspy/init.d/00-install-respeaker-driver
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if ! lsmod | grep seeed; then
echo "Installing seeed-voicecard driver..."
export LC_ALL=C.UTF-8
cd /usr/local/src
git clone https://github.com/HinTak/seeed-voicecard.git
cd seeed-voicecard
./install.sh
reboot --force
else
echo "seeed-voicecard driver installed, continuing..."
fi
3 changes: 3 additions & 0 deletions etc/rhasspy/init.d/01-docker-pull
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
docker pull rhasspy/rhasspy
docker pull nodered/node-red
2 changes: 2 additions & 0 deletions etc/rhasspy/init.d/02-heartbeat-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo heartbeat > /sys/class/leds/led0/trigger
3 changes: 3 additions & 0 deletions etc/rhasspy/init.d/03-docker-compose-up
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
TIMEZONE="$(cat /etc/timezone)" \
docker-compose -f ${SCRIPT_DIR}/docker-compose.yaml up
2 changes: 2 additions & 0 deletions etc/rhasspy/shutdown.d/00-docker-compose-down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f ${SCRIPT_DIR}/docker-compose.yaml down
2 changes: 2 additions & 0 deletions etc/rhasspy/shutdown.d/01-heartbeat-shutdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo none > /sys/class/leds/led0/trigger
16 changes: 16 additions & 0 deletions etc/systemd/system/rhasspy.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Rhasspy
Requires=docker.service
After=docker.service

[Service]
Type=forking
ExecStart=/etc/rhasspy/bootstrap.sh --start
ExecStop=/etc/rhasspy/bootstrap.sh --stop
Restart=on-failure
RestartSec=5s
User=root
TimeoutSec=900

[Install]
WantedBy=sysinit.target
20 changes: 19 additions & 1 deletion bootstrap.Pifile → rhasspy.Pifile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,22 @@ source modules/timezone.Pifile
# BOOTSTRAP_WPA_SSID, BOOTSTRAP_WPA_PASSPHRASE and BOOTSTRAP_WPA_COUNTRY (defaults: None)
# Note: all 3 vars need to be set, otherwise wpa_supplicant.conf will not be generated
# and Wi-Fi will be blocked with rfkill
source modules/wifi.Pifile
source modules/wifi.Pifile

# Increase side of our image to accomodate installs
PUMP 500M

# Set up docker and docker-compose
source modules/docker.Pifile

# Install Rhasspy and Node-RED as a docker-compose file managed by a systemd unit
INSTALL etc /etc
RUN systemctl enable rhasspy.service

# Create empty config dirs accessible to the pi user
RUN install -d -m 0755 -o pi \
/home/pi/.config/ \
/home/pi/.config/rhasspy \
/home/pi/.config/rhasspy/profiles \
/home/pi/.config/rhasspy/profiles/en
RUN install -d -m 0755 -o pi /home/pi/.config /home/pi/.config/node-red

0 comments on commit 9d6dc0d

Please sign in to comment.