├── .gitignore ├── .travis copy.yml ├── .travis.yml ├── LICENSE ├── README-CN.md ├── README.md ├── deb └── update-nodejs-and-nodered ├── pibuild ├── README.md ├── node-red-deb-pack.sh └── node-red-pi-install.sh ├── resources ├── Node-RED.desktop ├── node-red-icon.svg ├── node-red-log ├── node-red-reload ├── node-red-restart ├── node-red-start ├── node-red-start.old ├── node-red-start.rpm ├── node-red-stop ├── nodered ├── nodered.rotate ├── nodered.service ├── nodered.socket ├── nodered.xml ├── update-nodejs-and-nodered └── update-pi └── rpm └── update-nodejs-and-nodered /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | pibuild/lint.log 3 | pibuild/grab 4 | pibuild/packit 5 | pibuild/report 6 | pibuild/runit 7 | pibuild/dist/* 8 | *.deb 9 | *.rpm 10 | *socket 11 | -------------------------------------------------------------------------------- /.travis copy.yml: -------------------------------------------------------------------------------- 1 | 2 | dist: trusty 3 | 4 | sudo: required 5 | 6 | env: 7 | matrix: 8 | - OS=ubuntu DIST=trusty 9 | - OS=ubuntu DIST=xenial 10 | - OS=ubuntu DIST=bionic 11 | - OS=ubuntu DIST=cosmic 12 | - OS=ubuntu DIST=disco 13 | - OS=ubuntu DIST=eoan 14 | - OS=debian DIST=jessie 15 | - OS=debian DIST=stretch 16 | - OS=debian DIST=buster 17 | 18 | 19 | before_script: 20 | - sudo echo $NVM_DIR 21 | - sudo echo $(/etc/os_release) 22 | - sudo apt -y install libstdc++6 23 | - sudo rm -rf $NVM_DIR ~/.npm ~/.bower 24 | - sudo echo $(node -v) 25 | - sudo echo $TRAVIS_DIST $DIST 26 | - if [ "$DIST" = "trusty" ]; then echo "VERSION_ID=\"8\"" | sudo tee /etc/os-release ; curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - ; fi 27 | - if [ "$DIST" = "jessie" ]; then echo "VERSION_ID=\"8\"" | sudo tee /etc/os-release ; curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - ; fi 28 | - cat /etc/os-release | grep VERSION_ID | cut -d '"' -f 2 29 | 30 | script: 31 | - curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered > nr.sh 32 | - echo y | bash nr.sh -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os : linux 2 | sudo: required 3 | 4 | matrix: 5 | include: 6 | - env: OS='centos:7' OSTYPE='rpm' 7 | - env: OS='centos:latest' OSTYPE="rpm" 8 | - env: OS='fedora:latest' OSTYPE="rpm" 9 | - env: OS='ubuntu:16.04' OSTYPE="deb" 10 | - env: OS='ubuntu:18.04' OSTYPE="deb" 11 | - env: OS='ubuntu:20.04' OSTYPE="deb" 12 | - env: OS='debian:stretch' OSTYPE="deb" 13 | - env: OS='debian:buster' OSTYPE="deb" 14 | 15 | before_install: 16 | - docker pull $OS 17 | 18 | script: 19 | - echo "OS is $OS" 20 | - if [ "$OSTYPE" = "rpm" ]; then 21 | docker run -it $OS /bin/sh -c "curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/rpm/update-nodejs-and-nodered > nr.sh && printf '%s\n' Y N Y | bash nr.sh"; 22 | else 23 | docker run -it $OS /bin/sh -c "apt-get update && apt-get -y install curl sudo lsb-release && curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered > nr.sh && printf '%s\n' Y Y Y | bash nr.sh"; 24 | fi 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /README-CN.md: -------------------------------------------------------------------------------- 1 | ## For Debian/Raspberry Pi OS: 2 | 3 | If you are Chinese user, we suggest you to change your node-js offical mirror to Chinese mirror, 4 | 如果您在中国请使用国内镜像源获取更好的下载体验, 5 | 6 | run `curl -sL https://deb.nodesource.com/setup_18.x | sudo bash -` , 7 | 示例:`curl -sL https://deb.nodesource.com/setup_18.x | sudo bash -` 从官方安装apt源, 8 | 9 | then please edit apt source list`/etc/apt/sources.list.d/nodesource.list` like this: 10 | 编辑镜像源`/etc/apt/sources.list.d/nodesource.list` 修改如下: 11 | ``` 12 | #deb https://deb.nodesource.com/node_12.x bullseye main 13 | #deb-src https://deb.nodesource.com/node_12.x bullseye main 14 | deb https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_12.x bullseye main 15 | deb-src https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_12.x bullseye main 16 | ``` 17 | if you edit it. Please run`sudo apt-get update`. 18 | 更改镜像源后应该刷新缓存,请运行`sudo apt-get update`` 19 | 20 | also,you can change npm source`npm config set registry https://registry.npm.taobao.org` 21 | 同样,建议修改npm安装源为淘宝镜像源`npm config set registry https://registry.npm.taobao.org` 22 | 23 | Then run the install script as per the main README.md. 24 | 25 | ## For CentOS: 26 | 27 | If you are Chinese user, we suggest you to change your node-js offical mirror to Chinese mirror, 28 | 如果您在中国请使用国内镜像源获取更好的下载体验, 29 | 30 | visit `https://mirrors.tuna.tsinghua.edu.cn/nodesource/` and see which version do you need, you can add its yum source list like this `rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_18.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm` 31 | 请找到适合您的rpm源安装包 32 | 33 | then edit yum source list `/etc/yum.repos.d/nodesource-el7.repo` like this: 34 | 然后编辑nodesource源如下(请根据实际情况修改): 35 | ``` 36 | [nodesource] 37 | name=Node.js Packages for Enterprise Linux 7 - $basearch 38 | baseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_18.x/el/7/$basearch 39 | failovermethod=priority 40 | enabled=1 41 | gpgcheck=1 42 | gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL 43 | 44 | [nodesource-source] 45 | name=Node.js for Enterprise Linux 7 - $basearch - Source 46 | baseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_18.x/el/7/SRPMS 47 | failovermethod=priority 48 | enabled=0 49 | gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL 50 | gpgcheck=1 51 | ``` 52 | please make cache again by runing `sudo yum makecache` 53 | 更改镜像源后请刷新缓存。 54 | 55 | also,you can change npm source`npm config set registry https://registry.npm.taobao.org` 56 | 同样,建议修改npm安装源为淘宝镜像源`npm config set registry https://registry.npm.taobao.org` 57 | 58 | Then run the instal script as per the main README.md. 59 | 60 | 61 | refer: 62 | 1.[Nodesource 镜像使用帮助](https://mirror.tuna.tsinghua.edu.cn/help/nodesource/) 63 | 2.[淘宝 NPM 镜像](https://developer.aliyun.com/mirror/NPM?from=tnpm) 64 | 3.https://github.com/nodesource/distributions 65 | 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Linux Installers for Node-RED 2 | 3 | Both of the following commands use sudo (root) access to install Node-RED globally (and nodejs if required). You may want to inspect them first to satisfy yourself as to the actions they take. 4 | 5 | ### Debian, Ubuntu, Raspberry Pi OS 6 | 7 | The command line for installing on a Debian based OS is: 8 | 9 | ``` 10 | bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) 11 | ``` 12 | 13 | you should ensure you have the build tools installed if you are going to install extra nodes. 14 | 15 | ``` 16 | sudo apt install build-essential 17 | ``` 18 | 19 | There are lots of command line options available - add ` --help` to the end of the command above to see them all. 20 | 21 | 22 | ### Red Hat, Fedora, CentOS, Oracle Linux 23 | 24 | The command line for installing on a RPM based OS is: 25 | 26 | ``` 27 | bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/rpm/update-nodejs-and-nodered) 28 | ``` 29 | 30 | Change e.g. set the system user and open the firewall : 31 | 32 | ```bash 33 | curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/rpm/update-nodejs-and-nodered \ 34 | | bash -s --nodered-user=nodered --open-firewall 35 | ``` 36 | 37 | Command Line options: 38 | ``` 39 | --help display this help and exits. 40 | --nodered-user= specify the user to run as e.g. '--nodered-user=nodered'. 41 | --confirm-root install as root without asking confirmation. 42 | --open_firewall adding public firewall rule for node-red port 1880. 43 | --confirm-install confirm the installation without asking a confirmation. 44 | 45 | ``` 46 | 47 | Or by use of the environment variables e.g. to set service user: 48 | ```bash 49 | NODERED_USER=nodered bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/rpm/update-nodejs-and-nodered) 50 | ``` 51 | 52 | Environment variables, please note that the program command line options takes precedence: 53 | ```bash 54 | NODERED_USER=nodered 55 | OPEN_FIREWALL=y 56 | CONFIRM_ROOT=y 57 | CONFIRM_INSTALL=y 58 | ``` 59 | 60 | you should ensure you have the development tools installed if you are going to install extra nodes. 61 | 62 | ``` 63 | dnf groupinstall "Development Tools" 64 | ``` 65 | 66 | **Note**: This script will optionally add a firewall rule that adds port 1880 to the public zone. On a default install this should allow access to Node-RED from outside of the local machine. The default is not to do this. 67 | 68 | ### Pi Build 69 | 70 | The pibuild directory contains the scripts and files we use to build the pre-install .deb version of Node-RED for the Raspberry Pi. Most users should never need this as the script above is the recommended way to install and upgrade. See the [README](pibuild) in that directory for more information. 71 | -------------------------------------------------------------------------------- /deb/update-nodejs-and-nodered: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2016,2024 JS Foundation and other contributors, https://js.foundation/ 4 | # Copyright 2015,2016 IBM Corp. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | # Node-RED Installer for DEB based systems 19 | 20 | umask 0022 21 | tgta12=12.22.12 # need armv6l latest from https://unofficial-builds.nodejs.org/download/release/ 22 | tgtl12=12.16.3 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/ 23 | tgta14=14.21.3 # need armv6l latest from https://unofficial-builds.nodejs.org/download/release/ 24 | tgtl14=14.21.3 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/ 25 | tgta16=16.20.2 # need armv6l latest from https://unofficial-builds.nodejs.org/download/release/ 26 | tgtl16=16.20.2 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/ 27 | tgta18=18.20.8 # need armv6l latest from https://unofficial-builds.nodejs.org/download/release/ 28 | tgtl18=18.20.8 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/ 29 | tgta20=20.19.1 # need armv6l latest from https://unofficial-builds.nodejs.org/download/release/ 30 | tgtl20=20.19.1 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/ 31 | 32 | usage() { 33 | cat << EOL 34 | Usage: $0 [options] 35 | 36 | Options: 37 | --help display this help and exit 38 | --confirm-root install as root without asking confirmation 39 | --confirm-install confirm installation without asking confirmation 40 | --confirm-pi confirm installation of PI specific nodes without asking confirmation 41 | --skip-pi skip installing PI specific nodes without asking confirmation 42 | --restart restart service if install succeeds 43 | --allow-low-ports add capability to bind to ports below 1024 (default is disallow) 44 | --update-nodes run npm update on existing installed nodes (within scope of package.json) 45 | --no-init don't ask to initialise settings if they don't exist 46 | --on-diet bypass DietPi exit and force install Node-RED on DietPi 47 | --nodered-user specify the user to run as, useful for installing as sudo - e.g. --nodered-user=pi 48 | --nodered-version if not set, the latest version is used - e.g. --nodered-version="4.0.2" 49 | --node16 if set, forces install of major version of nodejs 16 LTS 50 | --node18 if set, forces install of major version of nodejs 18 LTS 51 | --node20 if set, forces install of major version of nodejs 20 LTS 52 | if none set, install nodejs 20 LTS if nodejs version is less than 18, 53 | otherwise leave current install 54 | 55 | Note: if you use allow-low-ports it may affect the node modules paths - see https://stackoverflow.com/a/65560687 56 | EOL 57 | } 58 | 59 | SUDO=sudo 60 | SUDOE="sudo -E" 61 | NODE_VERSION="" 62 | LOW_PORTS="n" 63 | if [ $# -gt 0 ]; then 64 | # Parsing parameters 65 | while (( "$#" )); do 66 | case "$1" in 67 | --help) 68 | usage && exit 0 69 | shift 70 | ;; 71 | --confirm-root) 72 | CONFIRM_ROOT="y" 73 | shift 74 | ;; 75 | --confirm-install) 76 | CONFIRM_INSTALL="y" 77 | shift 78 | ;; 79 | --skip-pi) 80 | CONFIRM_PI="n" 81 | shift 82 | ;; 83 | --confirm-pi) 84 | CONFIRM_PI="y" 85 | shift 86 | ;; 87 | --node12) 88 | NODE_VERSION="12" 89 | shift 90 | ;; 91 | --node14) 92 | NODE_VERSION="14" 93 | shift 94 | ;; 95 | --node16) 96 | NODE_VERSION="16" 97 | shift 98 | ;; 99 | --node18) 100 | NODE_VERSION="18" 101 | shift 102 | ;; 103 | --node20) 104 | NODE_VERSION="20" 105 | shift 106 | ;; 107 | --node22) 108 | NODE_VERSION="22" 109 | shift 110 | ;; 111 | --restart) 112 | RESTART="y" 113 | shift 114 | ;; 115 | --update-nodes) 116 | UPDATENODES="y" 117 | shift 118 | ;; 119 | --nodered-version=*) 120 | NODERED_VERSION="${1#*=}" 121 | shift 122 | ;; 123 | --nodered-user=*) 124 | NODERED_USER="${1#*=}" 125 | shift 126 | ;; 127 | --allow-low-ports) 128 | LOW_PORTS="y" 129 | shift 130 | ;; 131 | --no-init) 132 | INITSET="n" 133 | shift 134 | ;; 135 | --on-diet) 136 | ONDIET="y" 137 | shift 138 | ;; 139 | --) # end argument parsing 140 | shift 141 | break 142 | ;; 143 | -*|--*=) # unsupported flags 144 | echo "Error: Unsupported flag $1" >&2 145 | exit 1 146 | ;; 147 | esac 148 | done 149 | fi 150 | 151 | # helper function to test for existance of node and npm 152 | function HAS_NODE { 153 | if [ -x "$(command -v node)" ]; then return 0; else return 1; fi 154 | } 155 | function HAS_NPM { 156 | if [ -x "$(command -v npm)" ]; then return 0; else return 1; fi 157 | } 158 | 159 | # check for apt and systemctrl (set flags for later use and log if not found) 160 | if [ -x "$(command -v apt)" ]; then 161 | APTOK=true; 162 | else 163 | APTOK=false 164 | echo "apt not found. Node/npm install will be skipped" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 165 | fi 166 | if [ -x "$(command -v systemctl)" ]; then 167 | SYSTEMDOK=true; 168 | else 169 | SYSTEMDOK=false 170 | echo "systemctl not found. shortcuts/services setup will be skipped" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 171 | fi 172 | 173 | echo -ne "\033[2 q" 174 | if [[ -e /mnt/dietpi_userdata && "$ONDIET" != "y" ]]; then 175 | echo -ne "\n\033[1;32mDietPi\033[0m detected - only going to add the \033[0;36mnode-red-start, -stop, -log\033[0m commands.\n" 176 | echo -ne "Flow files and other things worth backing up can be found in the \033[0;36m/mnt/dietpi_userdata/node-red\033[0m directory.\n\n" 177 | echo -ne "Use the \033[0;36mdietpi-software\033[0m command to un-install and re-install \033[38;5;88mNode-RED\033[0m.\n\n" 178 | echo -ne "If you want to force install Node-RED, re-run this script with the \033[0;36m--on-diet\033[0m option.\n\n" 179 | echo "journalctl -f -n 100 -u node-red -o cat" > /usr/bin/node-red-log 180 | chmod +x /usr/bin/node-red-log 181 | echo "systemctl stop node-red" > /usr/bin/node-red-stop 182 | chmod +x /usr/bin/node-red-stop 183 | echo "systemctl start node-red" > /usr/bin/node-red-start 184 | echo "journalctl -f -n 0 -u node-red -o cat" >> /usr/bin/node-red-start 185 | chmod +x /usr/bin/node-red-start 186 | else 187 | 188 | if [[ -e /mnt/dietpi_userdata && "$ONDIET" == "y" ]]; then 189 | DIETPI="y" 190 | echo -ne "\n\033[1;32mDietPi\033[0m detected but going to force install of Node-RED.\n" 191 | echo -ne "\nThis should only be done if you DO NOT use the dietpi-software\ninstaller to set up nodejs and node-red.\n" 192 | echo -ne "\nTrying to mix both will quite probably break something - Use at your own risk.\n\n" 193 | read -t 10 -p "Are you really sure you want to force install on DietPi ? (y/N) ? " yn 194 | case $yn in 195 | [Yy]* ) 196 | ;; 197 | * ) 198 | echo " " 199 | exit 1 200 | ;; 201 | esac 202 | echo -ne "\nOK - fingers crossed.\n\n" 203 | apt install -y python3-rpi.gpio 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 204 | CONFIRM_ROOT="y" 205 | CONFIRM_INSTALL="y" 206 | CONFIRM_PI="y" 207 | fi 208 | 209 | if [ "$EUID" == "0" ]; then 210 | # if [[ $SUDO_USER != "" ]]; then 211 | echo -en "\nroot user detected. Typical installs should be done as a regular user.\r\n" 212 | echo -en "If you are running this script using sudo, please cancel and rerun without sudo.\r\n" 213 | echo -en "--nodered-user can be used to specify the user otherwise installation will happen under /root.\r\n" 214 | echo -en "If you know what you are doing as root, please continue.\r\n\r\n" 215 | 216 | yn="${CONFIRM_ROOT}" 217 | [ ! "${yn}" ] && read -t 10 -p "Are you really sure you want to install as root ? (y/N) ? " yn 218 | case $yn in 219 | [Yy]* ) 220 | NODERED_USER="root" 221 | ;; 222 | * ) 223 | echo " " 224 | exit 1 225 | ;; 226 | esac 227 | SUDO='' 228 | SUDOE='' 229 | id -u nobody &>/dev/null || adduser --no-create-home --shell /dev/null --disabled-password --disabled-login --gecos '' nobody &>/dev/null 230 | else 231 | groups "$USER" | grep -q '\bsudo\b' && GRS="Y" || GRS="N" 232 | if [[ "$GRS" == "N" ]]; then 233 | echo "User $USER not in sudoers group. Exiting" 234 | exit 1; 235 | fi 236 | fi 237 | 238 | # setup user, home and group 239 | if [[ "$NODERED_USER" == "" ]]; then 240 | NODERED_HOME=$HOME 241 | NODERED_USER=$USER 242 | NODERED_GROUP=`id -gn` 243 | else 244 | NODERED_GROUP="$NODERED_USER" 245 | NODERED_HOME="/home/$NODERED_USER" 246 | if [[ "$NODERED_USER" == "root" ]]; then 247 | NODERED_HOME="/root" 248 | fi 249 | fi 250 | SUDOU="sudo -u $NODERED_USER" 251 | 252 | if [[ "$(uname)" != "Darwin" ]]; then 253 | if curl -I https://registry.npmjs.org/@node-red/util >/dev/null 2>&1; then 254 | echo -e '\033]2;'$NODERED_USER@`hostname`: Node-RED update'\007' 255 | echo " " 256 | echo "This script checks the version of node.js installed is 16 or greater. It will try to" 257 | echo "install node 20 if none is found. It can optionally install node 18 or 20 LTS for you." 258 | echo " " 259 | echo "If necessary it will then remove the old core of Node-RED, before then installing the latest" 260 | echo "version. You can also optionally specify the version required." 261 | echo " " 262 | echo "It also tries to run 'npm rebuild' to refresh any extra nodes you have installed" 263 | echo "that may have a native binary component. While this normally works ok, you need" 264 | echo "to check that it succeeds for your combination of installed nodes." 265 | echo " " 266 | echo "To do all this it runs commands as root - please satisfy yourself that this will" 267 | echo "not damage your Pi, or otherwise compromise your configuration." 268 | echo "If in doubt please backup your SD card first." 269 | echo " " 270 | echo "See the optional parameters by re-running this command with --help" 271 | echo " " 272 | if [[ -e $NODERED_HOME/.nvm ]]; then 273 | echo -ne '\033[1mNOTE:\033[0m We notice you are using \033[38;5;88mnvm\033[0m. Please ensure it is running the current LTS version.\n' 274 | echo -ne 'Using nvm is NOT RECOMMENDED. Node-RED will not run as a service under nvm.\r\n\n' 275 | fi 276 | 277 | yn="${CONFIRM_INSTALL}" 278 | [ ! "${yn}" ] && read -p "Are you really sure you want to do this ? [y/N] ? " yn 279 | case $yn in 280 | [Yy]* ) 281 | echo "" 282 | EXTRANODES="" 283 | EXTRAW="update" 284 | 285 | response="${CONFIRM_PI}" 286 | [ ! "${response}" ] && read -r -t 15 -p "Would you like to install the Pi-specific nodes ? [y/N] ? " response 287 | if [[ "$response" =~ ^([yY])+$ ]]; then 288 | EXTRANODES="node-red-node-pi-gpio@latest node-red-node-random@latest node-red-node-ping@latest node-red-contrib-play-audio@latest node-red-node-smooth@latest node-red-node-serialport@latest node-red-contrib-buffer-parser@latest" 289 | EXTRAW="install" 290 | fi 291 | 292 | # this script assumes that $HOME is the folder of the user that runs node-red 293 | # that $NODERED_USER is the user name and the group name to use when running is the 294 | # primary group of that user 295 | # if this is not correct then edit the lines below 296 | MYOS=$(cat /etc/os-release | grep "^ID=" | cut -d = -f 2 | tr -d '"') 297 | GLOBAL="true" 298 | TICK='\033[1;32m\u2714\033[0m' 299 | CROSS='\033[1;31m\u2718\033[0m' 300 | cd "$NODERED_HOME" || exit 1 301 | clear 302 | echo -e "\nRunning Node-RED $EXTRAW for user $NODERED_USER at $NODERED_HOME on $MYOS\n" 303 | 304 | nv=0 305 | # nv2="" 306 | nv2=`dpkg -s nodejs 2>/dev/null | grep Version | cut -d ' ' -f 2` 307 | nrv=`echo $NODERED_VERSION | cut -d "." -f1` 308 | 309 | if [[ "$APTOK" == "false" ]]; then 310 | if HAS_NODE && HAS_NPM; then 311 | : # node and npm is installed, we can continue :) 312 | else 313 | if HAS_NODE; then :; else echo -en "\b$CROSS MISSING: nodejs\r\n"; fi 314 | if HAS_NPM; then :; else echo -en "\b$CROSS MISSING: npm\r\n"; fi 315 | echo -en "\b$CROSS MISSING: apt" 316 | echo -e "\r\n\r\nThis script uses apt to install nodejs and npm.\n" 317 | echo -e "You can install nodejs and npm manually then run the script again to continue.\r\n\r\n" 318 | exit 2 319 | fi 320 | fi 321 | 322 | if [[ "$APTOK" == "true" ]]; then 323 | ndeb=$(apt-cache policy nodejs | grep Installed | awk '{print $2}') 324 | fi 325 | if HAS_NODE && HAS_NPM; then 326 | nv=`node -v | cut -d "." -f1 | cut -d "v" -f2` 327 | nvs=`node -v | cut -d "." -f2` 328 | # nv2=`node -v` 329 | # nv2=`apt list nodejs 2>/dev/null | grep dfsg | cut -d ' ' -f 2 | cut -d '-' -f 1` 330 | echo "Already have nodejs $nv2" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 331 | fi 332 | # ensure ~/.config dir is owned by the user 333 | $SUDO chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.config/ 334 | 335 | echo "OLD nodejs "$nv" :" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 336 | echo "NEW nodejs "$NODE_VERSION" :" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 337 | # If older than version of 12.17 then force it to update to support es modules 338 | if [[ "$nv" -eq 12 && "$nvs" -lt 17 ]]; then 339 | nv=0 340 | NODE_VERSION="12" 341 | fi 342 | 343 | if [[ "$nv" -lt 18 && "$nv" -ne 0 && "$nrv" != 1 ]]; then 344 | if [[ "$NODE_VERSION" == "" ]]; then 345 | echo "Nodejs $nv too old and new version not specified - exiting" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 346 | echo "Node-RED v3.x no longer supports Nodejs $nv " 347 | # echo " Node-RED v2 no longer supports Nodejs $nv. Please update." 348 | # echo " " 349 | # echo " You can use the old v1 branch by specifying --nodered-version=1.*" 350 | echo " " 351 | echo " You can force an install of node 18 or 20 by adding --node18 or --node20 to the end of the command line above." 352 | echo " However doing so may break some nodes that may need re-installing manually." 353 | echo " Generally it is recommended to update all nodes to their latest versions before upgrading." 354 | echo " " 355 | echo " If you wish to stay on nodejs $nv you can update to the latest Node-RED 1.x or 2.x version by adding" 356 | echo ' --nodered-version="1.3.7" or --nodered-version="2.2.2" to that install command. If in doubt this is the safer option.' 357 | if [[ "$npv" != "" ]]; then 358 | echo "Checking for outdated nodes in $PWD" 359 | npm --silent outdated 360 | echo " " 361 | fi 362 | echo " Please backup your installation and flows before upgrading." 363 | echo " " 364 | if ! $SUDO grep -q Raspberry /proc/cpuinfo; then 365 | echo " Note: not all embedded hardware can be updated via this method - please check before proceeding." 366 | echo " " 367 | fi 368 | echo " Exiting now." 369 | exit 2 370 | fi 371 | echo "Installing nodejs "$NODE_VERSION" over "$nv" ." | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 372 | fi 373 | 374 | time1=$(date) 375 | echo "" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 376 | echo "***************************************" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 377 | echo "" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 378 | echo "Started : "$time1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 379 | echo "Running for user $NODERED_USER at $NODERED_HOME" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 380 | echo -ne '\r\nThis can take 20-30 minutes on the slower Pi versions - please wait.\r\n\n' 381 | echo -ne ' Stop Node-RED \r\n' 382 | echo -ne ' Remove old version of Node-RED \r\n' 383 | echo -ne ' Remove old version of Node.js \r\n' 384 | echo -ne ' Install Node.js \r\n' 385 | echo -ne ' Clean npm cache \r\n' 386 | echo -ne ' Install Node-RED core \r\n' 387 | echo -ne ' Move global nodes to local \r\n' 388 | echo -ne ' Npm rebuild existing nodes \r\n' 389 | echo -ne ' Install extra Pi nodes \r\n' 390 | echo -ne ' Add shortcut commands \r\n' 391 | echo -ne ' Update systemd script \r\n' 392 | echo -ne ' \r\n' 393 | echo -ne '\r\nAny errors will be logged to /var/log/nodered-install.log\r\n' 394 | echo -ne '\033[14A' 395 | 396 | # stop any running node-red service 397 | if $SUDO service nodered stop 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null ; then CHAR=$TICK; else CHAR=$CROSS; fi 398 | echo -ne " Stop Node-RED $CHAR\r\n" 399 | 400 | # save any global nodes 401 | GLOBALNODES=$(find /usr/local/lib/node_modules/node-red-* -maxdepth 0 -type d -printf '%f\n' 2>/dev/null) 402 | GLOBALNODES="$GLOBALNODES $(find /usr/lib/node_modules/node-red-* -maxdepth 0 -type d -printf '%f\n' 2>/dev/null)" 403 | echo "Found global nodes: $GLOBALNODES :" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 404 | 405 | # remove any old node-red installs or files 406 | if [[ "$APTOK" == "true" ]]; then 407 | $SUDO apt remove -y nodered 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 408 | fi 409 | # sudo apt remove -y node-red-update 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 410 | $SUDO rm -rf /usr/local/lib/node_modules/node-red* /usr/local/lib/node_modules/npm /usr/local/bin/node-red* /usr/local/bin/node /usr/local/bin/npm 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 411 | $SUDO rm -rf /usr/lib/node_modules/node-red* /usr/bin/node-red* 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 412 | echo -ne ' Remove old version of Node-RED \033[1;32m\u2714\033[0m\r\n' 413 | 414 | if [[ "$APTOK" == "false" ]]; then 415 | echo -ne " Node option not possible : Skipped - apt not found\n" 416 | echo -ne " Leave existing Node.js :" 417 | elif [[ "$NODE_VERSION" == "" && "$nv" -ne 0 ]]; then 418 | CHAR="-" 419 | echo -ne " Node option not specified : --node18 or --node20\n" 420 | echo -ne " Leave existing Node.js :" 421 | else 422 | if [[ "$NODE_VERSION" == "12" ]]; then 423 | tgtl=$tgtl12 424 | tgta=$tgta12 425 | elif [[ "$NODE_VERSION" == "14" ]]; then 426 | tgtl=$tgtl14 427 | tgta=$tgta14 428 | elif [[ "$NODE_VERSION" == "16" ]]; then 429 | tgtl=$tgtl16 430 | tgta=$tgta16 431 | elif [[ "$NODE_VERSION" == "18" ]]; then 432 | tgtl=$tgtl18 433 | tgta=$tgta18 434 | elif [[ "$NODE_VERSION" == "20" ]]; then 435 | tgtl=$tgtl20 436 | tgta=$tgta20 437 | elif [[ "$NODE_VERSION" == "22" ]]; then 438 | tgtl="None" 439 | tgta="None" 440 | else 441 | tgtl=$tgtl20 442 | tgta=$tgta20 443 | NODE_VERSION="20" 444 | fi 445 | # maybe remove Node.js - or upgrade if nodesource.list exists 446 | if [[ -d $NODERED_HOME/.nvm ]]; then 447 | GLOBAL="false" 448 | echo -ne ' Using NVM to manage Node.js + please run \033[0;36mnvm use lts\033[0m before running Node-RED\r\n' 449 | echo -ne ' NOTE: Using nvm is NOT RECOMMENDED. Node-RED will not run as a service under nvm.\r\n' 450 | export NVM_DIR=$NODERED_HOME/.nvm 451 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm 452 | echo "Using NVM !!! $(nvm current)" 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 453 | nvm install $NODE_VERSION --no-progress --latest-npm >/dev/null 2>&1 454 | nvm use $NODE_VERSION >/dev/null 2>&1 455 | nvm alias default $NODE_VERSION >/dev/null 2>&1 456 | echo "Now using --- $(nvm current)" 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 457 | ln -f -s $NODERED_HOME/.nvm/versions/node/$(nvm current)/lib/node_modules/node-red/red.js $NODERED_HOME/node-red 458 | echo -ne " Update Node.js $NODE_VERSION $CHAR - Using nvm is NOT recommended/supported." 459 | elif [[ $(which n) ]]; then 460 | echo "Using n" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 461 | echo -ne " Using N to manage Node.js +\r\n" 462 | echo -ne ' NOTE: Using n is NOT RECOMMENDED. Please use a standard nodejs install.\r\n' 463 | if $SUDO n $NODE_VERSION 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 464 | echo -ne " Update Node.js $NODE_VERSION $CHAR - Using n is NOT recommended/supported." 465 | elif [[ "$(uname -m)" =~ "i686" ]] || [[ "$(uname -m)" =~ "x86_64" && "$(getconf LONG_BIT)" =~ "32" ]]; then 466 | echo "Using 32bit nodejs" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 467 | if [[ "$tgtl" != "None" ]]; then 468 | curl -sSL -o /tmp/node.tgz https://unofficial-builds.nodejs.org/download/release/v$tgtl/node-v$tgtl-linux-x86.tar.gz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 469 | # unpack it into the correct places 470 | hd=$(head -c 9 /tmp/node.tgz) 471 | if [ "$hd" == "" ]; then 472 | CHAR="$CROSS File $f not downloaded"; 473 | else 474 | if [[ -d /tmp/nodejs ]]; then 475 | $SUDO rm -rf /tmp/nodejs 476 | fi 477 | mkdir -p /tmp/nodejs 478 | $SUDO tar -zxof /tmp/node.tgz --strip-components=1 -C /tmp/nodejs 479 | $SUDO chown -R 0:0 /tmp/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 480 | if $SUDO cp -PR /tmp/nodejs/* /usr/ 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 481 | $SUDO rm -rf /tmp/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 482 | # if $SUDO tar -zxof /tmp/node.tgz --strip-components=1 -C /usr 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 483 | fi 484 | rm /tmp/node.tgz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 485 | echo -ne " Install Node.js for i686 $CHAR" 486 | else 487 | echo -ne " Nodejs "$tgtl" for i686 does not exist $CROSS" 488 | fi 489 | elif uname -m | grep -q armv6l ; then 490 | if [[ "$tgta" != "None" ]]; then 491 | $SUDO apt remove -y nodejs nodejs-legacy npm 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 492 | $SUDO rm -rf /etc/apt/sources.d/nodesource.list /usr/lib/node_modules/npm* 493 | echo -ne " Remove old version of Node.js $TICK $nv2\r\n" 494 | echo -ne " Install Node.js for Armv6 \r" 495 | # f=$(curl -sL https://nodejs.org/download/release/latest-dubnium/ | grep "armv6l.tar.gz" | cut -d '"' -f 2) 496 | # curl -sL -o node.tgz https://nodejs.org/download/release/latest-dubnium/$f 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 497 | curl -sSL -o /tmp/node.tgz https://unofficial-builds.nodejs.org/download/release/v$tgta/node-v$tgta-linux-armv6l.tar.gz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 498 | # unpack it into the correct places 499 | hd=$(head -c 6 /tmp/node.tgz) 500 | if [ "$hd" == "" ]; then 501 | CHAR="$CROSS File $f not downloaded"; 502 | else 503 | if [[ -d /tmp/nodejs ]]; then 504 | $SUDO rm -rf /tmp/nodejs 505 | fi 506 | mkdir -p /tmp/nodejs 507 | $SUDO tar -zxof /tmp/node.tgz --strip-components=1 -C /tmp/nodejs 508 | $SUDO chown -R 0:0 /tmp/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 509 | if $SUDO cp -PR /tmp/nodejs/* /usr/ 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 510 | $SUDO rm -rf /tmp/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 511 | fi 512 | # remove the tgz file to save space 513 | rm /tmp/node.tgz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 514 | echo -ne " Install Node.js for Armv6 $CHAR" 515 | else 516 | echo -ne " Nodejs "$tgta" for Armv6 does not exist $CROSS" 517 | fi 518 | else 519 | echo "Installing nodejs $NODE_VERSION" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 520 | # clean out old nodejs stuff 521 | npv=$(npm -v 2>/dev/null | head -n 1 | cut -d "." -f1) 522 | $SUDO apt remove -y nodejs nodejs-legacy npm 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 523 | $SUDO dpkg -r nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 524 | $SUDO dpkg -r node 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 525 | $SUDO rm -rf /opt/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 526 | $SUDO rm -rf /usr/local/lib/nodejs* 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 527 | $SUDO rm -f /usr/local/bin/node* 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 528 | $SUDO rm -rf /usr/local/bin/npm* /usr/local/bin/npx* /usr/lib/node_modules/npm* 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 529 | if [ "$npv" = "1" ]; then 530 | $SUDO rm -rf /usr/local/lib/node_modules/node-red* /usr/lib/node_modules/node-red* 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 531 | fi 532 | $SUDO apt -y autoremove 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 533 | $SUDO rm -rf /etc/apt/sources.list.d/nodesource.list 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 534 | $SUDO rm -rf /etc/apt/keyrings/nodesource.gpg 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 535 | echo -ne " Remove old version of Node.js \033[1;32m\u2714\033[0m $nv2\r\n" 536 | echo "Grab the LTS bundle" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 537 | echo -ne " Install Node.js $NODE_VERSION LTS \r" 538 | 539 | # block debian nodejs install 540 | echo "Package: nodejs" | $SUDO tee /etc/apt/preferences.d/nodejs.pref >>/dev/null 541 | echo "Pin: release a=stable-security" | $SUDO tee -a /etc/apt/preferences.d/nodejs.pref >>/dev/null 542 | echo "Pin-Priority: -1" | $SUDO tee -a /etc/apt/preferences.d/nodejs.pref >>/dev/null 543 | 544 | # use the official script to install for other debian platforms 545 | $SUDO apt install -y ca-certificates curl gnupg 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 546 | $SUDO mkdir -p /etc/apt/keyrings 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 547 | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | $SUDOE gpg --batch --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 548 | # curl -sSL https://deb.nodesource.com/setup_$NODE_VERSION.x | $SUDOE bash - 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 549 | echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_VERSION.x nodistro main" | $SUDOE tee -a /etc/apt/sources.list.d/nodesource.list >>/dev/null 550 | $SUDO apt-get update 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 551 | if $SUDO apt install -y nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 552 | nov2=$(dpkg -s nodejs | grep Version | cut -d ' ' -f 2) 553 | echo -ne " Install Node $nov2 $CHAR" 554 | # echo -ne " Install Node.js $NODE_VERSION LTS $CHAR" 555 | fi 556 | fi 557 | 558 | NUPG=$CHAR 559 | hash -r 560 | rc="" 561 | if nov=$(node -v 2>/dev/null); then :; else rc="ERR"; fi 562 | if npv=$(npm -v 2>/dev/null); then :; else rc="ERR"; fi 563 | if [[ "$npv" == "" ]]; then npv="missing"; fi 564 | if [[ "$nov" == "" ]]; then nov="missing"; fi 565 | 566 | echo -ne "\nVersions: node:$nov npm:$npv\n" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 567 | if [[ "$rc" == "" ]]; then 568 | echo -ne " $nov Npm $npv\r\n" 569 | else 570 | echo -ne "\b$CROSS Bad install: Node.js $nov Npm $npv - Exit\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" 571 | exit 2 572 | fi 573 | if [ "$EUID" == "0" ]; then npm config set unsafe-perm true &>/dev/null; fi 574 | 575 | # clean up the npm cache and node-gyp 576 | if [[ "$NUPG" == "$TICK" ]]; then 577 | if [[ "$GLOBAL" == "true" ]]; then 578 | $SUDO npm cache clean --force 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 579 | else 580 | npm cache clean --force 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 581 | fi 582 | if $SUDO rm -rf "$NODERED_HOME/.node-gyp" "$NODERED_HOME/.npm" /root/.node-gyp /root/.npm; then CHAR=$TICK; else CHAR=$CROSS; fi 583 | fi 584 | echo -ne " Clean npm cache $CHAR\r\n" 585 | 586 | # and install Node-RED 587 | echo "Now install Node-RED $NODERED_VERSION" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 588 | 589 | NODERED_VERSION_SELECTION="" 590 | if [ -z ${NODERED_VERSION} ]; then 591 | NODERED_VERSION_SELECTION="latest" 592 | else 593 | NODERED_VERSION_SELECTION=${NODERED_VERSION} 594 | fi 595 | 596 | if [[ "$GLOBAL" == "true" ]]; then 597 | $SUDO npm i -g --unsafe-perm --no-progress --no-update-notifier --no-audit --no-fund --loglevel=error node-red@"$NODERED_VERSION_SELECTION" 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; nri=${PIPESTATUS[0]} 598 | if [[ $nri -eq 0 ]]; then CHAR=$TICK; else CHAR=$CROSS; fi 599 | else 600 | npm i -g --unsafe-perm --no-progress --no-update-notifier --no-audit --no-fund --loglevel=error node-red@"$NODERED_VERSION_SELECTION" 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; nri=${PIPESTATUS[0]} 601 | if [[ $nri -eq 0 ]]; then CHAR=$TICK; else CHAR=$CROSS; fi 602 | fi 603 | nrv=$(npm -g --no-progress --no-update-notifier --no-audit --no-fund --loglevel=error ls node-red | grep node-red | cut -d '@' -f 2 | $SUDO tee -a /var/log/nodered-install.log) >>/dev/null 2>&1 604 | echo -ne " Install Node-RED core $CHAR $nrv\r\n" 605 | 606 | # install any nodes, that were installed globally, as local instead 607 | echo "Now create basic package.json for the user and move any global nodes" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 608 | mkdir -p "$NODERED_HOME/.node-red/node_modules" 609 | $SUDO chown $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red 2>&1 >>/dev/null 610 | $SUDO chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red/node_modules 2>&1 >>/dev/null 611 | # Make it more secure by making settings owned by root and removing nopasswd file for default user. 612 | # $SUDO chown -Rf 0:0 $NODERED_HOME/.node-red/settings.js 2>&1 >>/dev/null 613 | # $SUDO rm -f /etc/sudoers.d/010_pi-nopasswd 614 | pushd "$NODERED_HOME/.node-red" 2>&1 >>/dev/null 615 | npm config set update-notifier false 2>&1 >>/dev/null 616 | # npm config set color false 2>&1 >>/dev/null 617 | if [ ! -f "package.json" ]; then 618 | echo '{' > package.json 619 | echo ' "name": "node-red-project",' >> package.json 620 | echo ' "description": "initially created for you by Node-RED '$nrv'",' >> package.json 621 | echo ' "version": "0.0.1",' >> package.json 622 | echo ' "private": true,' >> package.json 623 | echo ' "dependencies": {' >> package.json 624 | echo ' }' >> package.json 625 | echo '}' >> package.json 626 | fi 627 | CHAR="-" 628 | if [[ $GLOBALNODES != " " ]]; then 629 | if npm i --unsafe-perm --save --no-progress --no-update-notifier --no-audit --no-fund $GLOBALNODES 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 630 | fi 631 | echo -ne " Move global nodes to local $CHAR\r\n" 632 | 633 | # try to rebuild any already installed nodes 634 | CHAR="-" 635 | if [[ "$NUPG" == "$TICK" ]]; then 636 | echo -ne "Running npm rebuild\r\n" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 637 | if npm rebuild --no-progress --no-update-notifier --no-fund 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 638 | echo -ne " Npm rebuild existing nodes $CHAR\r" 639 | else 640 | echo -ne " Leave existing nodes -\r" 641 | fi 642 | if [[ "$UPDATENODES" == "y" ]]; then 643 | echo -ne "Running npm update\r\n" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 644 | echo -ne " Npm update existing nodes " 645 | if npm update --no-progress --no-update-notifier --no-fund 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 646 | echo -ne "$CHAR\r" 647 | fi 648 | echo -ne "\n" 649 | 650 | CHAR="-" 651 | if [[ ! -z $EXTRANODES ]]; then 652 | echo "Installing extra nodes: $EXTRANODES :" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 653 | if npm i --unsafe-perm --save --no-progress --no-update-notifier --no-audit --no-fund $EXTRANODES 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 654 | fi 655 | echo -ne " Install extra Pi nodes $CHAR\r\n" 656 | 657 | # If armv6 then remove the bcrypt binary to workaround illegal instruction error 658 | if uname -m | grep -q armv6l ; then 659 | $SUDO rm -rf /usr/lib/node_modules/node-red/node_modules/@node-rs | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 660 | fi 661 | 662 | popd 2>&1 >>/dev/null 663 | if [ -d "$NODERED_HOME/.npm" ]; then 664 | $SUDO chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.npm 2>&1 >>/dev/null 665 | fi 666 | 667 | if [[ "$SYSTEMDOK" == "true" ]]; then 668 | # add the shortcut and start/stop/log scripts to the menu 669 | echo "Now add the shortcut and start/stop/log scripts to the menu" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 670 | $SUDO mkdir -p /usr/bin 671 | if $SUDO curl -m 60 -f https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-icon.svg >/dev/null 2>&1; then 672 | $SUDO curl -sL -m 60 -o /usr/bin/node-red-start https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-start 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 673 | $SUDO curl -sL -m 60 -o /usr/bin/node-red-stop https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-stop 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 674 | $SUDO curl -sL -m 60 -o /usr/bin/node-red-restart https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-restart 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 675 | $SUDO curl -sL -m 60 -o /usr/bin/node-red-reload https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-reload 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 676 | $SUDO curl -sL -m 60 -o /usr/bin/node-red-log https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-log 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 677 | $SUDO curl -sL -m 60 -o /etc/logrotate.d/nodered https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.rotate 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 678 | $SUDO chmod +x /usr/bin/node-red-start 679 | $SUDO chmod +x /usr/bin/node-red-stop 680 | $SUDO chmod +x /usr/bin/node-red-restart 681 | $SUDO chmod +x /usr/bin/node-red-reload 682 | $SUDO chmod +x /usr/bin/node-red-log 683 | $SUDO curl -sL -m 60 -o /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-icon.svg 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 684 | $SUDO curl -sL -m 60 -o /usr/share/applications/Node-RED.desktop https://raw.githubusercontent.com/node-red/linux-installers/master/resources/Node-RED.desktop 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 685 | echo -ne " Add shortcut commands $TICK\r\n" 686 | else 687 | echo -ne " Add shortcut commands $CROSS\r\n" 688 | fi 689 | 690 | # add systemd script and configure it for $NODERED_USER 691 | echo "Now add systemd script and configure it for $NODERED_USER:$NODERED_GROUP @ $NODERED_HOME" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 692 | 693 | # check if systemd script already exists 694 | SYSTEMDFILE="/lib/systemd/system/nodered.service" 695 | 696 | if $SUDO curl -sL -m 60 -o ${SYSTEMDFILE}.temp https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 697 | # set the memory, User Group and WorkingDirectory in nodered.service 698 | if [ $(cat /proc/meminfo | grep MemTotal | cut -d ":" -f 2 | cut -d "k" -f 1 | xargs) -lt 894000 ]; then mem="256"; else mem="512"; fi 699 | if [ $(cat /proc/meminfo | grep MemTotal | cut -d ":" -f 2 | cut -d "k" -f 1 | xargs) -gt 1894000 ]; then mem="1024"; fi 700 | if [ $(cat /proc/meminfo | grep MemTotal | cut -d ":" -f 2 | cut -d "k" -f 1 | xargs) -gt 3894000 ]; then mem="2048"; fi 701 | 702 | $SUDO sed -i 's#=512#='$mem'#;' ${SYSTEMDFILE}.temp 703 | $SUDO sed -i 's#^User=.*#User='$NODERED_USER'#;s#^Group=.*#Group='$NODERED_GROUP'#;s#^WorkingDirectory=.*#WorkingDirectory='$NODERED_HOME'#;s#^EnvironmentFile=-.*#EnvironmentFile=-'$NODERED_HOME'/.node-red/environment#;' ${SYSTEMDFILE}.temp 704 | 705 | if test -f "$SYSTEMDFILE"; then 706 | # there's already a systemd script 707 | EXISTING_FILE=$(md5sum $SYSTEMDFILE | awk '$1 "${SYSTEMDFILE}" {print $1}'); 708 | TEMP_FILE=$(md5sum ${SYSTEMDFILE}.temp | awk '$1 "${SYSTEMDFILE}.temp" {print $1}'); 709 | 710 | if [[ $EXISTING_FILE == $TEMP_FILE ]]; 711 | then 712 | : # silent procedure 713 | else 714 | echo "Customized systemd script found @ $SYSTEMDFILE. To prevent loss of modifications, we will not recreate the systemd script." | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 715 | echo "If you want the installer to recreate the systemd script, please delete or rename the current script & re-run the installer." | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 716 | CHAR="- Skipped - existing script is customized." 717 | fi 718 | $SUDO rm ${SYSTEMDFILE}.temp 719 | else 720 | $SUDO mv ${SYSTEMDFILE}.temp $SYSTEMDFILE 721 | fi 722 | 723 | $SUDO systemctl daemon-reload 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 724 | echo -ne " Update systemd script $CHAR\r\n" 725 | else 726 | echo -ne " Add shortcut commands : Skipped - systemd not found\r\n" 727 | echo -ne " Update systemd script : Skipped - systemd not found\r\n" 728 | fi 729 | $SUDO ln -s $(which python3) /usr/bin/python 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 730 | 731 | # remove unneeded large sentiment library to save space and load time 732 | $SUDO rm -f /usr/lib/node_modules/node-red/node_modules/multilang-sentiment/build/output/build-all.json 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 733 | # on LXDE add launcher to top bar, refresh desktop menu 734 | pfile=/home/$NODERED_USER/.config/lxpanel/LXDE-pi/panels/panel 735 | if [ -e $pfile ]; then 736 | if ! grep -q "Node-RED" $pfile; then 737 | mat="lxterminal.desktop" 738 | ins="lxterminal.desktop\n }\n Button {\n id=Node-RED.desktop" 739 | $SUDO sed -i "s|$mat|$ins|" $pfile 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 740 | if xhost >& /dev/null ; then 741 | export DISPLAY=:0 && lxpanelctl restart 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 742 | fi 743 | fi 744 | fi 745 | 746 | # on Pi, add launcher to top bar, add cpu temp example, make sure ping works 747 | echo "Now add launcher to top bar, add cpu temp example, make sure ping works" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 748 | if $SUDO grep -q Raspberry /proc/cpuinfo; then 749 | # $SUDO setcap cap_net_raw+eip $(eval readlink -f `which node`) 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 750 | $SUDO adduser $NODERED_USER gpio 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 751 | FAM=$(cat /etc/issue | cut -d ' ' -f 1) 752 | ISS=$(cat /etc/issue | cut -d '/' -f 2 | cut -d ' ' -f 2) 753 | if [[ "$FAM" == *"bian" ]]; then 754 | if [ $ISS -gt 11 ] && [ "$DIETPI" != "y" ]; then 755 | echo "Replace old rpi.gpio with lgpio" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 756 | $SUDO apt purge -y python3-rpi.gpio 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 757 | $SUDO apt install -y python3-pip 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 758 | $SUDO pip3 install --break-system-packages rpi-lgpio 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 759 | else 760 | echo "Leaving old rpi.gpio" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 761 | $SUDO apt install -y python3-rpi.gpio 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 762 | fi 763 | fi 764 | fi 765 | $SUDO setcap cap_net_raw=ep /bin/ping 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 766 | 767 | echo "Allow binding to low ports : $LOW_PORTS" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 768 | if [[ "$LOW_PORTS" == "y" ]] ; then 769 | $SUDO setcap cap_net_bind_service=+ep $(eval readlink -f `which node`) 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 770 | fi 771 | 772 | echo -ne "\r\n\r\n\r\n" 773 | echo -ne "All done.\r\n" 774 | if [[ "$RESTART" == "y" ]]; then 775 | echo -ne "\033[1mRestarting \033[38;5;88mNode-RED\033[0m service\r\n" 776 | $SUDO systemctl restart nodered 777 | echo -ne "\033[1mRestarted \033[38;5;88mNode-RED\033[0m\r\n" 778 | else 779 | if [[ "$GLOBAL" == "true" ]] ; then 780 | if [[ "$SYSTEMDOK" == "true" ]]; then 781 | echo -ne "You can now start Node-RED with the command \033[0;36mnode-red-start\033[0m\r\n" 782 | echo -ne " or using the icon under Menu / Programming / Node-RED\r\n" 783 | else 784 | echo -ne "You can now start Node-RED with the command \033[0;36mnode-red\033[0m\r\n" 785 | fi 786 | else 787 | echo -ne "You can now start Node-RED with the command \033[0;36m./node-red\033[0m\r\n" 788 | fi 789 | fi 790 | echo -ne "Then point your browser to \033[0;36mlocalhost:1880\033[0m or \033[0;36mhttp://{your_pi_ip-address}:1880\033[0m\r\n" 791 | echo -ne "\r\n" 792 | if free -h -t >/dev/null 2>&1; then 793 | echo "Memory : $(free -h -t | grep Total | awk '{print $2}' | cut -d i -f 1)" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 794 | else 795 | echo "Mem : $(free -m | grep Mem | awk '{print $2}' | cut -d i -f 1)Mb" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 796 | echo "Swap : $(free -m | grep Swap | awk '{print $2}' | cut -d i -f 1)Mb" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null 797 | fi 798 | echo "Started : $time1 " | $SUDO tee -a /var/log/nodered-install.log 799 | echo "Finished: $(date)" | $SUDO tee -a /var/log/nodered-install.log 800 | 801 | file=/home/$NODERED_USER/.node-red/settings.js 802 | if [[ "$NODERED_USER" == "root" ]]; then 803 | file=/root/.node-red/settings.js 804 | fi 805 | if [ ! -f $file ]; then 806 | echo " " 807 | elif ! diff -q /usr/lib/node_modules/node-red/settings.js $file &>/dev/null 2>&1 ; then 808 | echo " " 809 | echo "Just FYI : Your settings.js file is different from the latest defaults." 810 | echo "You may wish to run" 811 | echo " diff -y --suppress-common-lines /usr/lib/node_modules/node-red/settings.js $file" 812 | echo "to compare them and see what the latest options are." 813 | echo " " 814 | fi 815 | 816 | echo "**********************************************************************************" 817 | echo " ### WARNING ###" 818 | echo " DO NOT EXPOSE NODE-RED TO THE OPEN INTERNET WITHOUT SECURING IT FIRST" 819 | echo " " 820 | echo " Even if your Node-RED doesn't have anything valuable, (automated) attacks will" 821 | echo " happen and could provide a foothold in your local network" 822 | echo " " 823 | echo " Follow the guide at https://nodered.org/docs/user-guide/runtime/securing-node-red" 824 | echo " to setup security." 825 | echo " " 826 | echo " ### ADDITIONAL RECOMMENDATIONS ###" 827 | if [ -f /etc/sudoers.d/010_pi-nopasswd ]; then 828 | echo " - Remove the /etc/sudoers.d/010_pi-nopasswd file to require entering your password" 829 | echo " when performing any sudo/root commands:" 830 | echo " " 831 | echo " sudo rm -f /etc/sudoers.d/010_pi-nopasswd" 832 | echo " " 833 | fi 834 | if [ ! -f $file ]; then 835 | echo " - You can customise the initial settings by running:" 836 | echo " " 837 | echo " node-red admin init" 838 | echo " " 839 | # echo " - After running Node-RED for the first time, change the ownership of the settings" 840 | # echo " file to 'root' to prevent unauthorised changes:" 841 | # echo " " 842 | # echo " sudo chown root:root ~/.node-red/settings.js" 843 | # echo " " 844 | # elif ! [[ $(stat --format '%G' ~/.node-red/settings.js) = "root" ]]; then 845 | # echo " - Change the ownership of its settings file to 'root' to prevent unauthorised changes:" 846 | # echo "" 847 | # echo " sudo chown root:root ~/.node-red/settings.js" 848 | # echo " " 849 | fi 850 | if [ "$EUID" == "0" ]; then 851 | echo " - Do not run Node-RED as root or an administraive account" 852 | echo " " 853 | fi 854 | echo "**********************************************************************************" 855 | echo " " 856 | if [ ! -f $file ]; then 857 | initset="${INITSET}" 858 | # [ ! "${INITSET}" ] && read -t 60 -p " Would you like to customise the settings now (y/N) ? " initset 859 | case $initset in 860 | [Yy]* ) 861 | export HOSTIP=`hostname -I | cut -d ' ' -f 1` 862 | $SUDO chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red 2>&1 >>/dev/null 863 | $SUDOU /usr/bin/node-red admin init 864 | # $SUDO chown 0:0 $file 865 | ;; 866 | [Nn]* ) 867 | echo "Settings not initialized." 868 | exit 0 869 | ;; 870 | * ) 871 | # echo " " 872 | # exit 1 873 | $SUDO chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red/ 2>&1 >>/dev/null 874 | $SUDOU /usr/bin/node-red admin init 875 | # $SUDO chown 0:0 $file 876 | ;; 877 | esac 878 | fi 879 | ;; 880 | * ) 881 | echo " " 882 | exit 1 883 | ;; 884 | esac 885 | else 886 | echo " " 887 | echo "Sorry - cannot connect to internet - not going to touch anything." 888 | echo "https://www.npmjs.com/package/node-red is not reachable." 889 | echo "Please ensure you have a working internet connection." 890 | echo "Return code from curl is "$? 891 | echo " " 892 | exit 1 893 | fi 894 | else 895 | echo " " 896 | echo "Sorry - I'm not supposed to be run on a Mac." 897 | echo "Please see the documentation at http://nodered.org/docs/getting-started/upgrading." 898 | echo " " 899 | exit 1 900 | fi 901 | fi 902 | -------------------------------------------------------------------------------- /pibuild/README.md: -------------------------------------------------------------------------------- 1 | # Build .deb package for Pi. 2 | 3 | Scripts required for the project to build the Node-RED deb package for the Raspbian software repository. Regular users can get the deb from the Raspbian repository using apt if required though we recommend the install script. 4 | 5 | - The last prebuilt deb version of Node-RED for Jessie was 0.15.3. 6 | - The last prebuilt deb version of Node-RED for Stretch was 0.20.8. 7 | 8 | **WARNING**: If you already have Node-RED installed **do not** run this *just for fun*. It will probably break your existing install. 9 | 10 | Only run it on a clean Raspbian Stretch SD card running in a Raspberry Pi Arm6 model - 11 | that way it will include the correct instruction set for other Arm6 type Pi (Original 12 | A and B models) and yet be forwards compatible with the Arm7 versions (Pi2, 3 etc). 13 | 14 | Transfer all the files from this project to the Pi. 15 | 16 | git clone https://github.com/node-red/linux-installers.git 17 | cd linux-installers/pibuild 18 | 19 | Then run the two scripts below 20 | 21 | ### node-red-pi-install.sh 22 | 23 | You should only run this script once. 24 | 25 | Firstly it does an apt-get update and installs node.js and npm. 26 | 27 | It then npm installs the latest Node-RED from npm. This can take 20-30 mins on a Pi 1. 28 | 29 | It also installs a few useful extra nodes. 30 | 31 | Then it removes a load of crud files from all the installed dependancies - 32 | such as test, doc, samples, examples and so on. 33 | 34 | Finally we install the icon file, init scripts, and desktop file. 35 | 36 | Once this finishes the Pi should be able to run Node-RED and have an icon under 37 | menu - programming 38 | 39 | ### node-red-deb-pack.sh 40 | 41 | The deb package version number is set at the top of this script. Edit as necessary. 42 | 43 | Next run this script - it also cleans up the crud just to be sure... then packs 44 | all the files and unpacks them into a directory in `/tmp/` 45 | 46 | It then moves files from `/usr/local/...` to `/usr/...` as required for pre-installed applications, and adds the necessary `DEBIAN/control` file. 47 | 48 | Finally it builds the actual deb file - moves it back in to the `/home/pi` directory and then runs `lintian` to report all the violations. 49 | 50 | Don't worry - there are loads ! so to trim then down to what I consider actually relevant try running 51 | 52 | cat lint.log | grep E: | grep -v '\.node' 53 | 54 | for the Errors - and 55 | 56 | cat lint.log | grep W: | grep -v '!node' | grep -v 'extra' | grep -v "image" | grep -v "please" | grep -v "not-executable" | grep -v '\.node' 57 | 58 | for the warnings. 59 | 60 | Move or Copy the `nodered_x.y.z.deb` file as required. 61 | 62 | ### Notes 63 | 64 | Both these scripts could be run as one. Though while messing around it made more sense to do the install once and then re-pack as many times as necessary. 65 | -------------------------------------------------------------------------------- /pibuild/node-red-deb-pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2016,2022 OpenJS Foundation and other contributors, https://openjsf.org/ 4 | # Copyright 2015,2016 IBM Corp. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | echo "" 19 | VER=$(node-red -? | grep RED | cut -d "v" -f 2)-2 20 | echo "NODE-RED VERSION is "$VER 21 | 22 | cd /usr/lib/node_modules 23 | sudo find . -type f -name .DS_Store -exec rm {} \; 24 | sudo find . -type f -name .npmignore -exec rm {} \; 25 | sudo find . -type f -name .eslintrc* -exec rm {} \; 26 | sudo find . -type f -name .editorconfig -exec rm {} \; 27 | sudo find . -type f -name *.swp -exec rm {} \; 28 | sudo find . -not -newermt 1971-01-01 -exec touch {} \; 29 | 30 | cd /usr/lib/node_modules/node-red/node_modules 31 | sudo find . -type d -name test -exec rm -r {} \; 32 | sudo find . -type d -name doc -exec rm -r {} \; 33 | # sudo find . -type d -name example -exec rm -r {} \; 34 | sudo find . -type d -name sample -exec rm -r {} \; 35 | sudo find . -type d -iname benchmark* -exec rm -r {} \; 36 | sudo find . -type d -iname .nyc_output -exec rm -r {} \; 37 | sudo find . -type d -iname unpacked -exec rm -r {} \; 38 | sudo find . -type d -name man* -exec rm -r {} \; 39 | sudo find . -type d -name tst -exec rm -r {} \; 40 | sudo find . -type d -iname demo -exec rm -r {} \; 41 | 42 | sudo find . -type f -name bench.gnu -exec rm {} \; 43 | sudo find . -type f -name .npmignore -exec rm {} \; 44 | sudo find . -type f -name .travis.yml -exec rm {} \; 45 | sudo find . -type f -name .jshintrc -exec rm {} \; 46 | sudo find . -type f -iname README.md -exec rm {} \; 47 | sudo find . -type f -iname HISTORY.md -exec rm {} \; 48 | sudo find . -type f -iname CONTRIBUTING.md -exec rm {} \; 49 | sudo find . -type f -iname CHANGE*.md -exec rm {} \; 50 | sudo find . -type f -iname .gitmodules -exec rm {} \; 51 | sudo find . -type f -iname .gitattributes -exec rm {} \; 52 | sudo find . -type f -iname .gitignore -exec rm {} \; 53 | sudo find . -type f -iname "*~" -exec rm {} \; 54 | 55 | # slightly more risky 56 | sudo find . -iname test* -exec rm -r {} \; 57 | sudo find . -type f -iname usage.txt -exec rm {} \; 58 | # sudo find . -type f -iname example.js -exec rm {} \; 59 | sudo find . -type d -name node-pre-gyp-github -exec rm -r {} \; 60 | sudo find . -type f -iname build-all.json -exec rm -r {} \; 61 | #sudo find . -iname LICENSE* -type f -exec rm {} \; 62 | 63 | cd /usr/lib/node_modules/node-red-node-serialport/node_modules 64 | sudo find . -type d -name test -exec rm -r {} \; 65 | sudo find . -type d -name doc -exec rm -r {} \; 66 | sudo find . -type d -name sample -exec rm -r {} \; 67 | sudo find . -type d -iname coverage -exec rm -r {} \; 68 | sudo find . -type d -iname benchmark -exec rm -r {} \; 69 | sudo find . -type f -iname bench.gnu -exec rm -r {} \; 70 | # sudo find . -name example* -exec rm -r {} \; 71 | sudo find . -type f -name .npmignore -exec rm {} \; 72 | sudo find . -type f -name .travis.yml -exec rm {} \; 73 | sudo find . -type f -name .jshintrc -exec rm {} \; 74 | sudo find . -type f -iname README.md -exec rm {} \; 75 | sudo find . -type f -iname HISTORY.md -exec rm {} \; 76 | sudo find . -type f -iname CONTRIBUTING.md -exec rm {} \; 77 | sudo find . -type f -iname CHANGE*.md -exec rm {} \; 78 | sudo find . -type f -iname .gitmodules -exec rm {} \; 79 | sudo find . -type f -iname .gitattributes -exec rm {} \; 80 | sudo find . -type f -iname "*~" -exec rm {} \; 81 | 82 | echo "Tar up the existing install" 83 | sudo rm -rf /tmp/nodered_* 84 | cd / 85 | sudo tar zcf /tmp/nred.tgz /usr/lib/node_modules/node-red* /usr/bin/node-red* /usr/share/applications/Node-RED.desktop /lib/systemd/system/nodered.service /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg 86 | echo " " 87 | ls -l /tmp/nred.tgz 88 | echo " " 89 | 90 | echo "Extract nred.tgz to /tmp directory" 91 | sudo mkdir -p /tmp/nodered_$VER/DEBIAN 92 | sudo tar zxf /tmp/nred.tgz -C /tmp/nodered_$VER 93 | 94 | cd /tmp/nodered_$VER 95 | cp /tmp/nodered.service lib/systemd/system/nodered.service 96 | 97 | # echo "Move from /usr/local/... to /usr/..." 98 | # sudo mv usr/local/* usr/ 99 | # sudo rm -rf usr/local 100 | 101 | echo "Reset file ownerships and permissions" 102 | sudo chown -R root:root * 103 | sudo chmod -R -s * 104 | sudo find . -type f -iname "*.js" -exec chmod 644 {} \; 105 | sudo find . -iname "*.json" -exec chmod 644 {} \; 106 | sudo find . -iname "*.yml" -exec chmod 644 {} \; 107 | sudo find . -iname "*.md" -exec chmod 644 {} \; 108 | sudo find . -iname "*.html" -exec chmod 644 {} \; 109 | sudo find . -iname "*.ts" -exec chmod 644 {} \; 110 | sudo find . -iname "*.map" -exec chmod 644 {} \; 111 | sudo find . -iname "*.lock" -exec chmod 644 {} \; 112 | sudo find . -iname LICENSE* -exec chmod 644 {} \; 113 | sudo find . -iname Makefile -exec chmod 644 {} \; 114 | sudo find . -iname *.png -exec chmod 644 {} \; 115 | sudo find . -iname *.txt -exec chmod 644 {} \; 116 | sudo find . -iname *.conf -exec chmod 644 {} \; 117 | sudo find . -iname *.pem -exec chmod 644 {} \; 118 | sudo find . -iname *.cpp -exec chmod 644 {} \; 119 | sudo find . -iname *.h -exec chmod 644 {} \; 120 | sudo find . -iname prepublish.sh -exec chmod 644 {} \; 121 | sudo find . -iname update_authors.sh -exec chmod 644 {} \; 122 | sudo find . -type d -exec chmod 755 {} \; 123 | sudo chmod 644 usr/lib/node_modules/node-red/editor/vendor/font-awesome/css/* 124 | sudo chmod 644 usr/lib/node_modules/node-red/editor/vendor/font-awesome/fonts/* 125 | sudo chmod 755 usr/lib/node_modules/node-red/red.js 126 | sudo chmod 755 usr/lib/node_modules/node-red-admin/node-red-admin.js 127 | 128 | sudo rm -f usr/lib/node_modules/node-red/node_modules/bcrypt/build-tmp-napi-v3/Release/nothing.a 129 | 130 | SIZE=`du -ks . | cut -f 1` 131 | echo "Installed size is $SIZE" 132 | 133 | echo "Create control file" 134 | cd DEBIAN 135 | echo "Package: nodered" | sudo tee control 136 | echo "Version: $VER" | sudo tee -a control 137 | echo "Section: editors" | sudo tee -a control 138 | echo "Priority: optional" | sudo tee -a control 139 | echo "Architecture: armhf" | sudo tee -a control 140 | echo "Installed-Size: $SIZE" | sudo tee -a control 141 | #echo "Depends: nodejs (>= 8), python (>= 2.7)" | sudo tee -a control 142 | # echo "Depends: nodejs (>= 10), npm (>= 5.8), python (>= 2.7)" | sudo tee -a control 143 | echo "Depends: nodejs (>= 12), npm (>= 7), python3 (>= 3)" | sudo tee -a control 144 | echo "Homepage: http://nodered.org" | sudo tee -a control 145 | echo "Maintainer: Dave Conway-Jones " | sudo tee -a control 146 | echo "Description: Node-RED - low-code programming for event-driven applications" | sudo tee -a control 147 | echo " A graphical flow editor for event driven applications." | sudo tee -a control 148 | echo " Runs on Node.js - using a browser for the user interface." | sudo tee -a control 149 | echo " See http://nodered.org for more information, documentation and examples." | sudo tee -a control 150 | echo " ." | sudo tee -a control 151 | echo " Copyright 2017,2022 OpenJS Foundation and other contributors, https://openjsf.org/" | sudo tee -a control 152 | echo " Copyright 2015,2017 IBM Corp." | sudo tee -a control 153 | echo " Licensed under the Apache License, Version 2.0" | sudo tee -a control 154 | echo " http://www.apache.org/licenses/LICENSE-2.0" | sudo tee -a control 155 | 156 | echo '#!/bin/sh -e' | sudo tee preinst 157 | echo 'service nodered stop || true >/dev/null 2>&1; exit 0' | sudo tee -a preinst 158 | 159 | echo '#!/bin/sh -e' | sudo tee postinst 160 | echo 'hash -r >/dev/null 2>&1' | sudo tee -a postinst 161 | echo 'sed -i "s#^User=.*#User=$SUDO_USER#;s#^Group=.*#Group=$SUDO_USER#;s#^WorkingDirectory=.*#WorkingDirectory=/home/$SUDO_USER#;s#^EnvironmentFile=.*#EnvironmentFile=-/home/$SUDO_USER/.node-red/environment#" /usr/lib/systemd/system/nodered.service' | sudo tee -a postinst 162 | echo 'sync' | sudo tee -a postinst 163 | echo 'exit 0' | sudo tee -a postinst 164 | echo "service nodered stop >/dev/null 2>&1; exit 0" | sudo tee prerm 165 | # echo "rm -rf /usr/lib/node_modules/node-red* /usr/bin/node-red* /usr/share/applications/Node-RED.desktop /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg >/dev/null 2>&1; exit 0" | sudo tee postrm 166 | # echo "rm -rf /usr/local/lib/node_modules/npm /usr/local/bin/npm && hash -r >/dev/null 2>&1; exit 0" | sudo tee postrm 167 | echo "export DISPLAY=:0 && lxpanelctl restart >/dev/null 2>&1; exit 0" | sudo tee postrm 168 | sudo chmod 0755 preinst postinst prerm postrm 169 | 170 | cd ../usr/share 171 | sudo mkdir -p doc/nodered 172 | cd doc/nodered 173 | echo " Copyright 2017-2022 OpenJS Foundation and other contributors, https://openjsf.org/" | sudo tee copyright 174 | echo "nodered ($VER) unstable; urgency=low" | sudo tee changelog 175 | echo " * Point release." | sudo tee -a changelog 176 | echo " -- DCJ $(date '+%a, %d %b %Y %H:%M:%S +0000')" | sudo tee -a changelog 177 | echo "" | sudo tee -a changelog 178 | sudo gzip -9 changelog 179 | 180 | echo "Build the actual deb file" 181 | cd /tmp/ 182 | sudo dpkg-deb --build nodered_$VER 183 | echo " " 184 | ls -lrt no*.deb 185 | 186 | echo "Move .deb to /home/pi directory" 187 | mkdir -p /home/pi/dist 188 | sudo mv nodered_$VER.deb /home/pi/dist 189 | cd /home/pi/dist 190 | sudo chown pi:pi nodered_$VER.deb 191 | dpkg-scanpackages -m . | gzip -9c > Packages.gz 192 | echo " " 193 | echo "Now running lintian report" 194 | lintian nodered_$VER.deb > /home/pi/lint.log 195 | cd .. 196 | echo ' ' 197 | echo 'Errors ' $(cat lint.log | grep E: | wc -l) 198 | echo 'Warnings ' $(cat lint.log | grep W: | wc -l) 199 | echo "All done - see ~/lint.log" 200 | -------------------------------------------------------------------------------- /pibuild/node-red-pi-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2016,2022 OpenJS Foundation and other contributors, https://openjsf.org/ 4 | # Copyright 2015,2016 IBM Corp. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | # clear out all old nodejs and node-red 19 | sudo rm -rf /usr/lib/node_modules/ 20 | sudo rm -rf /usr/bin/node-red* 21 | sudo rm -rf /usr/bin/update-nodejs-and-nodered 22 | sudo rm -rf /usr/local/lib/node_modules/ 23 | sudo rm -rf /usr/local/bin/node-red* 24 | sudo rm -rf /usr/local/bin/update-nodejs-and-nodered 25 | sudo rm -rf /home/pi/.npm /home/pi/.node-gyp 26 | sudo rm -rf /root/.npm /root/.node-gyp 27 | sudo rm -rf /etc/apt/sources.list.d/nodesource.list 28 | 29 | # can remove next line if already updated.... 30 | sudo apt-get update 31 | sudo apt-get install -y build-essential nodejs npm lintian 32 | 33 | hash -r 34 | sudo npm cache clean --force 35 | echo " " 36 | echo "Installed" 37 | echo " Node" $(node -v) 38 | echo " Npm "$(npm -v) 39 | echo "Now installing Node-RED - please wait - can take 25 mins on a Pi 1" 40 | echo " Node-RED "$(npm show node-red version) 41 | sudo npm i -g --unsafe-perm --no-progress --production node-red@2.* 42 | 43 | # Remove existing serialport 44 | sudo rm -rf /usr/local/lib/node_modules/node-red/nodes/node_modules/node-red-node-serialport 45 | 46 | # Remove a load of unnecessary doc/test/example from pre-reqs 47 | pushd /usr/local/lib/node_modules/node-red/node_modules 48 | sudo find . -type d -name test -exec rm -r {} \; 49 | sudo find . -type d -name doc -exec rm -r {} \; 50 | # sudo find . -type d -name example -exec rm -r {} \; 51 | sudo find . -type d -name sample -exec rm -r {} \; 52 | sudo find . -type d -iname benchmark* -exec rm -r {} \; 53 | sudo find . -type d -iname .nyc_output -exec rm -r {} \; 54 | sudo find . -type d -iname unpacked -exec rm -r {} \; 55 | sudo find . -type d -iname demo -exec rm -r {} \; 56 | 57 | sudo find . -name bench.gnu -type f -exec rm {} \; 58 | sudo find . -name .npmignore -type f -exec rm {} \; 59 | sudo find . -name .travis.yml -type f -exec rm {} \; 60 | sudo find . -name .jshintrc -type f -exec rm {} \; 61 | sudo find . -iname README.md -type f -exec rm {} \; 62 | sudo find . -iname HISTORY.md -type f -exec rm {} \; 63 | sudo find . -iname CONTRIBUTING.md -type f -exec rm {} \; 64 | sudo find . -iname CHANGE*.md -type f -exec rm {} \; 65 | sudo find . -iname .gitmodules -type f -exec rm {} \; 66 | sudo find . -iname .gitattributes -type f -exec rm {} \; 67 | sudo find . -iname .gitignore -type f -exec rm {} \; 68 | sudo find . -iname "*~" -type f -exec rm {} \; 69 | # slightly more risky 70 | sudo find . -iname test* -exec rm -r {} \; 71 | popd 72 | 73 | # Add some extra useful nodes 74 | mkdir -p ~/.node-red 75 | #sudo npm install -g --unsafe-perm --no-progress node-red-admin 76 | echo "Node-RED installed. Adding a few extra nodes" 77 | sudo npm install -g --unsafe-perm --no-progress node-red-node-pi-gpio node-red-node-random node-red-node-ping node-red-node-smooth node-red-contrib-play-audio node-red-node-serialport node-red-contrib-buffer-parser 78 | # sudo setcap cap_net_raw+eip $(eval readlink -f `which node`) 79 | 80 | match='editorTheme: {' 81 | file='/usr/local/lib/node_modules/node-red/settings.js' 82 | insert='editorTheme: {\n menu: { \"menu-item-help\": {\n label: \"Node-RED Pi Website\",\n url: \"http:\/\/nodered.org\/docs\/hardware\/raspberrypi.html\"\n } },' 83 | sudo sed -i "s|$match|$insert|" $file 84 | echo "*********************" 85 | 86 | echo "Move everything under /usr rather than /usr/local" 87 | sudo mkdir -p /usr/lib/node_modules 88 | sudo mv /usr/local/lib/node_modules/node-red* /usr/lib/node_modules/ 89 | sudo mv /usr/local/bin/node* /usr/bin/ 90 | 91 | # Get systemd script - start and stop scripts - svg icon - and .desktop file into correct places. 92 | if [ -d "resources" ]; then 93 | cd resources 94 | sudo chown root:root * 95 | sudo chmod +x node-red-st* 96 | sudo chmod +x node-red-re* 97 | sudo chmod +x node-red-log 98 | sudo cp nodered.service /lib/systemd/system/ 99 | sudo cp nodered.service /tmp/ 100 | sudo cp node-red-start /usr/bin/ 101 | sudo cp node-red-stop /usr/bin/ 102 | sudo cp node-red-restart /usr/bin/ 103 | sudo cp node-red-reload /usr/bin/ 104 | sudo cp node-red-log /usr/bin/ 105 | sudo cp node-red-icon.svg /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg 106 | sudo chmod 644 /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg 107 | sudo cp Node-RED.desktop /usr/share/applications/Node-RED.desktop 108 | sudo chown pi:pi * 109 | cd .. 110 | else 111 | echo " " 112 | echo "resources - subdirectory not in place... exiting." 113 | exit 1 114 | fi 115 | #sudo systemctl disable nodered 116 | 117 | # Restart lxpanelctl so icon appears in menu - programming 118 | #lxpanelctl restart 119 | echo " " 120 | echo "All done." 121 | echo " You can now start Node-RED with the command node-red-start" 122 | echo " or using the icon under Menu / Programming / Node-RED." 123 | echo " Then point your browser to http://127.0.0.1:1880 or http://{{your_pi_ip-address}:1880" 124 | echo " " 125 | -------------------------------------------------------------------------------- /resources/Node-RED.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Node-RED 3 | Comment=Low-code programming for event-driven applications 4 | Icon=/usr/share/icons/hicolor/scalable/apps/node-red-icon.svg 5 | Exec=node-red-start 6 | Type=Application 7 | Encoding=UTF-8 8 | Terminal=true 9 | Categories=Development; 10 | -------------------------------------------------------------------------------- /resources/node-red-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Node-RED Icon 5 | 6 | 7 | 8 | image/svg+xml 9 | 10 | Node-RED Icon 11 | 12 | 13 | 14 | Nick O'Leary 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /resources/node-red-log: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LINES=25 3 | while getopts ":n:" opt; do 4 | case $opt in 5 | n) LINES="$OPTARG" 6 | ;; 7 | \?) echo "Unrecognized option -$OPTARG. Usage: node-red-log [-n lines]. For example: node-red-log -n 50" >&2 && exit 1 8 | ;; 9 | esac 10 | done 11 | echo -e '\033]2;'$USER@`hostname`: Node-RED log'\007' 12 | echo " " 13 | sudo journalctl -f -n $LINES -u nodered -o cat 14 | -------------------------------------------------------------------------------- /resources/node-red-reload: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | node-red-stop && node-red-start 3 | -------------------------------------------------------------------------------- /resources/node-red-restart: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo systemctl restart nodered 3 | echo -e "\033[1mRestarted \033[38;5;88mNode-RED\033[0m" 4 | -------------------------------------------------------------------------------- /resources/node-red-start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2016,2020 JS Foundation and other contributors, https://js.foundation/ 4 | # Copyright 2015,2016 IBM Corp. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | echo -e '\033]2;'$USER@`hostname`: Node-RED console'\007' 18 | if [[ $(which node-red-pi) ]]; then 19 | if [[ ! $(which npm) ]]; then 20 | echo -e "\033[0m \033[0m" 21 | echo -e "\033[0m npm is not installed, it is recommended \033[0m" 22 | echo -e "\033[0m to install the latest by running: \033[0m" 23 | echo -e "\033[0m update-nodejs-and-nodered \033[0m" 24 | echo -e "\033[0m \033[0m" 25 | echo -e " " 26 | fi 27 | HOSTIP=`hostname -I | cut -d ' ' -f 1` 28 | if [ "$HOSTIP" = "" ]; then 29 | HOSTIP="127.0.0.1" 30 | fi 31 | echo -e "\033[1mStart \033[38;5;88mNode-RED\033[0m" 32 | echo " " 33 | echo "Once Node-RED has started, point a browser at http://$HOSTIP:1880" 34 | echo "On Pi Node-RED works better with the Firefox or Chrome browser" 35 | echo " " 36 | if groups | grep -q -w sudo; then 37 | echo -e "Use \033[0;36mnode-red-stop\033[0m to stop Node-RED" 38 | echo -e "Use \033[0;36mnode-red-start\033[0m to start Node-RED again" 39 | echo -e "Use \033[0;36mnode-red-log\033[0m to view the recent log output" 40 | fi 41 | echo -e "Use \033[0;36msudo systemctl enable nodered.service\033[0m to autostart Node-RED at every boot" 42 | echo -e "Use \033[0;36msudo systemctl disable nodered.service\033[0m to disable autostart on boot" 43 | echo " " 44 | echo "To find more nodes and example flows - go to http://flows.nodered.org" 45 | if [ "$nv" = "v0" ]; then 46 | echo "You may also need to install and upgrade npm" 47 | echo -e " \033[0;36msudo apt-get install npm\033[0m" 48 | echo -e " \033[0;36msudo npm i -g npm@2.x\033[0m" 49 | fi 50 | if groups $USER | grep -q -w sudo; then 51 | # Current user is member of sudo group, start node-red through systemd 52 | sudo systemctl start nodered 53 | echo " " 54 | echo "Starting as a systemd service." 55 | sudo journalctl -f -n 1 -u nodered -o cat 56 | elif [ $EUID -eq 0 ]; then 57 | # Current user is root, start node-red through systemd 58 | systemctl start nodered 59 | echo " " 60 | echo "Starting as root systemd service." 61 | journalctl -f -n 1 -u nodered -o cat 62 | else 63 | # Start node-red as unprivileged user 64 | echo " " 65 | echo "Starting as a normal user." 66 | node-red-pi 67 | fi 68 | else 69 | echo "Node-RED is not yet fully installed. Please re-run the install script again manually." 70 | echo " " 71 | echo " bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)" 72 | echo " " 73 | echo "then retry node-red-start" 74 | echo " " 75 | fi 76 | -------------------------------------------------------------------------------- /resources/node-red-start.old: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2016,2017 JS Foundation and other contributors, https://js.foundation/ 4 | # Copyright 2015,2016 IBM Corp. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | echo -e '\033]2;'Node-RED console'\007' 18 | if [[ $(which node-red) ]]; then 19 | if [[ ! $(which npm) ]]; then 20 | echo -e "\033[0m \033[0m" 21 | echo -e "\033[0m npm is not installed, it is recommended \033[0m" 22 | echo -e "\033[0m to install the latest by running: \033[0m" 23 | echo -e "\033[0m update-nodejs-and-nodered \033[0m" 24 | echo -e "\033[0m \033[0m" 25 | echo -e " " 26 | fi 27 | if [[ $(which node) ]]; then 28 | nv=`node -v | cut -d "." -f1` 29 | # if [ "$nv" = "v0" ] || [ "$nv" = "v4" ] || [ "$nv" = "v5" ]; then 30 | if [ "$nv" = "v0" ]; then 31 | echo -e "\033[0m \033[0m" 32 | echo -e "\033[0m node.js $nv.x is NO LONGER supported. \033[0m" 33 | echo -e "\033[0m please consider upgrading to node.js LTS. \033[0m" 34 | echo -e "\033[0m \033[0m" 35 | echo -e "\033[0m you can do this with the following command: \033[0m" 36 | echo -e "\033[0m update-nodejs-and-nodered \033[0m" 37 | echo -e "\033[0m \033[0m" 38 | echo -e " " 39 | fi 40 | HOSTIP=`hostname -I | cut -d ' ' -f 1` 41 | if [ "$HOSTIP" = "" ]; then 42 | HOSTIP="127.0.0.1" 43 | fi 44 | echo -e "\033[1mStart \033[38;5;88mNode-RED\033[0m" 45 | echo " " 46 | echo "Once Node-RED has started, point a browser at http://$HOSTIP:1880" 47 | echo "On Pi Node-RED works better with the Firefox or Chrome browser" 48 | echo " " 49 | if groups | grep -q -w sudo; then 50 | echo -e "Use \033[0;36mnode-red-stop\033[0m to stop Node-RED" 51 | echo -e "Use \033[0;36mnode-red-start\033[0m to start Node-RED again" 52 | echo -e "Use \033[0;36mnode-red-log\033[0m to view the recent log output" 53 | fi 54 | echo -e "Use \033[0;36msudo systemctl enable nodered.service\033[0m to autostart Node-RED at every boot" 55 | echo -e "Use \033[0;36msudo systemctl disable nodered.service\033[0m to disable autostart on boot" 56 | echo " " 57 | echo "To find more nodes and example flows - go to http://flows.nodered.org" 58 | if [ "$nv" = "v0" ]; then 59 | echo "You may also need to install and upgrade npm" 60 | echo -e " \033[0;36msudo apt-get install npm\033[0m" 61 | echo -e " \033[0;36msudo npm i -g npm@2.x\033[0m" 62 | fi 63 | if groups | grep -q -w sudo; then 64 | # Current user is member of sudo group, start node-red through systemd 65 | sudo systemctl start nodered 66 | echo " " 67 | echo "Starting as a systemd service." 68 | sudo journalctl -f -n 0 -u nodered -o cat 69 | else 70 | # Start node-red as unprivileged user 71 | node-red-pi 72 | fi 73 | else 74 | echo "Node is not yet fully installed" 75 | update-nodejs-and-nodered $USER 76 | if [ $? -eq 0 ]; then 77 | read -p "Would you like to start Node-RED now (y/N) ? " yn 78 | case $yn in 79 | [Yy]* ) 80 | node-red-start 81 | ;; 82 | * ) 83 | echo " " 84 | exit 85 | ;; 86 | esac 87 | fi 88 | fi 89 | else 90 | echo "Node-RED is not yet fully installed." 91 | update-nodejs-and-nodered $USER 92 | if [ $? -eq 0 ]; then 93 | read -p "Would you like to start Node-RED now (y/N) ? " yn 94 | case $yn in 95 | [Yy]* ) 96 | node-red-start 97 | ;; 98 | * ) 99 | echo " " 100 | exit 101 | ;; 102 | esac 103 | fi 104 | fi 105 | -------------------------------------------------------------------------------- /resources/node-red-start.rpm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2016,2017 JS Foundation and other contributors, https://js.foundation/ 4 | # Copyright 2015,2016 IBM Corp. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | echo -e '\033]2;'$USER@`hostname`: Node-RED console'\007' 18 | HOSTIP=`hostname -I | cut -d ' ' -f 1` 19 | if [ "$HOSTIP" = "" ]; then 20 | HOSTIP="127.0.0.1" 21 | fi 22 | echo -e "\033[1mStart \033[38;5;88mNode-RED\033[0m" 23 | echo " " 24 | echo "Once Node-RED has started, point a browser at http://$HOSTIP:1880" 25 | echo "On Pi Node-RED works better with the Firefox or Chrome browser" 26 | echo " " 27 | if groups | grep -q -w wheel; then 28 | echo -e "Use \033[0;36mnode-red-stop\033[0m to stop Node-RED" 29 | echo -e "Use \033[0;36mnode-red-start\033[0m to start Node-RED again" 30 | echo -e "Use \033[0;36mnode-red-log\033[0m to view the recent log output" 31 | fi 32 | echo -e "Use \033[0;36msudo systemctl enable nodered.service\033[0m to autostart Node-RED at every boot" 33 | echo -e "Use \033[0;36msudo systemctl disable nodered.service\033[0m to disable autostart on boot" 34 | echo " " 35 | echo "To find more nodes and example flows - go to http://flows.nodered.org" 36 | if groups | grep -q -w wheel; then 37 | # Current user is member of sudo group, start node-red through systemd 38 | sudo systemctl start nodered 39 | echo " " 40 | echo "Starting as a systemd service." 41 | sudo journalctl -f -n 0 -u nodered -o cat 42 | else 43 | # Start node-red as unprivileged user 44 | node-red 45 | fi 46 | -------------------------------------------------------------------------------- /resources/node-red-stop: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo -e "\033[1mStop \033[38;5;88mNode-RED\033[0m" 3 | echo " " 4 | echo -e "Use \033[0;36mnode-red-start\033[0m to start Node-RED again" 5 | sudo systemctl stop nodered 6 | echo " " 7 | exit 8 | -------------------------------------------------------------------------------- /resources/nodered: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Starts and stops Node-RED 3 | # /etc/init.d/nodered 4 | ### BEGIN INIT INFO 5 | # Provides: node-red 6 | # Required-Start: $syslog $local_fs 7 | # Required-Stop: $syslog $local_fs 8 | # Default-Start: 2 3 4 5 9 | # Default-Stop: 0 1 6 10 | # Short-Description: Node-RED initialisation 11 | ### END INIT INFO 12 | # Can be downloaded and installed in one go by using this command 13 | # sudo wget -O /tmp/download https://gist.github.com/bigmonkeyboy/9962293/download && sudo tar -zxf /tmp/download --strip-components 1 -C /etc/init.d && sudo chmod 755 /etc/init.d/nodered && sudo update-rc.d nodered defaults 14 | . /lib/lsb/init-functions 15 | 16 | # This runs as the user called pi - please change as you require 17 | USER=pi 18 | 19 | # The log is written to here - please make sure your user has write permissions. 20 | LOG=/var/log/node-red.log 21 | 22 | #Load up node red when called 23 | case "$1" in 24 | 25 | start) 26 | if pgrep ^node-red$ > /dev/null 27 | then 28 | echo "Node-RED already running." 29 | else 30 | echo "Starting Node-Red.." 31 | touch $LOG 32 | chown $USER:$USER $LOG 33 | echo "" >> $LOG 34 | echo "Node-RED service start: "$(date) >> $LOG 35 | # su -l $USER -c "cd ~/.node-red && screen -dmS red node-red-pi --max-old-space-size=512" 36 | # or 37 | su -l $USER -c "node-red-pi --max-old-space-size=512 -u ~/.node-red >> $LOG &" 38 | echo "Logging to "$LOG 39 | fi 40 | ;; 41 | 42 | stop) 43 | echo "Stopping Node-Red.." 44 | # su -l $USER -c "screen -S red -X quit" 45 | # or 46 | pkill -SIGINT ^node-red$ 47 | sleep 2 48 | echo "" >> $LOG 49 | echo "Node-RED service stop: "$(date) >> $LOG 50 | ;; 51 | 52 | restart|force-reload) 53 | echo "Restarting Node-Red.." 54 | $0 stop 55 | sleep 2 56 | $0 start 57 | echo "Restarted." 58 | ;; 59 | *) 60 | echo "Usage: $0 {start|stop|restart}" 61 | exit 1 62 | esac 63 | -------------------------------------------------------------------------------- /resources/nodered.rotate: -------------------------------------------------------------------------------- 1 | /var/log/nodered-install.log 2 | { 3 | rotate 4 4 | weekly 5 | missingok 6 | notifempty 7 | compress 8 | delaycompress 9 | } 10 | -------------------------------------------------------------------------------- /resources/nodered.service: -------------------------------------------------------------------------------- 1 | # systemd service file to start Node-RED 2 | 3 | [Unit] 4 | Description=Node-RED graphical event wiring tool 5 | Wants=network.target 6 | Documentation=http://nodered.org/docs/hardware/raspberrypi.html 7 | 8 | [Service] 9 | Type=simple 10 | # Run as normal pi user - change to the user name you wish to run Node-RED as 11 | User=pi 12 | Group=pi 13 | WorkingDirectory=/home/pi 14 | 15 | Environment="XDG_RUNTIME_DIR=/run/user/%U" 16 | Environment="NODE_OPTIONS=--max_old_space_size=512" 17 | # define an optional environment file in Node-RED's user directory to set custom variables externally 18 | EnvironmentFile=-/home/pi/.node-red/environment 19 | # uncomment and edit next line if you need an http proxy 20 | #Environment="HTTP_PROXY=my.httpproxy.server.address" 21 | # uncomment the next line for a more verbose log output 22 | #Environment="NODE_RED_OPTIONS=-v" 23 | # uncomment next line if you need to wait for time sync before starting 24 | #ExecStartPre=/bin/bash -c '/bin/journalctl -b -u systemd-timesyncd | /bin/grep -q "systemd-timesyncd.* Synchronized to time server"' 25 | 26 | ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS -- $NODE_RED_OPTIONS 27 | #ExecStart=/usr/bin/env node $NODE_OPTIONS red.js -- $NODE_RED_OPTIONS 28 | # Use SIGINT to stop 29 | KillSignal=SIGINT 30 | # Auto restart on crash 31 | Restart=on-failure 32 | RestartSec=20 33 | # Tag things in the log 34 | SyslogIdentifier=Node-RED 35 | #StandardOutput=syslog 36 | 37 | [Install] 38 | WantedBy=multi-user.target 39 | -------------------------------------------------------------------------------- /resources/nodered.socket: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Node-RED Socket 3 | PartOf=nodered.service 4 | 5 | [Socket] 6 | ListenStream=1880 7 | 8 | [Install] 9 | WantedBy=sockets.target 10 | -------------------------------------------------------------------------------- /resources/nodered.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Node-RED 4 | A Node-RED service. 5 | 6 | 7 | -------------------------------------------------------------------------------- /resources/update-nodejs-and-nodered: -------------------------------------------------------------------------------- 1 | ../deb/update-nodejs-and-nodered -------------------------------------------------------------------------------- /resources/update-pi: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2016,2017 JS Foundation and other contributors, https://js.foundation/ 4 | # Copyright 2015,2016 IBM Corp. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | wget -q --spider https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered 19 | if [ $? -eq 0 ]; then 20 | echo -ne "\nFetching \033[38;5;88mNode-RED\033[0m update.\n" 21 | bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered) 22 | else 23 | echo -ne "\n Can't reach upgrade server - please check your internet connection.\n\n" 24 | fi 25 | -------------------------------------------------------------------------------- /rpm/update-nodejs-and-nodered: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2019,2023 JS Foundation and other contributors, https://js.foundation/ 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Node-RED Installer for RPM based systems 18 | 19 | unset NODERED_HOME 20 | umask 0022 21 | 22 | usage() { 23 | cat << EOL 24 | 25 | Usage: $0 [options] 26 | 27 | options: 28 | --help display this help and exits. 29 | --nodered-user= specify the user to run as e.g. '--nodered-user=nodered'. 30 | --open-firewall adding public firewall rule for node-red port 1880. 31 | --confirm-root install as root without asking confirmation. 32 | --confirm-install confirm the installation without asking a confirmation. 33 | 34 | EOL 35 | } 36 | 37 | #NODE_VERSION="" 38 | 39 | if [ $# -gt 0 ]; then 40 | # Parsing parameters 41 | while (( "$#" )); do 42 | case "$1" in 43 | --help) 44 | usage && exit 0 45 | shift 46 | ;; 47 | --confirm-root) 48 | CONFIRM_ROOT="y" 49 | shift 50 | ;; 51 | --confirm-install) 52 | CONFIRM_INSTALL="y" 53 | shift 54 | ;; 55 | --open-firewall) 56 | OPEN_FIREWALL="y" 57 | shift 58 | ;; 59 | --nodered-user=*) 60 | NODERED_USER="${1#*=}" 61 | shift 62 | ;; 63 | --) # end argument parsing 64 | shift 65 | break 66 | ;; 67 | -*|--*=) # unsupported flags 68 | echo "Error: Unsupported flag $1" >&2 69 | exit 1 70 | ;; 71 | esac 72 | done 73 | fi 74 | 75 | echo -ne "\033[2 q" 76 | echo -en "\n **************************************\n" 77 | echo -en " *** \e[1;91mNode-RED\e[0;97m \e[1;97mRPM install Script\e[0m ***\n" 78 | echo -en " **************************************\n" 79 | 80 | # sanitize environment 81 | case "${CONFIRM_ROOT}" in 82 | [Yy]* ) 83 | export CONFIRM_ROOT=y 84 | ;; 85 | [Nn]* ) 86 | export CONFIRM_ROOT=n 87 | ;; 88 | * ) 89 | export CONFIRM_ROOT=n 90 | ;; 91 | esac 92 | 93 | case "${CONFIRM_INSTALL}" in 94 | [Yy]* ) 95 | export CONFIRM_INSTALL=y 96 | ;; 97 | [Nn]* ) 98 | export CONFIRM_INSTALL=n 99 | ;; 100 | * ) 101 | export CONFIRM_INSTALL=n 102 | ;; 103 | esac 104 | 105 | # user requested, not root 106 | if [[ -n "${NODERED_USER}" ]] && [[ "${NODERED_USER}" != "root" ]] && [[ "${CONFIRM_INSTALL}" == "n" ]] 107 | then 108 | echo -en "\nThe sytem user is requested as \e[1;32m'${NODERED_USER}'\e[0m\r\n\r\n" 109 | read -p $'\e[0;97mAre you really sure you want to install as the target user \e[1;32m'"'${NODERED_USER}'"$'\e[0;97m? [\e[1;32my\e[0m/N] ?\e[0m' yn 110 | case $yn in 111 | [Yy]* ) 112 | ;; 113 | * ) 114 | exit 115 | ;; 116 | esac 117 | fi 118 | 119 | # user root requested 120 | if [[ -n "${NODERED_USER}" ]] && [[ "${NODERED_USER}" == "root" ]] && [[ "${CONFIRM_ROOT}" == "n" ]] 121 | then 122 | echo -en "\nThe sytem user is requested as \e[1;33m'${NODERED_USER}'\e[0m\r\n\r\n" 123 | read -p $'\e[0;97mAre you really sure you want to install as the target user \e[1;33m'"'${NODERED_USER}'"$'\e[0;97m? [\e[1;33my\e[0m/N] ?\e[0m' yn 124 | case $yn in 125 | [Yy]* ) 126 | ;; 127 | * ) 128 | exit 129 | ;; 130 | esac 131 | fi 132 | 133 | # no user requested, default to the current non root user 134 | if [[ "${EUID}" != "0" ]] && [[ -z "${NODERED_USER}" ]] && [[ "${CONFIRM_INSTALL}" == "n" ]] 135 | then echo -en "\e[0;97m\nNo user has been set, this script is run as user '\e[1;33m${USER}\e[0;97m'.\r\n\r\n" 136 | read -p $'\e[0;97mWould you like to change to the recommended the target user to \e[1;32m\'nodered\'\e[0;97m? [\e[1;32my\e[0m/N] ' yn 137 | case $yn in 138 | [Yy]* ) 139 | export NODERED_USER=nodered 140 | ;; 141 | * ) 142 | ;; 143 | esac 144 | fi 145 | 146 | # no user requested, default to the current root user 147 | if [[ "${EUID}" == "0" ]] && [[ -z "${NODERED_USER}" ]] && [[ "${CONFIRM_ROOT}" == "n" ]] 148 | then 149 | echo -en "\nThe current user \e[1;33mroot\e[0m defaults as the target user for node-red install.\r\n\r\n" 150 | read -p $'\e[0;97mAre you really sure you want to install as the target user \e[1;31mroot\e[0;97m ? [\e[1;31my\e[0;97m/N] ?\e[0m' yn 151 | case $yn in 152 | [Yy]* ) 153 | [[ -n "${NODERED_HOME}" ]] || export NODERED_HOME=/root; 154 | ;; 155 | * ) 156 | exit 157 | ;; 158 | esac 159 | fi 160 | 161 | 162 | 163 | 164 | if [[ -z "${OPEN_FIREWALL}" ]] && [[ "${CONFIRM_INSTALL}" == "n" ]] 165 | then 166 | OPEN_FIREWALL="n" 167 | read -r -t 15 -p $'\e[0;97mWould you like to add Node-RED port \e[34m1880\e[0;97m to the \e[1;34mfirewall\e[0;97m public zone ? [\e[1;34my\e[0;97m/N] ? ' response 168 | if [[ "$response" =~ ^([yY])+$ ]]; then 169 | OPEN_FIREWALL="y" 170 | fi 171 | fi 172 | # sanitize environment variable OPEN_FIREWALL 173 | case "${OPEN_FIREWALL}" in 174 | [Yy]* ) 175 | export OPEN_FIREWALL=y 176 | ;; 177 | [Nn]* ) 178 | export OPEN_FIREWALL=n 179 | ;; 180 | * ) 181 | export OPEN_FIREWALL=n 182 | ;; 183 | esac 184 | 185 | # this script assumes that $HOME is the folder of the user that runs node-red 186 | # that $USER is the user name and the group name to use when running is the 187 | # primary group of that user 188 | # if this is not correct then edit the lines below 189 | [[ -n "${NODERED_USER}" ]] || export NODERED_USER=$USER; 190 | [[ -n "${NODERED_HOME}" ]] || export NODERED_HOME="/home/${NODERED_USER}" 191 | 192 | 193 | # check internet, if failure exit 194 | if curl -f https://www.npmjs.com/package/node-red >/dev/null 2>&1 195 | then 196 | echo " " 197 | else 198 | echo " " 199 | echo "Sorry - cannot connect to internet - not going to touch anything." 200 | echo "https://www.npmjs.com/package/node-red is not reachable." 201 | echo "Please ensure you have a working internet connection." 202 | echo " " 203 | exit 1 204 | fi 205 | 206 | # final install details 207 | host=`hostname` 208 | echo -e "\e[1;33m ${host}\e[0m : \e[1;97mNode-RED update \e[0;97m" 209 | echo " " 210 | echo -e "This script will do an install of node.js and \e[1;91mNode-RED\e[0;97m" 211 | echo -e " with the service to auto-run as user \e[1;33m'${NODERED_USER}'\e[0m" 212 | echo -e " in the home directory \e[1;37m'${NODERED_HOME}'\e[0m" 213 | [[ "${OPEN_FIREWALL}" == "y" ]] && echo -e " with public \e[1;34mfirewall\e[0;97m port \e[34m1880\e[0;97m opened." 214 | echo " " 215 | 216 | # final confirmation of the install 217 | yn="${CONFIRM_INSTALL}" 218 | [[ "${yn}" == "y" ]] || read -p $'\e[1;97mAre you really \e[0m\e[1;32msure\e[1;97m you want to do this ? [\e[1;32my\e[1;97m/N] ?\e[0m' yn 219 | case "${yn}" in 220 | [Yy]* ) 221 | sudo () 222 | { 223 | [[ $EUID = 0 ]] || set -- command sudo "$@" 224 | "$@" 225 | } 226 | sudo useradd ${NODERED_USER} 227 | NODERED_GROUP=`id -gn ${NODERED_USER}` 228 | MYOS=$(cat /etc/*release | grep "^ID=" | cut -d = -f 2) 229 | versions='fedora"centos"rhel"ol"almalinux"rocky"miraclelinux"nobara"' 230 | if [[ $versions != *"${MYOS}"* ]]; then 231 | echo " " 232 | echo "Doesn't seem to be running on RedHat, Centos, Fedora, Rocky, Alma, Oracle Linux, MIRACLE LINUX or Nobara so quitting" 233 | echo " " 234 | exit 1 235 | fi 236 | GLOBAL="true" 237 | TICK='\033[1;32m\u2714\033[0m' 238 | CROSS='\033[1;31m\u2718\033[0m' 239 | sudo cd "${NODERED_HOME}" || exit 1 240 | clear 241 | echo -e "\n\e[0;97mRunning nodejs and Node-RED install for user '\e[1;33m${NODERED_USER}\e[0;97m' at '${NODERED_HOME}' on ${MYOS}\e[0m\n" 242 | time1=$(date) 243 | echo "" | sudo tee -a /var/log/nodered-install.log >>/dev/null 244 | echo "***************************************" | sudo tee -a /var/log/nodered-install.log >>/dev/null 245 | echo "" | sudo tee -a /var/log/nodered-install.log >>/dev/null 246 | echo "Started : "$time1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 247 | echo "Running for user $USER at $HOME" | sudo tee -a /var/log/nodered-install.log >>/dev/null 248 | echo -ne ' Stop Node-RED \r\n' 249 | echo -ne ' Install Node.js \r\n' 250 | echo -ne ' Install Node-RED core \r\n' 251 | echo -ne ' Add shortcut commands \r\n' 252 | echo -ne ' Update systemd script \r\n' 253 | echo -ne ' Update public zone firewall rule \r\n' 254 | echo -ne ' \r\n' 255 | echo -ne '\r\nAny errors will be logged to /var/log/nodered-install.log\r\n' 256 | echo -ne '\033[9A' 257 | 258 | # stop any running node-red service 259 | if sudo systemctl stop nodered 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null ; then CHAR=$TICK; else CHAR=$CROSS; fi 260 | echo -ne " Stop Node-RED $CHAR\r\n" 261 | 262 | # ensure ~/.config dir is owned by the user 263 | sudo chown -Rf ${NODERED_USER}:${NODERED_GROUP} ${NODERED_HOME}/.config 264 | echo "Now install nodejs" | sudo tee -a /var/log/nodered-install.log >>/dev/null 265 | # if [ "${MYOS}" = "fedora" ] || [ "${MYOS}" = "almalinux" ] || [ "${MYOS}" = "rocky" ] || [ "${MYOS}" = "miraclelinux" ]; then 266 | # sudo dnf module reset -y nodejs 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 267 | # if sudo dnf module install -y nodejs:18/default 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 268 | # else 269 | # if [ "$EUID" == "0" ] 270 | # then 271 | # if curl -fsSL https://rpm.nodesource.com/setup_18.x | bash - 2>&1 | tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 272 | # else 273 | # if curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo -E bash - 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 274 | # fi 275 | # if sudo yum install -y nodejs 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 276 | # fi 277 | 278 | sudo yum install https://rpm.nodesource.com/pub_18.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 279 | if sudo yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 280 | 281 | echo -ne " Install Node.js LTS $CHAR" 282 | # sudo npm i -g npm 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; 283 | hash -r 284 | rc="" 285 | if nov=$(node -v 2>/dev/null); then :; else rc="ERR"; fi 286 | if npv=$(npm -v 2>/dev/null); then :; else rc="ERR"; fi 287 | if [[ $rc == "" ]]; then 288 | echo -ne " Node $nov Npm $npv\r\n" 289 | else 290 | echo -ne "\b$CROSS Failed to install Node.js - Exit\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" 291 | exit 2 292 | fi 293 | 294 | # clean up the npm cache and node-gyp 295 | 296 | # and install Node-RED 297 | echo "Now install Node-RED" | sudo tee -a /var/log/nodered-install.log >>/dev/null 298 | if sudo npm i -g --unsafe-perm --no-progress node-red@latest 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 299 | nrv=$(npm --no-progress -g ls node-red | grep node-red | cut -d '@' -f 2 | sudo tee -a /var/log/nodered-install.log) >>/dev/null 2>&1 300 | echo -ne " Install Node-RED core $CHAR $nrv\r\n" 301 | 302 | echo "Now create basic package.json for the user" | sudo tee -a /var/log/nodered-install.log >>/dev/null 303 | sudo lastlog -u ${NODERED_USER} -C >>/dev/null 2>&1 304 | sudo su - ${NODERED_USER} <<'EOF' 305 | cd 306 | mkdir -p ".node-red/node_modules" 307 | cd .node-red 308 | npm config set update-notifier false #2>&1 >>/dev/null 309 | if [ ! -f "package.json" ]; then 310 | echo '{' > package.json 311 | echo ' "name": "node-red-project",' >> package.json 312 | echo ' "description": "initially created for you by Node-RED '$nrv'",' >> package.json 313 | echo ' "version": "0.0.1",' >> package.json 314 | echo ' "dependencies": {' >> package.json 315 | echo ' }' >> package.json 316 | echo '}' >> package.json 317 | fi 318 | EOF 319 | echo "Now add start/stop/reload/log scripts" | sudo tee -a /var/log/nodered-install.log >>/dev/null 320 | sudo mkdir -p /usr/bin 321 | if curl -f https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-icon.svg >/dev/null 2>&1 322 | then 323 | sudo curl -sL -o /usr/bin/node-red-start https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-start.rpm 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 324 | sudo curl -sL -o /usr/bin/node-red-stop https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-stop 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 325 | sudo curl -sL -o /usr/bin/node-red-restart https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-restart 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 326 | sudo curl -sL -o /usr/bin/node-red-reload https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-reload 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 327 | sudo curl -sL -o /usr/bin/node-red-log https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-log 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 328 | sudo curl -sL -o /etc/logrotate.d/nodered https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.rotate 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 329 | sudo chmod +x /usr/bin/node-red-start 330 | sudo chmod +x /usr/bin/node-red-stop 331 | sudo chmod +x /usr/bin/node-red-restart 332 | sudo chmod +x /usr/bin/node-red-reload 333 | sudo chmod +x /usr/bin/node-red-log 334 | echo -ne " Add shortcut commands $TICK\r\n" 335 | else 336 | echo -ne " Add shortcut commands $CROSS\r\n" 337 | fi 338 | 339 | # add systemd script and configure it for ${NODERED_USER} 340 | echo "Now add systemd script and configure it for ${NODERED_USER}:${NODERED_GROUP} @ ${NODERED_HOME}" | sudo tee -a /var/log/nodered-install.log >>/dev/null 341 | 342 | # check if systemd script already exists 343 | SYSTEMDFILE="/etc/systemd/system/nodered.service" 344 | 345 | if sudo curl -sL -o ${SYSTEMDFILE}.temp https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 346 | # set the User,Group,EnvironmentFile and WorkingDirectory in nodered.service 347 | sudo sed -i 's#^User=pi#User='${NODERED_USER}'#; 348 | s#^Group=pi#Group='${NODERED_GROUP}'#; 349 | s#^WorkingDirectory=/home/pi#WorkingDirectory='${NODERED_HOME}'#; 350 | s#^EnvironmentFile=-/home/pi/.node-red#EnvironmentFile=-/etc/node-red#; 351 | s!^Environment="NODE_OPTIONS=--max_old_space_size=512"!#Environment="NODE_OPTIONS=--max_old_space_size=512"!' ${SYSTEMDFILE}.temp 352 | 353 | if test -f "${SYSTEMDFILE}"; then 354 | # there's already a systemd script 355 | EXISTING_FILE=$(md5sum ${SYSTEMDFILE} | awk '$1 "${SYSTEMDFILE}" {print $1}'); 356 | TEMP_FILE=$(md5sum ${SYSTEMDFILE}.temp | awk '$1 "${SYSTEMDFILE}.temp" {print $1}'); 357 | 358 | if [[ $EXISTING_FILE == $TEMP_FILE ]]; 359 | then 360 | : # silent procedure 361 | else 362 | echo "Customized systemd script found @ ${SYSTEMDFILE}. To prevent loss of modifications, we'll not recreate the systemd script." | sudo tee -a /var/log/nodered-install.log >>/dev/null 363 | echo "If you want the installer to recreate the systemd script, please delete or rename the current script & re-run the installer." | sudo tee -a /var/log/nodered-install.log >>/dev/null 364 | CHAR="- Skipped - existing script is customized." 365 | fi 366 | sudo rm ${SYSTEMDFILE}.temp 367 | else 368 | sudo mv ${SYSTEMDFILE}.temp ${SYSTEMDFILE} 369 | fi 370 | # make environment file for systemd 371 | sudo mkdir -p /etc/node-red 372 | if test ! -f /etc/node-red/environment; then 373 | echo "# Node-RED EnvironmentFile for Systemd Service" | sudo tee -a /etc/node-red/environment >>/dev/null 374 | echo "# after edit this file `sudo systemctl restart nodered` to reload Node-red with the new options" | sudo tee -a /etc/node-red/environment >>/dev/null 375 | 376 | echo "" | sudo tee -a /etc/node-red/environment >>/dev/null 377 | echo "# uncomment and edit if running on low memory resource hardware" | sudo tee -a /etc/node-red/environment >>/dev/null 378 | echo "#NODE_OPTIONS=--max_old_space_size=512" | sudo tee -a /etc/node-red/environment >>/dev/null 379 | 380 | echo "" | sudo tee -a /etc/node-red/environment >>/dev/null 381 | echo "# uncomment next line and edit if you need an http proxy" | sudo tee -a /etc/node-red/environment >>/dev/null 382 | echo "#HTTP_PROXY=my.httpproxy.server.address" | sudo tee -a /etc/node-red/environment >>/dev/null 383 | 384 | echo "" | sudo tee -a /etc/node-red/environment >>/dev/null 385 | echo "# uncomment the next line for a more verbose log output" | sudo tee -a /etc/node-red/environment >>/dev/null 386 | echo "#NODE_RED_OPTIONS=-v" | sudo tee -a /etc/node-red/environment >>/dev/null 387 | echo "" | sudo tee -a /etc/node-red/environment >>/dev/null 388 | 389 | echo "Created /etc/node-red/environment for systemd service." | sudo tee -a /var/log/nodered-install.log >>/dev/null 390 | fi 391 | sudo systemctl daemon-reload 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 392 | echo -ne " Update systemd script $CHAR\r\n" 393 | 394 | if [[ ${OPEN_FIREWALL} == "y" ]]; then 395 | echo "Now add firewall rule for 1880" | sudo tee -a /var/log/nodered-install.log >>/dev/null 396 | if sudo curl -sL -o /etc/firewalld/services/nodered.xml https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.xml 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi 397 | sudo firewall-cmd --zone=public --add-service=nodered 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 398 | sudo firewall-cmd --reload 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 399 | sudo firewall-cmd --zone=public --add-service=nodered --permanent 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 400 | sudo firewall-cmd --reload 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 401 | echo -ne " Update public zone firewall rule $CHAR\r\n" 402 | else 403 | echo "Not adding firewall rule" | sudo tee -a /var/log/nodered-install.log >>/dev/null 404 | echo -ne " Not adding firewall rule -\r\n" 405 | fi 406 | echo -ne "\r\n\r\n\r\n" 407 | echo -ne "All done.\r\n" 408 | echo -ne " You can now start Node-RED with the command \033[0;36mnode-red-start\033[0m\r\n" 409 | echo -ne " Then point your browser to \033[0;36mlocalhost:1880\033[0m or \033[0;36mhttp://{your_ip-address}:1880\033[0m\r\n" 410 | echo -ne "\r\nStarted $time1 - Finished $(date)\r\n\r\n" 411 | echo "Finished : "$time1 | sudo tee -a /var/log/nodered-install.log >>/dev/null 412 | ;; 413 | * ) 414 | echo " " 415 | exit 1 416 | ;; 417 | esac 418 | 419 | --------------------------------------------------------------------------------