Skip to content

Commit

Permalink
Plugins - Add self-hosted CSM-Sentinel plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
coincashew committed Oct 30, 2024
1 parent 501a8b2 commit 30a36f9
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 1 deletion.
76 changes: 75 additions & 1 deletion ethpillar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 🙌 Ask questions on Discord:
# * https://discord.gg/dEpAVWgFNB

EP_VERSION="3.0.0"
EP_VERSION="3.1.0"

# VARIABLES
export BASE_DIR="$HOME/git/ethpillar" && cd $BASE_DIR
Expand Down Expand Up @@ -866,6 +866,73 @@ while true; do
done
}

submenuPluginSentinel(){
while true; do
getNetworkConfig
getBackTitle
# Define the options for the submenu
SUBOPTIONS=(
1 "View Logs"
2 "Start sentinel"
3 "Stop sentinel"
4 "Restart sentinel"
5 "Edit .env configuration"
6 "Update to latest release"
7 "Uninstall plugin"
- ""
10 "Back to main menu"
)

# Display the submenu and get the user's choice
SUBCHOICE=$(whiptail --clear --cancel-button "Back" \
--backtitle "$BACKTITLE" \
--title "Plugin - CSM Sentinel" \
--menu "\nGet private notifications for your CSM Node Operator ID on Telegram\nConnect with your bot at t.me/[YOUR-BOT-NAME] and initiate service by typing /start" \
0 0 0 \
"${SUBOPTIONS[@]}" \
3>&1 1>&2 2>&3)

if [ $? -gt 0 ]; then # user pressed <Cancel> button
break
fi

# Handle the user's choice from the submenu
case $SUBCHOICE in
1)
sudo bash -c 'docker logs csm-sentinel -f -n 300 | ccze -A'
ohai "Press ENTER to exit logs."
read
;;
2)
sudo docker start csm-sentinel
;;
3)
sudo docker stop csm-sentinel
;;
4)
sudo docker restart csm-sentinel
;;
5)
sudo nano /opt/ethpillar/plugin-sentinel/csm-sentinel/.env
if whiptail --title "Reload env and restart services" --yesno "Do you want to restart with updated env?" 8 78; then
sudo docker stop csm-sentinel
runScript plugins/sentinel/plugin_csm_sentinel.sh -s
sudo docker start csm-sentinel
fi
;;
6)
runScript plugins/sentinel/plugin_csm_sentinel.sh -u
;;
7)
runScript plugins/sentinel/plugin_csm_sentinel.sh -r
;;
10)
break
;;
esac
done
}

submenuPluginCSMValidator(){
while true; do
getBackTitle
Expand Down Expand Up @@ -989,6 +1056,7 @@ while true; do
# Define the options for the submenu
SUBOPTIONS=(
1 "Lido CSM Validator: Activate an extra validator service. Re-use this node's EL/CL."
2 "CSM-Sentinel: Sends notifications for your CSM Node Operator ID. Self-hosted. Docker. Telegram."
- ""
99 "Back to main menu"
)
Expand Down Expand Up @@ -1016,6 +1084,12 @@ while true; do
fi
submenuPluginCSMValidator
;;
2)
if [[ ! -d /opt/ethpillar/plugin-sentinel ]]; then
runScript plugins/sentinel/plugin_csm_sentinel.sh -i
fi
submenuPluginSentinel
;;
99)
break
;;
Expand Down
104 changes: 104 additions & 0 deletions plugins/sentinel/plugin_csm_sentinel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash

# Author: coincashew.eth | coincashew.com
# License: GNU GPL
# Source: https://github.com/coincashew/ethpillar
# Description: csm-sentinel helper script
#
# Made for home and solo stakers 🏠🥩

# Base directory with scripts
BASE_DIR=$HOME/git/ethpillar

# Variables
#GITHUB_URL=https://api.github.com/repos/skhomuti/csm-sentinel/releases/latest
#GITHUB_RELEASE_NODES=https://github.com/skhomuti/csm-sentinel/releases
DESCRIPTION="CSM Sentinel is a telegram bot that sends you notifications for your CSM Node Operator events. Self-hosted. Uses docker."
DOCUMENTATION="https://github.com/skhomuti/csm-sentinel"
SOURCE_CODE="https://github.com/skhomuti/csm-sentinel"
APP_NAME="csm-sentinel"
PLUGIN_NAME="CSM Sentinel Plugin"
PLUGIN_SOURCE_PATH="$BASE_DIR/plugins/sentinel"
PLUGIN_INSTALL_PATH="/opt/ethpillar/plugin-sentinel"

#Asks to update
function upgrade(){
if whiptail --title "Update $PLUGIN_NAME" --yesno "Reminder: Always read the release notes for breaking changes: $SOURCE_CODE\n\nDo you want to update?" 10 78; then
cd $PLUGIN_INSTALL_PATH/$APP_NAME
sudo git pull
sudo docker stop $APP_NAME
sudo docker build -t csm-sentinel .
__start
fi
}

# Installs latest release
function install(){
exec sudo $PLUGIN_SOURCE_PATH/sentinel-installer.sh
}

# Starts the docker container
function __start(){
cd $PLUGIN_INSTALL_PATH/$APP_NAME
if docker ps -aq --filter=name=$APP_NAME > /dev/null 2>&1; then
sudo docker rm -f $APP_NAME
fi
sudo docker run --net=host -d --env-file=.env --name csm-sentinel -v csm-sentinel-persistent:/app/.storage csm-sentinel
}

# Uninstall
function removeAll() {
if whiptail --title "Uninstall $APP_NAME" --defaultno --yesno "Are you sure you want to remove $APP_NAME" 9 78; then
sudo docker stop "$APP_NAME"
sudo docker rm -f $APP_NAME
sudo docker rmi -f "$APP_NAME"
sudo docker volume rm csm-sentinel-persistent
sudo rm -rf "$PLUGIN_INSTALL_PATH"
whiptail --title "Uninstall finished" --msgbox "You have uninstalled $APP_NAME." 8 78
fi
}

# Displays usage info
function usage() {
cat << EOF
Usage: $(basename "$0") [-i] [-u] [-r] [-s]
$APP_NAME Helper Script
Options)
-i Install $APP_NAME
-u Upgrade $APP_NAME
-r Remove $APP_NAME
-s Start $APP_NAME
-h Display help
About $APP_NAME)
- $DESCRIPTION
- Source code: $SOURCE_CODE
- Documentation: $DOCUMENTATION
EOF
}

# Process command line options
while getopts :iurhs opt; do
case ${opt} in
i ) install ;;
u ) upgrade ;;
r ) removeAll ;;
s ) __start ;;
h)
usage
exit 0
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
usage
exit 1
;;
:)
echo "Option -${OPTARG} requires an argument." >&2
usage
exit 1
;;
esac
done
149 changes: 149 additions & 0 deletions plugins/sentinel/sentinel-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/bin/bash

# Author: coincashew.eth | coincashew.com
# License: GNU GPL
# Source: https://github.com/coincashew/ethpillar
# Description: csm-sentinel installer script
#
# Made for home and solo stakers 🏠🥩

set -e
set -x

setWhiptailColors(){
export NEWT_COLORS='root=,black
border=green,black
title=green,black
roottext=red,black
window=red,black
textbox=white,black
button=black,green
compactbutton=white,black
listbox=white,black
actlistbox=black,white
actsellistbox=black,green
checkbox=green,black
actcheckbox=black,green'
}
setWhiptailColors

MSG_ABOUT="About: CSM Sentinel is a telegram bot that sends you notifications for your CSM Node Operator events.
\nMaintainer: This bot was developed and is maintained by @skhomuti, a member of the Lido Protocol community, to simplify the process of subscribing to the important events for CSM.
\nLocally ran instance: This bot will run on your node, self-hosted for your own improved reliability and privacy.
\nSource Code: https://github.com/skhomuti/csm-sentinel
\nContinue to install?"

# Intro screen
if ! whiptail --title "CSM Sentinel: Running your own instance" --yesno "$MSG_ABOUT" 20 78; then exit; fi

# Get network
_NETWORK=$(whiptail --title "Set Network" --menu \
"For which network are you running CSM Sentinel?" 10 78 2 \
"mainnet" "ethereum" \
"holesky" "testnet" \
3>&1 1>&2 2>&3)

MSG_TOKEN="First, you need to create a bot on Telegram.
\nTo create a bot, initiate a conversation with @BotFather (https://t.me/botfather), select the 'New Bot' option, and follow the prompts to set up your bot's name, username, and initial settings.
\nEnter the token you received from the BotFather.
\nExample: 270485614:AAHfiqksKZ8WmR2zSjiQ7_v4TMAKdiHm9T0"

# Get token
while true; do
_TOKEN=$(whiptail --title "Set Token from BotFather" --inputbox "$MSG_TOKEN" 17 78 --ok-button "Submit" 3>&1 1>&2 2>&3)
if [ -z "$_TOKEN" ]; then exit; fi #pressed cancel
if [[ "${_TOKEN}" =~ [0-9]+:.* ]]; then
break
else
whiptail --title "Error" --msgbox "Invalid TOKEN. Try again." 8 78
fi
done

MSG_WEB3_SOCKET_PROVIDER="The websocket provider for your node.
\nPreferably, use your own local execution client node e.g. you already have for CSM validators.
\nDefault example: ws://127.0.0.1:8545"

# Get token
_WEB3_SOCKET_PROVIDER=$(whiptail --title "Set WEB3_SOCKET_PROVIDER" --inputbox "$MSG_WEB3_SOCKET_PROVIDER" 15 78 "ws://127.0.0.1:8545" --ok-button "Submit" 3>&1 1>&2 2>&3)
if [ -z "$_WEB3_SOCKET_PROVIDER" ]; then exit; fi #pressed cancel

# Install packages
apt-get update
apt-get upgrade -y

install_docker() {
# Install Docker
sudo apt-get install --yes docker.io
# Verify that we can at least get version output
if ! docker --version; then
echo "ERROR: Is Docker installed?"
exit 1
fi
}

if ! command -v docker &> /dev/null; then
install_docker
fi

# Setup files
mkdir -p /opt/ethpillar/plugin-sentinel
cd /opt/ethpillar/plugin-sentinel
if [[ ! -d /opt/ethpillar/plugin-sentinel/csm-sentinel ]]; then
git clone https://github.com/skhomuti/csm-sentinel
cd csm-sentinel
else
cd csm-sentinel && git pull
fi

# Build image
docker build -t csm-sentinel .
docker volume create csm-sentinel-persistent

# Create env file
case $_NETWORK in
mainnet)
cat << EOF > /opt/ethpillar/plugin-sentinel/csm-sentinel/.env
FILESTORAGE_PATH=.storage
TOKEN=${_TOKEN}
WEB3_SOCKET_PROVIDER=${_WEB3_SOCKET_PROVIDER}
CSM_ADDRESS=0xdA7dE2ECdDfccC6c3AF10108Db212ACBBf9EA83F
ACCOUNTING_ADDRESS=0x4d72BFF1BeaC69925F8Bd12526a39BAAb069e5Da
FEE_DISTRIBUTOR_ADDRESS=0xD99CC66fEC647E68294C6477B40fC7E0F6F618D0
VEBO_ADDRESS=0x0De4Ea0184c2ad0BacA7183356Aea5B8d5Bf5c6e
CSM_STAKING_MODULE_ID=3
ETHERSCAN_URL=https://etherscan.io
BEACONCHAIN_URL=https://beaconcha.in
CSM_UI_URL=https://csm.lido.fi/?ref=ethpillar
EOF
;;
holesky)
cat << EOF > /opt/ethpillar/plugin-sentinel/csm-sentinel/.env
FILESTORAGE_PATH=.storage
TOKEN=${_TOKEN}
WEB3_SOCKET_PROVIDER=${_WEB3_SOCKET_PROVIDER}
CSM_ADDRESS=0x4562c3e63c2e586cD1651B958C22F88135aCAd4f
ACCOUNTING_ADDRESS=0xc093e53e8F4b55A223c18A2Da6fA00e60DD5EFE1
FEE_DISTRIBUTOR_ADDRESS=0xD7ba648C8F72669C6aE649648B516ec03D07c8ED
VEBO_ADDRESS=0xffDDF7025410412deaa05E3E1cE68FE53208afcb
CSM_STAKING_MODULE_ID=4
ETHERSCAN_URL=https://holesky.etherscan.io
BEACONCHAIN_URL=https://holesky.beaconcha.in
CSM_UI_URL=https://csm.testnet.fi/?ref=ethpillar
EOF
;;
*)
echo "Unsupported network"
exit 1
;;
esac

# Start docker container
cd /opt/ethpillar/plugin-sentinel/csm-sentinel
sudo docker run -d --env-file=.env --name csm-sentinel -v csm-sentinel-persistent:/app/.storage csm-sentinel

MSG_COMPLETE="Done! Congratulations on your new locally hosted CSM Sentinel bot.
\nYou will find it at t.me/[YOUR-BOT-NAME].
Follow your Node Operator id."

# Intro screen
whiptail --title "CSM Sentinel: Install Complete" --msgbox "$MSG_COMPLETE" 10 78
7 changes: 7 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ function uninstallPlugins(){
sudo userdel csm_nimbus_validator
sudo rm -rf /opt/ethpillar/plugin-csm;
fi
if [[ -d /opt/ethpillar/plugin-sentinel ]]; then
sudo docker stop csm-sentinel
sudo docker rm csm-sentinel
sudo docker rmi csm-sentinel
sudo docker volume rm csm-sentinel-persistent
sudo rm -rf /opt/ethpillar/plugin-sentinel
fi
}

function cleanupMisc(){
Expand Down

0 comments on commit 30a36f9

Please sign in to comment.