Move sensitive config to .env file

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 22:39:15 -05:00
parent ae2e924322
commit 434b1cfa70
4 changed files with 29 additions and 18 deletions

5
.env.example Normal file
View File

@@ -0,0 +1,5 @@
SLSKD_URL="http://localhost:5030"
SLSKD_USER="slskd"
SLSKD_PASS="slskd"
GOTIFY_URL="https://notify.example.com"
GOTIFY_TOKEN=""

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.env

View File

@@ -28,7 +28,11 @@ Uploads are intentionally **not** counted as activity — they're what you're tr
sudo chmod +x /opt/arr/slskd/scripts/auto-disconnect.sh
```
2. Edit the configuration variables at the top of the script (`SLSKD_URL`, `SLSKD_USER`, `SLSKD_PASS`, `CONTAINER_NAME`, etc.)
2. Create a `.env` file from the example:
```bash
sudo cp .env.example /opt/arr/slskd/scripts/.env
sudo nano /opt/arr/slskd/scripts/.env
```
3. Add a cron job (as root):
```bash
@@ -40,23 +44,16 @@ Uploads are intentionally **not** counted as activity — they're what you're tr
## Configuration
Variables at the top of the script:
The script loads a `.env` file from its own directory. See `.env.example` for all available options.
| Variable | Default | Description |
|----------|---------|-------------|
| `SLSKD_URL` | `http://localhost:5030` | slskd API base URL |
| `SLSKD_USER` | `slskd` | slskd web UI username |
| `SLSKD_PASS` | `slskd` | slskd web UI password |
| `CONTAINER_NAME` | `slskd` | Docker container name |
| `LOG_CHECK_MIN` | `5` | How far back to check docker logs (minutes) |
| `LOG_MAX_LINES` | `500` | Max log file lines before truncation |
Environment variable overrides:
| Variable | Default | Description |
|----------|---------|-------------|
| `SLSKD_IDLE_TIMEOUT` | `30` | Minutes of inactivity before disconnect |
| `SLSKD_GOTIFY_TOKEN` | *(empty)* | Gotify app token for push notifications |
| `GOTIFY_URL` | *(empty)* | Gotify server URL for push notifications |
| `GOTIFY_TOKEN` | *(empty)* | Gotify app token for push notifications |
## Logs

View File

@@ -16,21 +16,29 @@
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Load .env if present
if [ -f "$SCRIPT_DIR/.env" ]; then
set -a
source "$SCRIPT_DIR/.env"
set +a
fi
# --- Configuration ---
SLSKD_URL="http://localhost:5030"
SLSKD_USER="slskd"
SLSKD_PASS="slskd"
SLSKD_URL="${SLSKD_URL:-http://localhost:5030}"
SLSKD_USER="${SLSKD_USER:-slskd}"
SLSKD_PASS="${SLSKD_PASS:-slskd}"
IDLE_TIMEOUT_MIN="${SLSKD_IDLE_TIMEOUT:-30}"
LOG_CHECK_MIN=5
CONTAINER_NAME="slskd"
SCRIPT_DIR="/opt/arr/slskd/scripts"
STATE_FILE="$SCRIPT_DIR/.last_active"
LOG_FILE="$SCRIPT_DIR/auto-disconnect.log"
LOG_MAX_LINES=500
GOTIFY_URL="https://notify.thecozycat.net"
GOTIFY_TOKEN="${SLSKD_GOTIFY_TOKEN:-}"
GOTIFY_URL="${GOTIFY_URL:-}"
GOTIFY_TOKEN="${GOTIFY_TOKEN:-}"
# --- Functions ---
@@ -105,7 +113,7 @@ seconds_since_active() {
notify() {
local msg="$1"
if [ -n "$GOTIFY_TOKEN" ]; then
if [ -n "$GOTIFY_TOKEN" ] && [ -n "$GOTIFY_URL" ]; then
curl -sf --max-time 10 "$GOTIFY_URL/message" -X POST \
-H "X-Gotify-Key: $GOTIFY_TOKEN" \
-F "title=slskd" \