Skip to content

Commit

Permalink
debug config
Browse files Browse the repository at this point in the history
  • Loading branch information
boecks committed Oct 7, 2024
1 parent 25ec63c commit 9ee5d0d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion smtp2mqtt/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## [1.0.2] - 2024-10-07

### Fixed
- Correctly set addon config
- Correctly set addon config with run.sh

## [1.0.1] - 2024-10-06

Expand Down
29 changes: 0 additions & 29 deletions smtp2mqtt/apparmor.txt

This file was deleted.

26 changes: 4 additions & 22 deletions smtp2mqtt/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: "SMTP to MQTT"
version: "v1.0.2"
version: "v1.0.3"
slug: smtp2mqtt
description: "Transform SMTP to MQTT"
url: "https://github.com/boecks/hassio-addons/tree/main/smtp2mqtt"
arch:
- armhf
- armv7
Expand All @@ -25,7 +24,7 @@ schema:
mqtt_topic: str
mqtt_user: str?
mqtt_pass: password?
smtp_auth_required: bool?
smtp_auth_required: bool
smtp_relay_host: str?
smtp_relay_port: port?
smtp_relay_user: str?
Expand All @@ -35,23 +34,6 @@ schema:
publish_attachments: bool?
save_attachments: bool?
save_attachments_dir: str?
debug: bool?
debug: bool
image: "ghcr.io/boecks/docker-smtp2mqtt-{arch}"

environment:
- MQTT_HOST: "!mqtt_host"
- MQTT_PORT: "!mqtt_port"
- MQTT_USER: "!mqtt_user"
- MQTT_PASS: "!mqtt_pass"
- MQTT_TOPIC: "!mqtt_topic"
- SMTP_AUTH_REQUIRED: "!smtp_auth_required"
- SMTP_RELAY_HOST: "!smtp_relay_host"
- SMTP_RELAY_PORT: "!smtp_relay_port"
- SMTP_RELAY_USER: "!smtp_relay_user"
- SMTP_RELAY_PASS: "!smtp_relay_pass"
- SMTP_RELAY_STARTTLS: "!smtp_relay_starttls"
- SMTP_RELAY_TIMEOUT_SECS: "!smtp_relay_timeout_secs"
- PUBLISH_ATTACHMENTS: "!publish_attachments"
- SAVE_ATTACHMENTS: "!save_attachments"
- SAVE_ATTACHMENTS_DIR: "!save_attachments_dir"
- DEBUG: "!debug"
legacy: true
46 changes: 46 additions & 0 deletions smtp2mqtt/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bashio

bashio::log.info "Getting configuration..."

# Grab configuration options using bashio
DEBUG="$(bashio::config 'debug')"
MQTT_HOST="$(bashio::config 'mqtt_host' 'core-mosquitto')" # Default to core-mosquitto
SMTP_LISTEN_PORT="$(bashio::config 'smtp_listen_port' '25')"
SMTP_AUTH_REQUIRED="$(bashio::config 'smtp_auth_required' 'false')"
SMTP_RELAY_HOST="$(bashio::config 'smtp_relay_host')"
SMTP_RELAY_PORT="$(bashio::config 'smtp_relay_port')"
SMTP_RELAY_USER="$(bashio::config 'smtp_relay_user')"
SMTP_RELAY_PASS="$(bashio::config 'smtp_relay_pass')"
SMTP_RELAY_STARTTLS="$(bashio::config 'smtp_relay_starttls' 'false')"
SMTP_RELAY_TIMEOUT_SECS="$(bashio::config 'smtp_relay_timeout_secs' '30')"
MQTT_PORT="$(bashio::config 'mqtt_port' '1883')"
MQTT_USER="$(bashio::config 'mqtt_user')"
MQTT_PASS="$(bashio::config 'mqtt_pass')"
MQTT_TOPIC="$(bashio::config 'mqtt_topic' 'smtp2mqtt')"
PUBLISH_ATTACHMENTS="$(bashio::config 'publish_attachments' 'true')"
SAVE_ATTACHMENTS="$(bashio::config 'save_attachments' 'false')"

# Enable debugging if required
if [[ "$DEBUG" == "true" ]]; then
bashio::log.info "Debug mode is enabled."
bashio::log.info "MQTT_HOST: $MQTT_HOST"
bashio::log.info "SMTP_LISTEN_PORT: $SMTP_LISTEN_PORT"
bashio::log.info "MQTT_PORT: $MQTT_PORT"
bashio::log.info "MQTT_TOPIC: $MQTT_TOPIC"
fi

# Set the attachment save directory if needed
if [[ "$SAVE_ATTACHMENTS" == "true" ]]; then
SAVE_ATTACHMENTS_DIR="/share/smtp2mqtt"
if [[ -n "$MQTT_TOPIC" ]] && [[ "$MQTT_TOPIC" != "null" ]]; then
SAVE_ATTACHMENTS_DIR="/share/$MQTT_TOPIC"
fi
bashio::log.info "Creating attachment save directory: $SAVE_ATTACHMENTS_DIR"
mkdir -p "$SAVE_ATTACHMENTS_DIR" || {
bashio::log.error "Failed to create directory: $SAVE_ATTACHMENTS_DIR"
exit 1
}
fi

bashio::log.info "Starting application..."
exec python3 /app/smtp2mqtt.py

0 comments on commit 9ee5d0d

Please sign in to comment.