#!/bin/bash dev=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A500DA2H-if00-port0 rundir=$(realpath $(dirname $0)) cmd="" quiet="" while [ $# -gt 0 ]; do case "$1" in start) cmd=$1;; stop) cmd=$1;; restart) cmd=$1;; status) cmd=$1;; -q) quiet=$1;; --quiet) quiet=$1;; *) echo "usage: $0 [start|stop|restart|status] [-q|--quiet]" exit 1 ;; esac shift done is_running=$(tmux has -t tic2mqtt 2> /dev/null && echo yes) case "$cmd" in start) if [ -n "$is_running" ]; then echo "tic2mqtt already running. aborting" exit 1 fi make -s test -z $quiet && echo "starting tic2mqtt" tmux new -s tic2mqtt -d "./tic2mqtt -a -t $dev -h doctor -v" test -z $quiet && tmux ls ;; stop) if [ ! -n "$is_running" ]; then test -z $quiet && echo "no tic2mqtt running. nothing to stop" exit 0 fi test -z $quiet && echo "killing tic2mqtt" tmux kill-session -t tic2mqtt ;; restart) $0 $quiet stop $0 $quiet start ;; status) if [ -n "$is_running" ]; then tmux ls | grep tic2mqtt else echo "no tic2mqtt running" fi ;; *) echo "usage: $0 [start|stop]" ;; esac