Issues with Raspberry Pi upgrade script

There are a few bugs in the update-nodejs-and-nodered installer script. These bugs arise when using the --nodered-user parameter:

This parameter sets the variable NODERED_USER to the = part of the parameter. However the line that checks if the user is in the sudoers group does not use this variable, it uses $USER.

The line should read:

groups "$NODERED_USER" | grep -q '\bsudo\b' && GRS="Y" || GRS="N"

Welcome to the forum @DerekK19.

I don't think it's necessary for the Node-red user to be a member of the sudo group (Couldn't check - see note below).
However it is necessary for the user who installs Node-red since the script calls sudo many times.

So I suspect that the line you highlight is intended to check that the current user is a member.

You might be right there is a bug there though, should it be like this?

groups "$USER" | grep -q '\bsudo\b' && GRS="Y" || GRS="N"
    if [[ "$GRS" == "N" ]]; then
        echo "User $USER not in sudoers group. Exiting"
        exit 1;
    fi

or even

groups | grep -q '\bsudo\b' && GRS="Y" || GRS="N"
    if [[ "$GRS" == "N" ]]; then
        echo "You are not in sudoers group. Exiting"
        exit 1;
    fi

Note I just tried installing Node-red with the --node-red-user=pi parameter and the script fell over at line 272

cd: /home/pi: Permission denied

and ls -l /home gives me

drwx------ 2 newuser newuser 4096 Jul 27 02:04 newuser
drwx------ 5 pi      pi      4096 Jul 27 01:49 pi

Since neither of these users can cd to the other's $HOME, and we are strongly discouraged from running the script as root what user is able to install Node-red for someone else?

@dceejay can you comment on these two issues?

1 Like

Thanks for that. To get the install to work, I added my node red user to the sudo group (very dangerous I think) and ran as that user, then didn't pass the --nodered-user parameter. Having done the install I will now remove my node red user from the sudo group - and just hope I remember all this next time I try to upgrade node-red

I think I need to read that script more fully since there is something wrong (or misleading) there

I very nearly removed my only login user (pi) from the sudo group as a test.
Not sure how I could have reversed that. :scream:

1 Like

First thing I do is add a second user then make that user a sudo user. Otherwise your only option is to rebuild your Pi (Been there, done that!)

Yes - you are correct - the intention is that the Node-RED user shouldn't need sudo - but he user running the install script should - so yes there do seem to be some wrinkles in there. Suggestions and/or PR would be greatly appreciated.

What about this though?

To answer my own question:
To install Node-red for a different user (on a Raspberry Pi) use the command

sudo bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --nodered-user=<Nodered user name>

and confirm twice that you really want to do this.

It looks like a small change is needed to the script. Just change groups "$NODERED_USER" to groups "$USER"

Then as jbudd explains the current user would use sudo to run the script and pass the Node-Red user name as a --nodered-user parameter:

Then the installing user would run:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.