From ff1afbabbfa1f64412bb22e2c8bb68ce3347c2ff Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 4 Apr 2018 23:05:04 +0100 Subject: [PATCH] Snap config for daemon or user mode. --- snap/default_config.conf | 1 + snap/launcher.sh | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/snap/default_config.conf b/snap/default_config.conf index 2647d15e..be2071c6 100644 --- a/snap/default_config.conf +++ b/snap/default_config.conf @@ -1,2 +1,3 @@ port 1883 persistence false +user root diff --git a/snap/launcher.sh b/snap/launcher.sh index 803999e6..40f7f732 100755 --- a/snap/launcher.sh +++ b/snap/launcher.sh @@ -1,20 +1,32 @@ #!/bin/sh -# Wrapper to check for custom config in $SNAP_USER_COMMON and use it -# otherwise fall back to the included basic config which will at least +# Wrapper to check for custom config in $SNAP_USER_COMMON or $SNAP_COMMON and +# use it otherwise fall back to the included basic config which will at least # allow mosquitto to run and do something. -# This script will also copy the full example config in to SNAP_USER_COMMON -# so that people can refer to it. +# This script will also copy the full example config in to SNAP_USER_COMMON or +# SNAP_COMMON so that people can refer to it. +# +# The decision about whether to use SNAP_USER_COMMON or SNAP_COMMON is taken +# based on the user that runs the command. If the user is root, it is assumed +# that mosquitto is being run as a system daemon, and SNAP_COMMON will be used. +# If a non-root user runs the command, then SNAP_USER_COMMON will be used. + +if [ "$USER" = "root" ] +then + COMMON=$SNAP_COMMON +else + COMMON=$SNAP_USER_COMMON +fi CONFIG_FILE="$SNAP/default_config.conf" -CUSTOM_CONFIG="$SNAP_USER_COMMON/mosquitto.conf" +CUSTOM_CONFIG="$COMMON/mosquitto.conf" # Copy the example config if it doesn't exist -if [ ! -e "$SNAP_USER_COMMON/mosquitto_example.conf" ] +if [ ! -e "$COMMON/mosquitto_example.conf" ] then - echo "Copying example config to $SNAP_USER_COMMON/mosquitto_example.conf" + echo "Copying example config to $COMMON/mosquitto_example.conf" echo "You can create a custom config by creating a file called $CUSTOM_CONFIG" - cp $SNAP/mosquitto.conf $SNAP_USER_COMMON/mosquitto_example.conf + cp $SNAP/mosquitto.conf $COMMON/mosquitto_example.conf fi