Skip to content

Commit 711147a

Browse files
committed
feat: add shutdown config command
1 parent c27dc7e commit 711147a

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ priority = "optional"
4949
assets = [
5050
["target/arm-unknown-linux-gnueabihf/release/bloop-box", "usr/bin/", "755"],
5151
["README.md", "usr/share/doc/bloop-box/", "644"],
52-
["etc/bloop-box.conf", "etc/", "644"]
52+
["etc/bloop-box.conf", "etc/", "644"],
53+
["etc/011_bloop-box-shutdown", "etc/sudoers.d", "440"]
5354
]

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44

55
Bloop box client written in Rust with Tokio.
66

7-
## NFC Tag Support
7+
## Table of Contents
8+
9+
1. [NFC tag support](#nfc-tag-support)
10+
2. [Run-time configuration](#run-time-configuration)
11+
3. [LED status codes](#led-status-codes)
12+
4. [Pre-requisites](#pre-requisites)
13+
5. [Shared data](#shared-data)
14+
6. [Deployment](#deployment)
15+
1. [Automatic](#automatic)
16+
2. [Manual](#manual)
17+
7. [System Setup](#system-setup)
18+
19+
## NFC tag support
820

921
While for reading UIDs any NFC tag supporting Iso14443a with a baud rate of 106 is supported, it is recommended to use
1022
tags with a 7-byte UID. Tags with shorter UIDs will be padded with zeroes, while tags with longer UIDs will be
@@ -13,7 +25,25 @@ truncated.
1325
When it comes to config tags though you have to use either NTAG 213, 215 or 216. Other NTAG formats may work but are
1426
not tested.
1527

16-
## LED Status Codes
28+
## Run-time configuration
29+
30+
You can change all configuration at run-time via text records on an NTAG tag. A helpful utility to automatically
31+
generate the text records [is available here](https://github.com/bloop-box/bloop-box-config). If you prefer to generate
32+
the config tags in another way, following is the format for the text record:
33+
34+
Each record begins with a single letter denoting the command. It is followed by a JSON array with zero or more
35+
arguments.
36+
37+
| Command | Description | Arguments |
38+
|---------|-----------------------------------|-------------------------------|
39+
| w | Set WiFi Credentials | SSID, Password |
40+
| c | Set Connection Details | Host, Port, Client ID, Secret |
41+
| v | Set Max Volume | Volume (0.0 - 0.1) |
42+
| u | Add additional config tag | |
43+
| r | Remove all but current config tag | |
44+
| s | Shut down system | |
45+
46+
## LED status codes
1747

1848
The status RGB LED will display the current status of the Bloop Box. If no user interaction is required, you'll get a
1949
static light, otherwise a blinking one.
@@ -80,6 +110,12 @@ chown bloop-box:nogroup /var/lib/bloop-box
80110

81111
On a development system, you might want to give the bloop-box user a login shell and a home directory.
82112

113+
#### Allow bloop-box user to shut down system
114+
115+
The bloop box client has the capability to shut down the system when it receives the right config command. In order to
116+
do so it needs sudo privilege to call the `shutdown` binary. You can accomplish this by copying the
117+
`011_bloop-box-shutdown` file from the `etc` directory to `/etc/sudoers.d` and change its permissions ot `440`.
118+
83119
#### Hardware config
84120

85121
In order to configure the Bloop Box for your specific hardware, you need to copy the `etc/bloop-box.conf` file to via

etc/011_bloop-box-shutdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bloop-box ALL=(ALL) NOPASSWD:/usr/sbin/shutdown

src/subsystems/controller.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::etc_config::EtcConfig;
22
use anyhow::{anyhow, Error, Result};
33
use log::info;
44
use std::path::PathBuf;
5+
use std::process::Command;
56
use std::time::Duration;
67
use tokio::fs::metadata;
78
use tokio::fs::File;
@@ -255,6 +256,12 @@ impl Controller {
255256
.await?;
256257
config_rx.await?;
257258
}
259+
's' => {
260+
Command::new("sudo")
261+
.args(["shutdown", "now"])
262+
.output()
263+
.expect("Failed to shut down system");
264+
}
258265
_ => {
259266
return Err(anyhow!("Value too short"));
260267
}

0 commit comments

Comments
 (0)