From 595b433d9d62903cf4cf8551906399e8658405dc Mon Sep 17 00:00:00 2001 From: Hans Karlinius Date: Wed, 27 Nov 2024 11:33:54 +0100 Subject: [PATCH] test --- vhclient/config.yaml | 8 +++-- .../rootfs/etc/s6-overlay/s6-rc.d/config/run | 7 +++-- vhclient/rootfs/usr/bin/my_program | 3 -- vhclient/rootfs/usr/bin/vhconfig_edit | 29 +++++++++++++++++++ 4 files changed, 39 insertions(+), 8 deletions(-) delete mode 100755 vhclient/rootfs/usr/bin/my_program create mode 100755 vhclient/rootfs/usr/bin/vhconfig_edit diff --git a/vhclient/config.yaml b/vhclient/config.yaml index 8d1d58e..0f72b6d 100644 --- a/vhclient/config.yaml +++ b/vhclient/config.yaml @@ -1,5 +1,5 @@ name: VirtualHere Client -version: "0.1.124" +version: "0.1.125" slug: vhclient description: VirtualHere Client arch: @@ -22,8 +22,8 @@ ingress: true #ingress_port: 8000 panel_icon: mdi:puzzle panel_title: vhclient -devices: - - /dev/mem +#devices: +# - /dev/mem privileged: - NET_ADMIN - SYS_ADMIN @@ -41,6 +41,8 @@ usbip: true kernel_modules: true options: autouse: true + autofind: true + manualhub: schema: autouse: bool autofind: bool diff --git a/vhclient/rootfs/etc/s6-overlay/s6-rc.d/config/run b/vhclient/rootfs/etc/s6-overlay/s6-rc.d/config/run index 60b0631..117584e 100755 --- a/vhclient/rootfs/etc/s6-overlay/s6-rc.d/config/run +++ b/vhclient/rootfs/etc/s6-overlay/s6-rc.d/config/run @@ -3,8 +3,11 @@ if bashio::config.has_value 'autofind'; then autofind=($(bashio::config 'autofind')) bashio::log.info "Set AUTOFIND hub to ${autofind}" - # TODO: check before toggle - /usr/bin/vhclient -t "AUTOFIND" + if [ "${autofind}" = "true" ]; then + /usr/bin/vhconfig_edit General AutoFind 1 + else + /usr/bin/vhconfig_edit General AutoFind 0 + fi fi if bashio::config.has_value 'manualhub'; then diff --git a/vhclient/rootfs/usr/bin/my_program b/vhclient/rootfs/usr/bin/my_program deleted file mode 100755 index a287b13..0000000 --- a/vhclient/rootfs/usr/bin/my_program +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -echo "All done!" > /share/example_addon_output.txt diff --git a/vhclient/rootfs/usr/bin/vhconfig_edit b/vhclient/rootfs/usr/bin/vhconfig_edit new file mode 100755 index 0000000..467fad4 --- /dev/null +++ b/vhclient/rootfs/usr/bin/vhconfig_edit @@ -0,0 +1,29 @@ +#!/command/with-contenv bashio +# Changed code from https://gist.github.com/thomedes/6201620#file-ini-sed + +file="/config/vhclient.ini" + +awkconfig_update_value(){ + local section="$1" + local key="$2" + local value="$3" + awk -v RS="(^|\n)[:blank:]*\\\\[" -v setFound=0 -v sec="$section"\ + -v kv="$key=$value" -v secPat="$section" -v subPat="$key"\ + '$1~"^[[:blank:]\[]*" secPat "[:blank:]*\]"{ \ + s = sub("[:blank:]*" subPat "[:blank:]*=[^#^;^\n]*", kv);\ + $0 = $0 ((0 == s)? "\n" kv "\n" : ""); # adding kv to $0;\ + secFound=1;\ + }\ + $1~"^[^;^#^\n^=]*\]"{\ + $0 = "[" $0; # adding the record separator "[" back in\ + }\ + NF{sub(/\n$/, ""); print $0}\ + END{ if (secFound == 0){\ + print "[" sec "]";\ + print kv;\ + }\ + }' $file > /tmp/vhclient_config_tmp +} + +awkconfig_update_value $1 $2 $3 +mv /tmp/vhclient_config_tmp $file \ No newline at end of file