| 1 | #!/bin/sh |
| 2 | |
| 3 | NORMAL="\033[1;0m" |
| 4 | STRONG="\033[1;1m" |
| 5 | GREEN="\033[1;32m" |
| 6 | |
| 7 | config=$(find /etc -maxdepth 1 -type f -name bitcoin.conf*) |
| 8 | |
| 9 | randgen() { |
| 10 | output=$(cat /dev/urandom | tr -dc '0-9a-zA-Z!@$%^&*_+-' | head -c${1:-$1}) 2>/dev/null |
| 11 | echo $output |
| 12 | } |
| 13 | |
| 14 | findRandomTcpPort(){ |
| 15 | port=$(( 1024 + $(( $RANDOM % $(( 65534 - 1024 )) )) )) |
| 16 | while netstat -atn | grep -q :$port; do port=$(expr $port + 1); done; echo $port |
| 17 | } |
| 18 | |
| 19 | GenPasswd(){ |
| 20 | sed -i "/rpcuser=/ c \rpcuser=USER-"$(randgen 32)"" $1 |
| 21 | sed -i "/rpcpassword=/ c \rpcpassword=PW-"$(randgen 64)"" $1 |
| 22 | sed -i "/rpcport=/ c \rpcport="$(findRandomTcpPort)"" $1 |
| 23 | print_green "Generated random user / password / port in:" " $1\n" |
| 24 | } |
| 25 | |
| 26 | print_green() { |
| 27 | local prompt="${STRONG}$1${GREEN}$2${NORMAL}" |
| 28 | printf "${prompt}%s" |
| 29 | } |
| 30 | |
| 31 | for file in $config; do |
| 32 | if grep -F "changeme" $file 1>/dev/null; then |
| 33 | GenPasswd $file |
| 34 | fi |
| 35 | done |
| 36 | |
| 37 | exit 0 |