Skip to content

Instantly share code, notes, and snippets.

@utaani
Last active October 2, 2019 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utaani/2243b7501a2cde52d93cb85c91f173e8 to your computer and use it in GitHub Desktop.
Save utaani/2243b7501a2cde52d93cb85c91f173e8 to your computer and use it in GitHub Desktop.
admin password creator for Node-RED on Raspberry Pi
#!/bin/bash
# password setter for Node-RED on Raspberry Pi
# auther: utaani@ueno.org
#
# usage: bash nrpiadminpass.sh password
#
# this script will change Pi default Node-RED file.
# after that, you need nodered restart with node-red-restart
# password
INPUTPASS=$1
# target settings.js
SETTINGSJS="/home/pi/.node-red/settings.js"
# check edited setting.js
CHECKER=`grep '// type: "credentials",' $SETTINGSJS`
if [ -z "$CHECKER" ]; then
echo "changed settings.js found. you must change settings.js by hand."
exit 1
fi
# create password crypted string
ADMINPASS=`/usr/bin/node -e "console.log(require('/usr/lib/node_modules/node-red/node_modules/bcryptjs/dist/bcrypt.min.js').hashSync('$INPUTPASS'));"`
# backup org file
cp $SETTINGSJS $SETTINGSJS.org
# replace adminAuth line
REPLINE="adminAuth: { type:\"credentials\", users: [{ username: \"admin\", password: \"$ADMINPASS\", permissions: \"*\" }] },"
sed -i "/adminAuth\:/c $REPLINE" $SETTINGSJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment