Last active
December 21, 2023 13:44
-
-
Save d6n13l0l1v3r/4a0fe01889e2d554df6f605fb159998a to your computer and use it in GitHub Desktop.
update rpc password for those services than don't support rpcauth (.cookiesfile)
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 | |
script_name=$(basename "$0") | |
service=$1 | |
log() { | |
logger -t "$script_name" "$1" | |
} | |
#start log messages | |
log "Script $script_name started with service: $service" | |
#Use awk to extract the user value from .bitcoin/.cookie | |
user=$(awk -F':' '{print $1}' /data/bitcoin/.cookie) | |
# Use awk to extract the password value from .bitcoin/.cookie | |
password=$(awk -F':' '{print $2}' /data/bitcoin/.cookie) | |
if [ "$service" = "mempool" ]; then | |
# Update the value in mempool-config.json using jq | |
jq --arg new_password "$password" --arg new_user "$user" '.CORE_RPC.PASSWORD = $new_password | .SECOND_CORE_RPC.PASSWORD = $new_password |.CORE_RPC.USERNAME= $new_user | .SECOND_CORE_RPC.USERNAME = $new_user' ~/mempool/backend/mempool-config.json > tmp.json && mv tmp.json ~/mempool/backend/mempool-config.json | |
# Set the file permissions to 600 | |
chmod 600 ~/mempool/backend/mempool-config.json | |
elif [ "$service" = "teos" ]; then | |
# Use sed to update the value in .teos/teos.toml | |
sed -i "s/btc_rpc_user = \".*\"/btc_rpc_user = \"$user\"/" ~/.teos/teos.toml | |
sed -i "s/btc_rpc_password = \".*\"/btc_rpc_password = \"$password\"/" ~/.teos/teos.toml | |
# Set the file permissions to 600 | |
chmod 600 ~/.teos/teos.toml | |
elif [ "$service" = "ckpool" ]; then | |
# Update the value in ckpool.conf using jq | |
jq --arg new_password "$password" --arg new_user "$user" '.btcd[0].pass = $new_password | .btcd[0].auth = $new_user' ~/ckpool-solo/ckpool.conf > tmp.conf && mv tmp.conf ~/ckpool-solo/ckpool.conf | |
# Set the file permissions to 600 | |
chmod 600 ~/ckpool-solo/ckpool.conf | |
else | |
log "No service match" | |
exit 1 | |
fi | |
# Check if jq and mv commands were successful | |
if [ $? -ne 0 ]; then | |
log "Error updating Bitcoin RPC password for ${service}" | |
exit 1 | |
fi | |
log "Bitcoin RPC Password update successful for ${service}" | |
exit 0 |
sample output in journalctl
Dec 20 20:29:57 minibolt systemd[1]: Starting CK Pool...
Dec 20 20:30:27 minibolt update_rpcpassword.sh[1465077]: Script update_rpcpassword.sh started with service: ckpool
Dec 20 20:30:27 minibolt update_rpcpassword.sh[1465082]: Bitcoin RPC Password update successful for ckpool
Dec 20 20:30:27 minibolt systemd[1]: Started CK Pool.
Dec 20 20:30:27 minibolt ckpool[1465084]: [2023-12-20 20:30:27.945] ckpool generator starting
Dec 20 20:30:27 minibolt ckpool[1465084]: [2023-12-20 20:30:27.945] ckpool stratifier starting
Dec 20 20:30:27 minibolt ckpool[1465084]: [2023-12-20 20:30:27.945] ckpool connector starting
Dec 20 20:30:27 minibolt ckpool[1465084]: [2023-12-20 20:30:27.947] ckpool connector ready
Dec 20 20:30:28 minibolt ckpool[1465084]: [2023-12-20 20:30:28.313] ckpool generator ready
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sample service definition