Skip to content

Instantly share code, notes, and snippets.

@Stadicus
Last active February 23, 2018 21:35
Show Gist options
  • Save Stadicus/caccfcbac9d409e711526a199cf9413b to your computer and use it in GitHub Desktop.
Save Stadicus/caccfcbac9d409e711526a199cf9413b to your computer and use it in GitHub Desktop.
bash welcome script for RaspiBolt
#!/bin/sh
# original script by Damian Mee https://github.com/meeDamian
# copy script to /etc/update-motd.d/
# set colors
color_red='\033[0;31m'
color_green='\033[0;32m'
color_yellow='\033[0;33m'
color_gray='\033[0;37m'
color_darkgray='\033[1;30m'
# get memory
load=$(w | grep load | cut -c11-)
ram_total=$(free -m | grep Mem | awk '{ print $2 }')
ram_avail=$(free -m | grep Mem | awk '{ print $7 }')
if [ ${ram_avail} -lt 100 ]; then
color_ram="${color_red}\e[7m"
else
color_ram=${color_green}
fi
# get storage
sd_free=$(df -h | grep "/$" | awk '{ print $4 }')
sd_free_ratio=$(printf "%d" "$(df -h | grep "/$" | awk '{ print $4/$2*100 }')") 2>null
if [ ${sd_free_ratio} -lt 10 ]; then
color_sd="${color_red}"
else
color_sd=${color_green}
fi
hdd_free=$(df -h | grep "/mnt/hdd$" | awk '{ print $4 }')
hdd_free_ratio=$(printf "%d" "$(df -h | grep '/mnt/hdd$' | awk '{ print $4/$2*100 }')") 2>null
if [ ${hdd_free_ratio} -lt 10 ]; then
color_hdd="${color_red}\e[7m"
else
color_hdd=${color_green}
fi
# get network traffic
network_rx=$(ifconfig eth0 | grep 'RX packets' | awk '{ print $6$7 }' | sed 's/[()]//g')
network_tx=$(ifconfig eth0 | grep 'TX packets' | awk '{ print $6$7 }' | sed 's/[()]//g')
# Bitcoin blockchain
btc_path=$(command -v bitcoin-cli)
if [ ! -z ${btc_path} ]; then
btc_line1="₿itcoin"
chain="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')"
if [ ! -z $chain ]; then
btc_line1="${btc_line1} (${chain}net)"
# get sync status
progress="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.verificationprogress')"
percentage=$(printf "%.1f%%" "$(echo $progress | awk '{print 100 * $1}')")
sync_ratio=$(printf "%d" "$(echo $progress | awk '{print 100 * $1}')") 2>null
if [ -n $percentage ]; then
if [ ${sync_ratio} -gt 98 ]; then
btc_line2="${color_gray}Synced ${color_green}${sync_ratio}%"
else
btc_line2="${color_yellow}Syncing ${percentage}"
fi
fi
# get last known block
last_block="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockcount)"
if [ ! -z "${last_block}" ]; then
btc_line2="${btc_line2} ${color_gray}(block ${last_block})"
fi
# get mem pool transactions
mempool="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getmempoolinfo | jq -r '.size')"
else
btc_line2="${color_red}NOT RUNNING\t\t"
fi
fi
# get public IP
if [ $chain = "test" ]
then
public_check=$(curl -s https://bitnodes.earn.com/api/v1/nodes/me-18333/ | jq .success)
public_port=18333
else
public_check=$(curl -s https://bitnodes.earn.com/api/v1/nodes/me-8333/ | jq .success)
public_port=8333
fi
public_ip=$(curl -s ipinfo.io/ip)
if [ $public_check = "true" ]; then
public_line1="${color_green}Yes"
public_line2="${color_gray}${public_ip}:${public_port}"
else
public_line1="${color_red}Not reachable"
public_line2="${color_gray}${public_ip}:${public_port}"
fi
# get lightning info
ln_alias="$(/home/bitcoin/bin/eclair-cli getinfo | jq -r '.alias')" 2>null
ln_port="$(/home/bitcoin/bin/eclair-cli getinfo | jq -r '.port')"
ln_peers_total="$(/home/bitcoin/bin/eclair-cli peers | jq '. | length')"
ln_peers_online="$(/home/bitcoin/bin/eclair-cli peers | jq '[.[] | select(.state=="CONNECTED")] | length')"
ln_channels_total="$(/home/bitcoin/bin/eclair-cli channels | jq '. | length')"
ln_channels_online="$(/home/bitcoin/bin/eclair-cli channels | jq '[.[] | select(.state=="NORMAL")] | length')"
echo "
${color_green}
.~~. .~~. ${color_yellow}$(hostname): ${color_gray}Bitcoin Core + Lightning${color_green}
'. \ ' ' / .' ${color_yellow}-------------------------------------------------------------------------------${color_red}
.~ .~~~..~. ${color_gray}${load}${color_red}
: .~.'~'.~. :
~ ( ) ( ) ~ ${color_yellow}Ressources free\t\t${btc_line1}\t\tLightning${color_red}
( : '~'.~.'~' : ) ${color_gray}Memory ${color_ram}${ram_avail}M / ${ram_total}M ${color_gray}${btc_line2} ${color_gray}${ln_alias}${color_red}
~ .~ ( ) ~. ~ ${color_gray}SDD ${color_sd}${sd_free} (${sd_free_ratio}%) ${color_gray}Public ${public_line1} ${color_gray} ${ln_peers_online}/${ln_peers_total} Peers online${color_red}
( : '~' : ) ${color_gray}HDD ${color_hdd}${hdd_free} (${hdd_free_ratio}%) ${color_gray}${public_line2} ${color_gray} ${ln_channels_online}/${ln_channels_total} Channels online${color_red}
'~ .~~~. ~' ${color_gray}Bandwidth ▲ ${network_tx} ${color_gray}Mempool ${mempool} tx${color_red}
'~' ${color_gray} ▼ ${network_rx}${color_red}
$(tput -T xterm sgr0)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment