From 69d3b5d3c65859e808104dda8e5ce59081ff5287 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 12 Feb 2025 21:42:37 +0100 Subject: [PATCH] Allow both node and root --- signalk/rootfs/etc/cont-init.d/99-run.sh | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/signalk/rootfs/etc/cont-init.d/99-run.sh b/signalk/rootfs/etc/cont-init.d/99-run.sh index 411ac4404..eb992d42c 100755 --- a/signalk/rootfs/etc/cont-init.d/99-run.sh +++ b/signalk/rootfs/etc/cont-init.d/99-run.sh @@ -3,21 +3,26 @@ set -e # hadolint ignore=SC2155 -# Variables -USER=node -if bashio::config.true "RUN_AS_ROOT"; then - USER="root" - bashio::log.warning "RUN_AS is set, app will run as $USER" -fi - # Set configuration directory if [ -d "/home/node/.signalk" ]; then rm -r "/home/node/.signalk" fi -ln -sf /config "/home/node/.signalk" + +# Variables +USER=node +if bashio::config.true "RUN_AS_ROOT"; then + USER="root" + HOMEDIR="/root" + bashio::log.warning "RUN_AS is set, app will run as $USER" + ln -sf /config "/root/.signalk" +else + HOMEDIR="/home/node" + ln -sf /config "/home/node/.signalk" +fi chown -R "$USER:$USER" /config -chown -R "$USER:$USER" "/home/node" -chown -R "$USER:$USER" "/home/node/.signalk" +ln -sf /config "$HOMEDIR/.signalk" +chown -R "$USER:$USER" "$HOMEDIR" +chown -R "$USER:$USER" "$HOMEDIR/.signalk" # Option 1 : define permissions for /dev/ttyUSB for device in /dev/ttyUSB /dev/ttyUSB0 /dev/ttyUSB1; do @@ -34,12 +39,11 @@ done || true # Option 2 : set single user for SSL files -for file in ssl-key.pem ssl-cert.pem; do - if [ -e "/home/node/.signalk/$file" ]; then - chmod 600 "/home/node/.signalk/$file" +for file in ssl-key.pem ssl-cert.pem security.json; do + if [ -e "/config/$file" ]; then + chmod 600 "/config/$file" fi done bashio::log.info "Starting application" - sudo -u "$USER" -s /bin/sh -c "/home/node/signalk/startup.sh"