Last active
October 2, 2019 05:12
-
-
Save utaani/2243b7501a2cde52d93cb85c91f173e8 to your computer and use it in GitHub Desktop.
admin password creator for Node-RED on Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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