71 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/bash
 | 
						|
 | 
						|
dev=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A500DA2H-if00-port0
 | 
						|
rundir=$(realpath $(dirname $0))
 | 
						|
session="tic2mqtt"
 | 
						|
 | 
						|
cmd=""
 | 
						|
quiet=""
 | 
						|
 | 
						|
while [ $# -gt 0 ]; do
 | 
						|
    case "$1" in
 | 
						|
      start)   cmd=$1;;
 | 
						|
      stop)    cmd=$1;;
 | 
						|
      restart) cmd=$1;;
 | 
						|
      status)  cmd=$1;;
 | 
						|
      log)     cmd=$1;;
 | 
						|
      -q)      quiet=$1;;
 | 
						|
      --quiet) quiet=$1;;
 | 
						|
      *)       echo "usage: $0 [start|stop|restart|status|log] [-q|--quiet]"
 | 
						|
               exit 1
 | 
						|
               ;;
 | 
						|
    esac
 | 
						|
    shift
 | 
						|
done
 | 
						|
 | 
						|
is_running=$(tmux has -t $session 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 $session -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 $session
 | 
						|
        ;;
 | 
						|
    restart)
 | 
						|
        $0 $quiet stop
 | 
						|
        $0 $quiet start
 | 
						|
        ;;
 | 
						|
    status)
 | 
						|
        if [ -n "$is_running" ]; then
 | 
						|
            tmux ls | grep $session
 | 
						|
        else
 | 
						|
            echo "no tic2mqtt running"
 | 
						|
        fi
 | 
						|
        ;;
 | 
						|
    log)
 | 
						|
        if [ -n "$is_running" ]; then
 | 
						|
            tmux capture -b $session -p -S - | head -15
 | 
						|
            echo "[...]"
 | 
						|
            tmux capture -b $session -p -E -
 | 
						|
        else
 | 
						|
            echo "no tic2mqtt running"
 | 
						|
        fi
 | 
						|
        ;;
 | 
						|
    *)
 | 
						|
        echo "usage: $0 [start|stop]"
 | 
						|
        ;;
 | 
						|
esac
 |