Guest User

Untitled

a guest
Mar 21st, 2017
490
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. username="user"
  2. userpass="password123"
  3. adminname="admin"
  4. adminpass="password123"
  5.  
  6.     cd ~/.node-red/
  7.     sudo service nodered start ; while [ ! -f settings.js ] ; do sudo sleep 1 ; done ; sudo service nodered stop;
  8.     echo " "
  9.     bcryptadminpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $adminpass)
  10.     bcryptuserpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $userpass)
  11.     # echo Encrypted password: $bcryptpass
  12.     cp settings.js settings.js.bak-pre-crypt
  13.     sudo sed -i -e 's#functionGlobalContext: {#\/\/ functionGlobalContext: {#g' settings.js
  14.     sudo sed -i -e 's#\s\s\s\s\},#    \/\/ },#g' settings.js
  15.     sudo sed -i -e 's#^\}#,#g' settings.js
  16.     sudo echo " " > tmpfile
  17.     sudo echo "    httpStatic: '/home/pi/.node-red/public'," >> tmpfile
  18.     sudo echo "    functionGlobalContext: {" >> tmpfile
  19.     sudo echo "        os:require('os')," >> tmpfile
  20.     sudo echo "        moment:require('moment'), " >> tmpfile
  21.     sudo echo "        fs:require('fs')" >> tmpfile
  22.     sudo echo "    }," >> tmpfile
  23.     sudo echo " " >> tmpfile
  24.     sudo echo "    adminAuth: {" >> tmpfile
  25.     sudo echo "        type: \"credentials\"," >> tmpfile
  26.     sudo echo "        users: [{" >> tmpfile
  27.     sudo echo "            username: \"$adminname\"," >> tmpfile
  28.     sudo echo "            password: \"$bcryptadminpass\"," >> tmpfile
  29.     sudo echo "            permissions: \"*\"" >> tmpfile
  30.     sudo echo "        }]" >> tmpfile
  31.     sudo echo "    }," >> tmpfile
  32.     sudo echo " " >> tmpfile
  33.     sudo echo "    httpNodeAuth: {user:\"$username\", pass:\"$bcryptuserpass\"}" >> tmpfile
  34.     sudo echo "}" >> tmpfile
  35.     sudo cat tmpfile >> settings.js
  36.     sudo rm -f tmpfile
RAW Paste Data