launcher.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. # Wrapper to check for custom config in $SNAP_USER_COMMON or $SNAP_COMMON and
  3. # use it otherwise fall back to the included basic config which will at least
  4. # allow mosquitto to run and do something.
  5. # This script will also copy the full example config in to SNAP_USER_COMMON or
  6. # SNAP_COMMON so that people can refer to it.
  7. #
  8. # The decision about whether to use SNAP_USER_COMMON or SNAP_COMMON is taken
  9. # based on the user that runs the command. If the user is root, it is assumed
  10. # that mosquitto is being run as a system daemon, and SNAP_COMMON will be used.
  11. # If a non-root user runs the command, then SNAP_USER_COMMON will be used.
  12. case "$SNAP_USER_COMMON" in
  13. */root/snap/mosquitto/common*) COMMON=$SNAP_COMMON ;;
  14. *) COMMON=$SNAP_USER_COMMON ;;
  15. esac
  16. CONFIG_FILE="$SNAP/default_config.conf"
  17. CUSTOM_CONFIG="$COMMON/mosquitto.conf"
  18. # Copy the example config if it doesn't exist
  19. if [ ! -e "$COMMON/mosquitto_example.conf" ]
  20. then
  21. echo "Copying example config to $COMMON/mosquitto_example.conf"
  22. echo "You can create a custom config by creating a file called $CUSTOM_CONFIG"
  23. cp $SNAP/mosquitto.conf $COMMON/mosquitto_example.conf
  24. fi
  25. # Does the custom config exist? If so use it.
  26. if [ -e "$CUSTOM_CONFIG" ]
  27. then
  28. echo "Found config in $CUSTOM_CONFIG"
  29. CONFIG_FILE=$CUSTOM_CONFIG
  30. else
  31. echo "Using default config from $CONFIG_FILE"
  32. fi
  33. # Launch the snap
  34. $SNAP/usr/sbin/mosquitto -c $CONFIG_FILE $@