Last active
September 7, 2018 07:42
-
-
Save meeDamian/21a215f42ad928782188892c82fa5015 to your computer and use it in GitHub Desktop.
This is a MOTD for a raspberry pi running bitcoind and either lnd or lightning (or both). To install, download and execute `install.sh` file.
This file contains hidden or 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/sh | |
. /usr/local/lib/metrics/colors.sh | |
. /usr/local/lib/metrics/board.sh | |
echo | |
echo -n "${WHITE}Raspberry Pi ($(get_host), $(get_public_ip), $(get_local_ip))${RESET_STYLE} " && uname -rm | |
uptime |
This file contains hidden or 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/sh | |
. /usr/local/lib/metrics/colors.sh | |
. /usr/local/lib/metrics/board.sh | |
. /usr/local/lib/metrics/bitcoind.sh | |
ram_total="$(get_memory | grep ram | grep total | cut -f 4)" | |
ram_used="$(get_memory | grep ram | grep used | cut -f 4)" | |
if is_swap_enabled; [ "$?" -eq "0" ]; then | |
swap_total="$(get_memory | grep swap | grep total | cut -f 4)" | |
swap_used="$(get_memory | grep swap | grep used | cut -f 4)" | |
swap_info="swap: ${BOLD}${swap_used} / ${swap_total}${RESET_STYLE}" | |
fi | |
sd_total="$(get_storage | grep sd | grep total | cut -f 4)" | |
sd_used="$(get_storage | grep sd | grep used | cut -f 4)" | |
if is_external_storage_available; [ "$?" -eq "0" ]; then | |
ext_total=$(get_storage | grep ext | grep total | cut -f 4) | |
ext_used=$(get_storage | grep ext | grep used | cut -f 4) | |
ext_info="external: ${BOLD}${ext_used} / ${ext_total}${RESET_STYLE}" | |
fi | |
if [ ! -z "$(get_bitcoind_binary_path)" ]; then | |
btc_line1="₿itcoin Core" | |
if is_bitcoind_available; [ "$?" -ne "0" ]; then | |
btc_line2="${RED}NOT RUNNING" | |
else | |
version="$(get_bitcoind_version)" | |
if [ -z "${version}" ]; then | |
btc_line2="${YELLOW}STARTING OR IDLE…" | |
else | |
btc_line1="${btc_line1} ${BOLD}(v${version}, $(get_bitcoind_chain))${RESET_STYLE}" | |
btc_line2="peers connected: ${BOLD}$(get_bitcoind_peer_count)${RESET_STYLE}\t${SOME_COLOR}last block: ${BOLD}$(get_bitcoind_blocks) ($(get_bitcoind_progress))${RESET_STYLE}" | |
btc_line3="balance: ${BOLD}$(get_bitcoind_balance btc)${RESET_STYLE}\t${SOME_COLOR}mempool transactions: ${BOLD}$(get_bitcoind_mempool_count)${RESET_STYLE}" | |
addresses="$(get_bitcoind_addresses | tr "\n" "\t")" | |
if [ ! -z "${addresses}" ]; then | |
btc_line4="accessible as" | |
btc_line5="${addresses}" | |
fi | |
fi | |
fi | |
fi | |
echo "${GREEN} | |
.~~. .~~. resources used | |
'. \ ' ' / .' mem: ${BOLD}${ram_used} / ${ram_total}${RESET_STYLE}${GREEN}\t\t${swap_info}${RED} | |
.~ .~~~..~. ${GREEN}storage: ${BOLD}${sd_used} / ${sd_total}${RESET_STYLE}${GREEN}\t${ext_info}${RED} | |
: .~.'~'.~. : | |
~ ( ) ( ) ~ ${SOME_COLOR}${btc_line1}${RED} | |
( : '~'.~.'~' : ) ${SOME_COLOR}${btc_line2}${RED} | |
~ .~ ( ) ~. ~ ${SOME_COLOR}${btc_line3}${RED} | |
( : '~' : ) | |
'~ .~~~. ~' ${SOME_COLOR}${btc_line4}${RED} | |
'~' ${SOME_COLOR}${BOLD}${btc_line5}${RESET_STYLE}${RED} | |
${RESET_STYLE}" |
This file contains hidden or 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/sh | |
. /usr/local/lib/metrics/colors.sh | |
. /usr/local/lib/metrics/lnd.sh | |
if [ -z "$(get_lnd_binary_path)" ]; then | |
exit 0 | |
fi | |
if is_lnd_available; [ "$?" -ne "0" ]; then | |
ln_line2="${RED}NOT RUNNING" | |
else | |
version="$(get_lnd_version)" | |
if [ -z "${version}" ]; then | |
ln_line2="${YELLOW}STARTING OR IDLE…" | |
else | |
ln_line1="${BLUE}${BOLD}($(get_lnd_chain), $(get_lnd_alias), ${version})${RESET_STYLE}" | |
ln_line2="id: ${BOLD}$(get_lnd_pubkey)${RESET_STYLE}" | |
ln_line3="peers connected: ${BOLD}$(get_lnd_peer_count)${RESET_STYLE}\t${BLUE}synced to block: ${BOLD}$(get_lnd_blocks)${RESET_STYLE}" | |
ln_line4="relayed HTLCs #: ${BOLD}$(get_lnd_relayed_txs_count)${RESET_STYLE}${BLUE}\tearned: ${BOLD}$(get_lnd_relayed_txs_earned)${RESET_STYLE}" | |
ln_line5="channels: ${BOLD}$(get_lnd_channels_count_all)${RESET_STYLE} (${YELLOW}${BOLD}pending: $(get_lnd_channels_count_pending)${RESET_STYLE}${BLUE}, ${GREEN}${BOLD}open: $(get_lnd_channels_count_open)${RESET_STYLE}${BLUE}, ${RED}${BOLD}closing: $(get_lnd_channels_count_closing)${RESET_STYLE}${BLUE})" | |
ln_line6="balance:" | |
s_max="$(get_lnd_funds_chan_spend_max)" | |
if [ "${s_max}" -gt "0" ]; then | |
max_spend=" (max: $(sat_to_btc "${s_max}"))" | |
fi | |
ln_line7="on-chain: ${BOLD}$(get_lnd_funds_onchain btc)${RESET_STYLE}\t${BLUE}LN spend : ${BOLD}$(get_lnd_funds_chan_spend_total btc)${max_spend}${RESET_STYLE}" | |
r_max="$(get_lnd_funds_chan_receive_max)" | |
if [ "${r_max}" -gt "0" ]; then | |
max_receive=" (max: $(sat_to_btc "${r_max}"))" | |
fi | |
ln_line8="\t\t\t\tLN receive: ${BOLD}$(get_lnd_funds_chan_receive_total btc)${max_receive}${RESET_STYLE}" | |
ln_line9="accessible as" | |
ln_line10="${BOLD}$(get_lnd_addresses | tr "\n" "\t")${RESET_STYLE}" | |
ln_line12="connstring:" | |
ln_line14="${BOLD}$(get_lnd_pubkey)@$(get_lnd_addresses | head -n 1)" | |
fi | |
fi | |
echo "${YELLOW} ____ ${BLUE}lnd ${YELLOW}⚡ ${ln_line1}${YELLOW} | |
/ / ${BLUE}${ln_line2}${YELLOW} | |
/ / ${BLUE}${ln_line3}${YELLOW} | |
/ /_ ${BLUE}${ln_line4}${YELLOW} | |
/_ / ${BLUE}${ln_line5}${YELLOW} | |
/ / ${BLUE}${ln_line6}${YELLOW} | |
/ /_ ${BLUE}${ln_line7}${YELLOW} | |
/ / ${BLUE}${ln_line8}${YELLOW} | |
/ / ${BLUE}${ln_line9}${YELLOW} | |
/ / ${BLUE}${ln_line10}${YELLOW} | |
// ${BLUE}${ln_line11}${YELLOW} | |
/ ${BLUE}${ln_line12}${YELLOW} | |
${ln_line14} | |
${RESET_STYLE}" |
This file contains hidden or 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/sh | |
. /usr/local/lib/metrics/colors.sh | |
. /usr/local/lib/metrics/lightningd.sh | |
if [ -z "$(get_lightningd_binary_path)" ]; then | |
exit 0 | |
fi | |
if is_lightningd_available; [ "$?" -ne "0" ]; then | |
ln_line2="${RED}NOT RUNNING" | |
else | |
version="$(get_lightningd_version)" | |
if [ -z "${version}" ]; then | |
ln_line2="${YELLOW}STARTING OR IDLE…" | |
else | |
ln_line1="${BLUE}${BOLD}($(get_lightningd_chain), $(get_lightningd_alias), ${version})${RESET_STYLE}" | |
ln_line2="id: ${BOLD}$(get_lightningd_pubkey)${RESET_STYLE}" | |
ln_line3="peers connected: ${BOLD}$(get_lightningd_peer_count)${RESET_STYLE}\t${BLUE}synced to block: ${BOLD}$(get_lightningd_blocks)${RESET_STYLE}" | |
# ln_line4="relayed HTLCs #: ${BOLD}${relay_txs}${RESET_STYLE}${BLUE}\tearned: ${BOLD}${relay_earnings}${RESET_STYLE}" | |
ch_other="$(get_lightningd_channels_count_other)" | |
if [ "${ch_other}" -ne "0" ]; then | |
other_channels="${BLUE}, other: ${ch_other}${RESET_STYLE}" | |
fi | |
ln_line5="channels: ${BOLD}$(get_lightningd_channels_count_all)${RESET_STYLE} (${YELLOW}${BOLD}pending: $(get_lightningd_channels_count_pending)${RESET_STYLE}${BLUE}, ${GREEN}${BOLD}open: $(get_lightningd_channels_count_open)${RESET_STYLE}${BLUE}, ${RED}${BOLD}closing: $(get_lightningd_channels_count_closing)${RESET_STYLE}${other_channels}${BLUE})" | |
ln_line6="balance:" | |
s_max="$(get_lightningd_funds_chan_spend_max)" | |
if [ "${s_max}" -gt "0" ]; then | |
max_spend=" (max: $(sat_to_btc "${s_max}"))" | |
fi | |
ln_line7="on-chain: ${BOLD}$(get_lightningd_funds_onchain btc)${RESET_STYLE}\t${BLUE}LN spend : ${BOLD}$(get_lightningd_funds_chan_spend_total btc)${max_spend}${RESET_STYLE}" | |
r_max="$(get_lightningd_funds_chan_receive_max)" | |
if [ "${r_max}" -gt "0" ]; then | |
max_receive=" (max: $(sat_to_btc "${r_max}"))" | |
fi | |
ln_line8="\t\t\t\tLN receive: ${BOLD}$(get_lightningd_funds_chan_receive_total btc)${max_receive}${RESET_STYLE}" | |
ln_line9="accessible as" | |
ipv4=$(get_lightningd_address ipv4) | |
ipv6=$(get_lightningd_address ipv6) | |
torv2=$(get_lightningd_address torv2) | |
torv3=$(get_lightningd_address torv3) | |
# I'm sorry for the `if` hell below 😬 | |
if [ ! -z ${ipv6} ]; then | |
ln_line9="${ln_line9} ipv6: ${BOLD}${ipv6}${RESET_STYLE}" | |
fi | |
if [ ! -z ${torv3} ]; then | |
ln_line10="torv3: ${BOLD}${torv3}${RESET_STYLE}" | |
fi | |
if [ ! -z ${torv2} ]; then | |
legacy_line="torv2: ${BOLD}${torv2}${RESET_STYLE}" | |
fi | |
if [ ! -z "${legacy_line}" ]; then | |
legacy_line="${legacy_line}\t" | |
fi | |
if [ ! -z ${ipv4} ]; then | |
legacy_line="${legacy_line}${BLUE}ipv4: ${BOLD}${ipv4}${RESET_STYLE}" | |
fi | |
if [ ! -z "${ln_line10}" ]; then | |
ln_line11="${legacy_line}" | |
else | |
ln_line10="${legacy_line}" | |
fi | |
ln_line12="connstring:" | |
ln_line14="${BOLD}$(get_lightningd_pubkey)@$(get_lightningd_address ipv4)" | |
fi | |
fi | |
echo "${YELLOW} ____ ${BLUE}c-lightning ${YELLOW}⚡ ${ln_line1}${YELLOW} | |
/ / ${BLUE}${ln_line2}${YELLOW} | |
/ / ${BLUE}${ln_line3}${YELLOW} | |
/ /_ ${BLUE}${ln_line4}${YELLOW} | |
/_ / ${BLUE}${ln_line5}${YELLOW} | |
/ / ${BLUE}${ln_line6}${YELLOW} | |
/ /_ ${BLUE}${ln_line7}${YELLOW} | |
/ / ${BLUE}${ln_line8}${YELLOW} | |
/ / ${BLUE}${ln_line9}${YELLOW} | |
/ / ${BLUE}${ln_line10}${YELLOW} | |
// ${BLUE}${ln_line11}${YELLOW} | |
/ ${BLUE}${ln_line12}${YELLOW} | |
${ln_line14} | |
${RESET_STYLE}" |
This file contains hidden or 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/sh | |
. /usr/local/lib/metrics/colors.sh | |
. /usr/local/lib/metrics/board.sh | |
if is_swap_enabled; [ "$?" -ne "0" ]; then | |
exit 0 | |
fi | |
echo "${RED}$(get_memory | grep swap | grep used | cut -f 4) of SWAP is being used! It can significanly shorten the life span of your microSD card. | |
Disable SWAP with:${RESET_STYLE} | |
sudo swapoff --all && sudo apt-get remove dphys-swapfile && sudo apt-get autoremove | |
${RED} | |
Or disable this warning with:${RESET_STYLE} | |
sudo chmod -x /etc/update-motd.d/30-swap-warning" |
This file contains hidden or 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/sh | |
if [ "$(id -u)" -ne "0" ]; then | |
echo "Installing motd requires root" | |
exit 1 | |
fi | |
command -v jq 2>&1 1>/dev/null | |
if [ "$?" -ne "0" ]; then | |
echo "'jq' is needed by functions within this script. If you're on Debian-based system, you can install it with:" | |
echo "\tsudo apt install jq" | |
exit 1 | |
fi | |
DEST=/etc/update-motd.d | |
warning_path="${DEST}/30-swap-warning" | |
if [ ! -f "${warning_path}" ] || [ -x "${warning_path}" ]; then | |
warning_path="" | |
fi | |
# install "metrics" dependencies from https://gist.github.com/meeDamian/fec388a943e0d4e64c876e6196a8d18f | |
wget -qO- 'https://gist.githubusercontent.com/meeDamian/fec388a943e0d4e64c876e6196a8d18f/raw/12e8741e133146ce4bfd98548462916b068ea554/install.sh' | grep -v 'print.sh' | sh | |
mkdir -p "${DEST}" | |
wget -qN 'https://gist.githubusercontent.com/meeDamian/21a215f42ad928782188892c82fa5015/raw/040f60ae160e54c8162bec117ab0f036250c3284/10-uname' -P "${DEST}" | |
wget -qN 'https://gist.githubusercontent.com/meeDamian/21a215f42ad928782188892c82fa5015/raw/829e8993c0d7f6cf8b78300b913d033a8d5da738/20-raspberry-bitcoin' -P "${DEST}" | |
wget -qN 'https://gist.githubusercontent.com/meeDamian/21a215f42ad928782188892c82fa5015/raw/73c78d5f3eaf4ce96119d50b8f9b96b0f30f325c/23-raspberry-lnd' -P "${DEST}" | |
wget -qN 'https://gist.githubusercontent.com/meeDamian/21a215f42ad928782188892c82fa5015/raw/f3d534e484ea41b81bcd237254c88a3513d7973d/26-raspberry-lightning' -P "${DEST}" | |
wget -qN 'https://gist.githubusercontent.com/meeDamian/21a215f42ad928782188892c82fa5015/raw/e108d3088ad8cf1d9aea733687b45243bcbb0d4d/30-swap-warning' -P "${DEST}" | |
chmod -R +x "${DEST}/" | |
if [ ! -z "${warning_path}" ]; then | |
chmod -x "${warning_path}" | |
fi | |
echo "" > /etc/motd | |
run-parts --lsbsysinit /etc/update-motd.d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment