mynode/rootfs/standard/usr/bin/mynode_chpasswd.sh

34 lines
1.2 KiB
Bash
Raw Normal View History

2019-06-15 23:02:44 +00:00
#!/bin/bash
PASSWORD=$1
HASH_SHA256=$(echo -n "$PASSWORD" | sha256sum | awk '{print $1}')
2021-11-22 02:58:22 +00:00
HASH_BCRYPT=$(/usr/local/bin/python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$PASSWORD\", bcrypt.gensalt()).decode(\"ascii\"))")
# If pass did not change and all hash files exist, exit success
if [ -f /home/bitcoin/.mynode/.hashedpw ]; then
OLD_HASH_SHA256=$(cat /home/bitcoin/.mynode/.hashedpw)
if [ "$OLD_HASH_SHA256" = "$HASH_SHA256" ] && [ -f /home/bitcoin/.mynode/.hashedpw_bcrypt ]; then
exit 0;
fi
fi
2019-06-15 23:02:44 +00:00
# Change Linux Password
echo "admin:$PASSWORD" | chpasswd
2019-07-28 23:34:08 +00:00
# Save hashed password
echo "$HASH_SHA256" > /home/bitcoin/.mynode/.hashedpw
echo "$HASH_BCRYPT" > /home/bitcoin/.mynode/.hashedpw_bcrypt
2019-07-28 23:34:08 +00:00
2019-06-15 23:02:44 +00:00
# Change RTL password
if [ -f /mnt/hdd/mynode/rtl/RTL-Config.json ]; then
sed -i "s/\"multiPassHashed\":.*/\"multiPassHashed\": \"$HASH_SHA256\",/g" /mnt/hdd/mynode/rtl/RTL-Config.json
systemctl restart rtl &
fi
2020-07-16 04:33:32 +00:00
# Change Thunderhub password
if [ -f /mnt/hdd/mynode/thunderhub/thub_config.yaml ]; then
sed -i "s#masterPassword:.*#masterPassword: \"thunderhub-$HASH_BCRYPT\"#g" /mnt/hdd/mynode/thunderhub/thub_config.yaml
systemctl restart thunderhub &
fi