From 89cbcd1569332976cb664be2cc2bfab2379ffcee Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 12 Feb 2025 08:50:39 +0100 Subject: [PATCH] Revert + allow RUN_AS https://github.com/alexbelgium/hassio-addons/issues/1450#issuecomment-2651980887 --- signalk/config.json | 5 ++- signalk/rootfs/etc/cont-init.d/99-run.sh | 42 +++++++++++++++++------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/signalk/config.json b/signalk/config.json index c97d37dcc..772c281b2 100644 --- a/signalk/config.json +++ b/signalk/config.json @@ -49,11 +49,14 @@ "SYS_ADMIN", "SYS_RAWIO" ], + "schema": { + "RUN_AS": "str?" + }, "slug": "signalk", "uart": true, "udev": true, "url": "https://github.com/alexbelgium/hassio-addons", "usb": true, - "version": "2.13.1-2", + "version": "2.13.1-2_test2", "webui": "http://[HOST]:[PORT:3000]" } diff --git a/signalk/rootfs/etc/cont-init.d/99-run.sh b/signalk/rootfs/etc/cont-init.d/99-run.sh index b0b4e489d..dccc42380 100755 --- a/signalk/rootfs/etc/cont-init.d/99-run.sh +++ b/signalk/rootfs/etc/cont-init.d/99-run.sh @@ -3,23 +3,43 @@ set -e # hadolint ignore=SC2155 -# Set configuration directory -mkdir -p /config/.signalk -if [ -d "/home/node/.signalk" ]; then - if [ -n "$(find /home/node/.signalk -mindepth 1 -print -quit 2>/dev/null)" ]; then - cp -r /home/node/.signalk/* /config/.signalk/ - fi - rm -rf "/home/node/.signalk" +# Variables +USER=node +if bashio::config_has.value "RUN_AS"; then + USER="$(bashio::config "RUN_AS")" + bashio::log.warning "RUN_AS is set, app will run as $USER" fi -ln -sf /config/.signalk "/home/node/.signalk" -# Set single user for SSL files +# Set configuration directory +if [ -d "/home/node/.signalk" ]; then + rm -r "/home/node/.signalk" +fi +ln -sf /config "/home/node/.signalk" +chown -R "$USER:$USER" /config +chown -R "$USER:$USER" "/home/node/.signalk" + +# Option 1 : define permissions for /dev/ttyUSB +for device in /dev/ttyUSB /dev/ttyUSB0 /dev/ttyUSB1; do + if [ -e "$device" ]; then + # Check if 'node' is already in the 'root' group before modifying + if ! groups node | grep -q '\broot\b'; then + sudo usermod -a -G root node || true + echo "User 'node' added to group 'root'." + else + echo "User 'node' is already in group 'root'." + fi + fi +done + + +# Option 2 : set single user for SSL files for file in ssl-key.pem ssl-cert.pem; do if [ -e "/config/.signalk/$file" ]; then - chown "$(id -u):$(id -g)" "/config/.signalk/$file" + chown "$USER:$USER" "/config/.signalk/$file" chmod 600 "/config/.signalk/$file" fi done bashio::log.info "Starting application" -exec /home/node/signalk/startup.sh + +sudo -u "$USER" -s /bin/sh -c "/home/node/signalk/startup.sh"