From fb90864a19f2b834ce8ba5773dc0a6aed9e0f11e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 7 Nov 2018 12:01:29 +0100 Subject: updated openwrt packaging diff --git a/openwrt/rhctl/Makefile b/openwrt/rhctl/Makefile index ada885d..b126c32 100644 --- a/openwrt/rhctl/Makefile +++ b/openwrt/rhctl/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2013-2015 Christian Pointner, +# Copyright (C) 2016 Christian Pointner, # # # This is free software, licensed under the GNU General Public License v2. @@ -12,7 +12,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=rhctl -PKG_VERSION:=2015-07-26 +PKG_VERSION:=2017-01-11 PKG_RELEASE:=1 PKG_SOURCE_PROTO:=git @@ -26,62 +26,40 @@ include $(INCLUDE_DIR)/package.mk define Package/rhctl SECTION:=utils CATEGORY:=Utilities - TITLE:=Radio Helsinki audioswitch control tools + TITLE:=Radio Helsinki audioswitch control daemon URL:=http://www.helsinki.at MAINTAINER:=Christian Pointner - DEPENDS:=+liblua +luasocket +hotplug2 +msmtp + DEPENDS:=+curl endef define Package/rhctl/conffiles -/etc/rhctl/switchctl.conf +/etc/rhctl/config.toml endef define Package/rhctl/description -rhctl is a collection of daemons and tools intended to control the - main audio switch of Radio Helsinki. +rhctl is a small daemon to control the main audioswitch at Radio Helsinki. + The daemon can work standalone but may be controlled via telnet. It also + exports status updates via websockets. endef define Build/Configure - (cd $(PKG_BUILD_DIR)/src; \ - touch include.mk; \ - ) endef define Build/Compile - $(MAKE) -C $(PKG_BUILD_DIR)/src \ - $(TARGET_CONFIGURE_OPTS) \ - TARGET=Linux \ - CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include" \ - LDFLAGS="$(TARGET_LDFLAGS) -ldl -lm -lcrypt" \ - LUA_LDFLAGS="-llua" - $(STRIP) $(PKG_BUILD_DIR)/src/switchctl - $(STRIP) $(PKG_BUILD_DIR)/src/serialclient - $(STRIP) $(PKG_BUILD_DIR)/src/stdioclient - $(STRIP) $(PKG_BUILD_DIR)/src/heartbeatclient - $(STRIP) $(PKG_BUILD_DIR)/src/luaclient + export GOROOT=/opt/go + $(MAKE) -C $(PKG_BUILD_DIR)/ build-alix endef define Package/rhctl/install $(INSTALL_DIR) $(1)/etc/rhctl - $(INSTALL_DATA) ./files/switchctl.conf $(1)/etc/rhctl/ - $(INSTALL_DIR) $(1)/etc/config - $(INSTALL_DATA) ./files/rhctl.config $(1)/etc/config/rhctl + $(INSTALL_DATA) ./files/config.toml $(1)/etc/rhctl/ $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/switchctl $(1)/usr/bin/ - $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/serialclient $(1)/usr/bin/ - $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/stdioclient $(1)/usr/bin/ - $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/heartbeatclient $(1)/usr/bin/ - $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/luaclient $(1)/usr/bin/ - $(INSTALL_BIN) ./files/rhctlsh $(1)/usr/bin/ - $(INSTALL_DIR) $(1)/usr/share/rhctl - $(INSTALL_DATA) $(PKG_BUILD_DIR)/src/*.lua $(1)/usr/share/rhctl/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/linux_386/rhctl $(1)/usr/bin/ $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/switchctl.init $(1)/etc/init.d/switchctl - $(INSTALL_BIN) ./files/serialclient.init $(1)/etc/init.d/serialclient - $(INSTALL_BIN) ./files/heartbeatclient.init $(1)/etc/init.d/heartbeatclient - $(INSTALL_BIN) ./files/luaclient.init $(1)/etc/init.d/luaclient - $(INSTALL_DIR) $(1)/etc/hotplug.d/usb - $(INSTALL_DATA) ./files/rhctl-usbserial.hotplug $(1)/etc/hotplug.d/usb/20-rhctl-usbserial + $(INSTALL_BIN) ./files/rhctl.init $(1)/etc/init.d/rhctl + $(INSTALL_DIR) $(1)/usr/lib/check_mk_agent/plugins + $(INSTALL_BIN) ./files/rhctl.check_mk $(1)/usr/lib/check_mk_agent/plugins/rhctl + endef $(eval $(call BuildPackage,rhctl)) diff --git a/openwrt/rhctl/files/config.toml b/openwrt/rhctl/files/config.toml new file mode 100644 index 0000000..17ea2ef --- /dev/null +++ b/openwrt/rhctl/files/config.toml @@ -0,0 +1,41 @@ +[audioswitch] +dev = "/dev/ttyS1" +baud = 38400 +timeout = "500ms" +unit = 0 +inputs = [ { number = 1, server = "master", channel = "main" }, + { number = 2, server = "master", channel = "music" }, + { number = 3, server = "standby", channel = "main" }, + { number = 4, server = "standby", channel = "music" } ] + + +[servers] + + [servers.master] + dev = "/dev/ttyUSB3" + baud = 38400 + + [servers.standby] + dev = "/dev/ttyUSB2" + baud = 38400 + + +[timing] + + [timing.settling] + awakening = "30s" + select_server = "10s" + update_states = "3s" + + [timing.stale_states] + check_interval = "1m" + max_age = "1h1m" + + +[clients] + + [clients.web] + addr = ":4080" + + [clients.telnet] + addr = "localhost:4023" diff --git a/openwrt/rhctl/files/heartbeatclient.init b/openwrt/rhctl/files/heartbeatclient.init deleted file mode 100755 index 002dfb3..0000000 --- a/openwrt/rhctl/files/heartbeatclient.init +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh /etc/rc.common -START=72 - -BIN=heartbeatclient -DAEMON=/usr/bin/$BIN -DESC=$BIN -RUN_D=/var/run/rhctl -PIDFILE=$RUN_D/$BIN.pid - - -option_cb() { - local varname="$1" - local value="$2" - - if ! echo "$CONFIG_OPTIONS" | grep " $varname " > /dev/null; then - CONFIG_OPTIONS="$CONFIG_OPTIONS $varname " - fi -} - -start_daemon() { - local option - local value - local args="" - - local status="OK" - for option in $CONFIG_OPTIONS - do - config_get value "$1" "$option" - option=`echo $option | tr '_' '-'` - if [ $option = "led" ]; then - local led_path - eval "led_path=\${LED_${value}}" - if [ -z "$led_path" ]; then - status="OK but led not found" - else - led_path="/sys/class/leds/$led_path/brightness" - args="$args --led $led_path" - fi - elif [ -n "$value" ]; then - args="$args --$option $value" - fi - done - $DAEMON --write-pid $PIDFILE $args || status="failed" - echo -n " ($status)" -} - -get_led() -{ - local name - local sysfs - config_get name $1 name - config_get sysfs $1 sysfs - eval LED_$name=$sysfs -} - -start() { - echo -n "Starting $DESC:" - config_load "system" - config_foreach get_led "led" - config_load "rhctl" - mkdir -p $RUN_D - config_foreach start_daemon "heartbeatclient" - echo "." -} - -stop() { - echo -n "Stopping $DESC:" - if [ -f $PIDFILE ]; then - kill `cat $PIDFILE` > /dev/null 2>&1 - rm -f $PIDFILE > /dev/null 2>&1 - echo -n " (Ok)" - else - echo -n " (not running)" - fi - echo "." -} diff --git a/openwrt/rhctl/files/luaclient.init b/openwrt/rhctl/files/luaclient.init deleted file mode 100755 index bd0a796..0000000 --- a/openwrt/rhctl/files/luaclient.init +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/sh /etc/rc.common -START=73 - -BIN=luaclient -DAEMON=/usr/bin/$BIN -DESC=$BIN -RUN_D=/var/run/rhctl - - -option_cb() { - local varname="$1" - local value="$2" - - if ! echo "$CONFIG_OPTIONS" | grep " $varname " > /dev/null; then - CONFIG_OPTIONS="$CONFIG_OPTIONS $varname " - fi -} - -foreach_config_forced() { - foreach_config $1 "$2" "forced" -} - -foreach_config() { - local cfg="$1" - local name - local option - local value - local args="" - local forced=0 - - config_get name "$cfg" "name" - if [ -n "$2" ] && [ "x$2" != "x$name" ]; then - return - fi - - if [ -n "$3" ] && [ "x$3" == "xforced" ]; then - forced=1 - fi - - for option in $CONFIG_OPTIONS - do - config_get value "$cfg" "$option" - if [ "x$option" == "xdisabled" ]; then - if [ $forced -eq 0 ] && [ -n "$value" ] && [ $value -eq 1 ]; then - echo -n " $name(disabled)" - return - fi - continue - fi - - if [ "x$option" == "xname" ]; then - continue - fi - - option=`echo $option | tr '_' '-'` - if [ -n "$value" ]; then - args="$args --$option $value" - fi - done - echo -n " $name" - local status="OK" - $DAEMON --write-pid "$RUN_D/$BIN.$name.pid" $args || status="failed" - echo -n "($status)" -} - -stop_client() { - local name=$1 - local pidfile=$RUN_D/$BIN.$name.pid - echo -n " $name" - local status="OK" - if [ ! -f "$pidfile" ]; then - status="tunnel not active" - else - kill `cat $pidfile` > /dev/null 2>&1 || status="failed" - rm -f $pidfile - fi - echo -n "($status)" -} - -start() { - echo -n "Starting $DESC:" - config_load "rhctl" - if [ $# -gt 0 ]; then - while [ $# -gt 0 ]; do - config_foreach foreach_config_forced "luaclient" "$1" - shift - done - else - config_foreach foreach_config "luaclient" - fi - echo "." -} - -stop() { - echo -n "Stopping $DESC:" - local name - local pidfile - - if [ $# -gt 0 ]; then - while [ $# -gt 0 ]; do - stop_client $1 - shift - done - else - for pidfile in `ls $RUN_D/$BIN.*.pid 2> /dev/null`; do - name=${pidfile%%.pid} - name=${name##$RUN_D/$BIN.} - stop_client $name - done - fi - echo "." -} diff --git a/openwrt/rhctl/files/rhctl-usbserial.hotplug b/openwrt/rhctl/files/rhctl-usbserial.hotplug deleted file mode 100755 index 8d2f7bc..0000000 --- a/openwrt/rhctl/files/rhctl-usbserial.hotplug +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh -# -# Persistent naming for usb serial devices. -# -# Copyright 2013-2014 Christian Pointner -# - -logger="logger -p daemon.info -t rhctl-usbserial" - -idVendor=`echo $PRODUCT | awk -F '/' '{ print($1) }'` -idProduct=`echo $PRODUCT | awk -F '/' '{ print($2) }'` -bcdDevice=`echo $PRODUCT | awk -F '/' '{ print($3) }'` - -if [ "$idVendor" != "403" ] || [ "$idProduct" != "6011" ]; then - exit 0 -fi - -DEVPATH="/sys$DEVPATH" -if [ $ACTION == "add" ]; then - if [ ! -e "$DEVPATH/bInterfaceNumber" ]; then - exit 0 - fi - - PARENT=`dirname "$DEVPATH` - SERIAL=`cat $PARENT/serial` - - if [ "$SERIAL" != $(uci -q get rhctl.@global[0].ftdi_serial) ]; then - exit 0 - fi -fi - -hotplug=/dev/.hotplug -token=$hotplug/`echo $PRODUCT$DEVPATH | sed 's/\//=/g'` - -case "$ACTION" in - add) - ttydir=`echo "$DEVPATH/ttyUSB*` - tty=`basename $ttydir` - interface=`cat "$DEVPATH/bInterfaceNumber"` - - device="$interface" - - case "$interface" in - 00) device="ttyMasterCtl" - ;; - 01) device="ttyMasterHB" - ;; - 02) device="ttyStandbyCtl" - ;; - 03) device="ttyStandbyHB" - ;; - *) exit 0 - ;; - esac - - mkdir -p "$hotplug" - rm -f "/dev/$device" "$token" - ln -s "/dev/$device" "$token" - ln -s "/dev/$tty" "/dev/$device" - $logger "added: tty=$tty device=$device" - ;; - remove) - if [ -h "$token" ]; then - device=$(ls -l $token | sed 's/.*-> //;/ /s/.*//') - case "$device" in - "") # no symlink - $logger "failed: token=$token device=$device" - ;; - *) - rm -f $token $device - $logger "removed: $device" - ;; - esac - fi - ;; -esac - -exit 0 diff --git a/openwrt/rhctl/files/rhctl.check_mk b/openwrt/rhctl/files/rhctl.check_mk new file mode 100755 index 0000000..bb923c7 --- /dev/null +++ b/openwrt/rhctl/files/rhctl.check_mk @@ -0,0 +1,6 @@ +#!/bin/sh + +echo "<<>>" +curl http://localhost:4080/api/state + +exit 0 diff --git a/openwrt/rhctl/files/rhctl.config b/openwrt/rhctl/files/rhctl.config deleted file mode 100644 index 7df0239..0000000 --- a/openwrt/rhctl/files/rhctl.config +++ /dev/null @@ -1,66 +0,0 @@ -config 'global' - option ftdi_serial 'FTVSOXJP' -# option ftdi_serial 'FTVRIHVY' - -config 'switchctl' - option log 'syslog:3,switchctl,daemon' - option command_sock '/var/run/rhctl/switchctl.sock' - option baudrate '19200' - option device '/dev/ttyS1' - option config '/etc/rhctl/switchctl.conf' - option mode 'master' - option channel 'main' - -config 'serialclient' -# option disabled 1 - option name 'master' - option log 'syslog:3,serialclient-master,daemon' - option command_sock '/var/run/rhctl/switchctl.sock' - option baudrate '38400' - option device '/dev/ttyMasterCtl' - option type 'master' - -config 'serialclient' -# option disabled 1 - option name 'standby' - option log 'syslog:3,serialclient-standby,daemon' - option command_sock '/var/run/rhctl/switchctl.sock' - option baudrate '38400' - option device '/dev/ttyStandbyCtl' - option type 'standby' - -config 'heartbeatclient' - option log 'syslog:3,heartbeatclient,daemon' - option command_sock '/var/run/rhctl/switchctl.sock' - option baudrate '38400' - option device '/dev/ttyMasterHB' - option timeout '25' - option led 'heartbeat' - -config 'luaclient' -# option disabled 1 - option name 'mode-watch' - option log 'syslog:3,luaclient-mode-watch,daemon' - option command_sock '/var/run/rhctl/switchctl.sock' - option lua_file '/usr/share/rhctl/mode-watch.lua' - -config 'luaclient' -# option disabled 1 - option name 'health-watch' - option log 'syslog:3,luaclient-health-watch,daemon' - option command_sock '/var/run/rhctl/switchctl.sock' - option lua_file '/usr/share/rhctl/health-watch.lua' - -config 'luaclient' -# option disabled 1 - option name 'silence-watch' - option log 'syslog:3,luaclient-silence-watch,daemon' - option command_sock '/var/run/rhctl/switchctl.sock' - option lua_file '/usr/share/rhctl/silence-watch.lua' - -config 'luaclient' -# option disabled 1 - option name 'mode-tcpserver' - option log 'syslog:3,luaclient-mode-tcpserver,daemon' - option command_sock '/var/run/rhctl/switchctl.sock' - option lua_file '/usr/share/rhctl/mode-tcpserver.lua' diff --git a/openwrt/rhctl/files/rhctl.init b/openwrt/rhctl/files/rhctl.init new file mode 100755 index 0000000..ac3b111 --- /dev/null +++ b/openwrt/rhctl/files/rhctl.init @@ -0,0 +1,15 @@ +#!/bin/sh /etc/rc.common + +START=90 + +USE_PROCD=1 +PROG=/usr/bin/rhctl + +start_service () { + procd_open_instance + procd_set_param command "$PROG" +# procd_set_param env RHCTL_DEBUG=1 + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_close_instance +} diff --git a/openwrt/rhctl/files/rhctlsh b/openwrt/rhctl/files/rhctlsh deleted file mode 100755 index 50bcbfc..0000000 --- a/openwrt/rhctl/files/rhctlsh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -RUN_D=/var/run/rhctl -SOCK=$RUN_D/switchctl.sock - -/usr/bin/stdioclient --command-sock $SOCK diff --git a/openwrt/rhctl/files/serialclient.init b/openwrt/rhctl/files/serialclient.init deleted file mode 100755 index 63b0b44..0000000 --- a/openwrt/rhctl/files/serialclient.init +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/sh /etc/rc.common -START=71 - -BIN=serialclient -DAEMON=/usr/bin/$BIN -DESC=$BIN -RUN_D=/var/run/rhctl - - -option_cb() { - local varname="$1" - local value="$2" - - if ! echo "$CONFIG_OPTIONS" | grep " $varname " > /dev/null; then - CONFIG_OPTIONS="$CONFIG_OPTIONS $varname " - fi -} - -foreach_config_forced() { - foreach_config $1 "$2" "forced" -} - -foreach_config() { - local cfg="$1" - local name - local option - local value - local args="" - local forced=0 - - config_get name "$cfg" "name" - if [ -n "$2" ] && [ "x$2" != "x$name" ]; then - return - fi - - if [ -n "$3" ] && [ "x$3" == "xforced" ]; then - forced=1 - fi - - for option in $CONFIG_OPTIONS - do - config_get value "$cfg" "$option" - if [ "x$option" == "xdisabled" ]; then - if [ $forced -eq 0 ] && [ -n "$value" ] && [ $value -eq 1 ]; then - echo -n " $name(disabled)" - return - fi - continue - fi - - if [ "x$option" == "xname" ]; then - continue - fi - - option=`echo $option | tr '_' '-'` - if [ -n "$value" ]; then - args="$args --$option $value" - fi - done - echo -n " $name" - local status="OK" - $DAEMON --write-pid "$RUN_D/$BIN.$name.pid" $args || status="failed" - echo -n "($status)" -} - -stop_client() { - local name=$1 - local pidfile=$RUN_D/$BIN.$name.pid - echo -n " $name" - local status="OK" - if [ ! -f "$pidfile" ]; then - status="tunnel not active" - else - kill `cat $pidfile` > /dev/null 2>&1 || status="failed" - rm -f $pidfile - fi - echo -n "($status)" -} - -start() { - echo -n "Starting $DESC:" - config_load "rhctl" - if [ $# -gt 0 ]; then - while [ $# -gt 0 ]; do - config_foreach foreach_config_forced "serialclient" "$1" - shift - done - else - config_foreach foreach_config "serialclient" - fi - echo "." -} - -stop() { - echo -n "Stopping $DESC:" - local name - local pidfile - - if [ $# -gt 0 ]; then - while [ $# -gt 0 ]; do - stop_client $1 - shift - done - else - for pidfile in `ls $RUN_D/$BIN.*.pid 2> /dev/null`; do - name=${pidfile%%.pid} - name=${name##$RUN_D/$BIN.} - stop_client $name - done - fi - echo "." -} diff --git a/openwrt/rhctl/files/switchctl.conf b/openwrt/rhctl/files/switchctl.conf deleted file mode 100644 index 381fd8d..0000000 --- a/openwrt/rhctl/files/switchctl.conf +++ /dev/null @@ -1,16 +0,0 @@ -ch1 01 -ch2 02 -ch3 03 -ch4 04 -ch5 05 -ch6 06 -ch7 07 -ch8 08 -master_main 01 -master_music 02 -standby_main 03 -standby_music 04 -studio 05 -ext_studio 06 -streamer 07 -emergency 08 diff --git a/openwrt/rhctl/files/switchctl.init b/openwrt/rhctl/files/switchctl.init deleted file mode 100755 index 24ed62f..0000000 --- a/openwrt/rhctl/files/switchctl.init +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh /etc/rc.common -START=70 - -BIN=switchctl -DAEMON=/usr/bin/$BIN -DESC=$BIN -RUN_D=/var/run/rhctl -PIDFILE=$RUN_D/$BIN.pid - - -option_cb() { - local varname="$1" - local value="$2" - - if ! echo "$CONFIG_OPTIONS" | grep " $varname " > /dev/null; then - CONFIG_OPTIONS="$CONFIG_OPTIONS $varname " - fi -} - -start_daemon() { - local option - local value - local args="" - - for option in $CONFIG_OPTIONS - do - config_get value "$1" "$option" - option=`echo $option | tr '_' '-'` - if [ -n "$value" ]; then - args="$args --$option $value" - fi - done - local status="OK" - $DAEMON --write-pid $PIDFILE $args || status="failed" - echo -n " ($status)" -} - -start() { - echo -n "Starting $DESC:" - config_load "rhctl" - mkdir -p $RUN_D - config_foreach start_daemon "switchctl" - echo "." -} - -stop() { - echo -n "Stopping $DESC:" - if [ -f $PIDFILE ]; then - kill `cat $PIDFILE` > /dev/null 2>&1 - rm -f $PIDFILE > /dev/null 2>&1 - echo -n " (Ok)" - else - echo -n " (not running)" - fi - echo "." -} -- cgit v0.10.2