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"
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?
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
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.