Skip to content

Instantly share code, notes, and snippets.

@AlexanderGW
Created August 27, 2022 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexanderGW/5f1baab44098bc1950ec62f680ec9b12 to your computer and use it in GitHub Desktop.
Save AlexanderGW/5f1baab44098bc1950ec62f680ec9b12 to your computer and use it in GitHub Desktop.
Geth (go-ethereum) service auto-update
#!/bin/bash
# Geth auto-update
# Installs and reloads `geth` service, if version is different
# Assumes you have installed and are running a systemd service
# `/etc/systemd/system/geth.service`
#
# [Unit]
# Description=Go Ethereum Client
# After=network.target
# Wants=network.target
# [Service]
# User=geth
# Group=geth
# Type=simple
# Restart=always
# RestartSec=45
# ExecStart=/usr/local/bin/geth ..."
# [Install]
# WantedBy=default.target
GETH_BUILD_PATH=~/go/bin/geth
GETH_DEPLOY_PATH=/usr/local/bin/geth
# Get latest geth binary
go install github.com/ethereum/go-ethereum/cmd/geth@latest
# Compare versions to determine continuation
GETH_OLD_VERSION=`${GETH_DEPLOY_PATH} version | sed -n '2p'`
GETH_NEW_VERSION=`${GETH_BUILD_PATH} version | sed -n '2p'`
# Exit, nothing has changed
if [ "$GETH_NEW_VERSION" == "$GETH_OLD_VERSION" ]; then
echo "Nothing to update for geth.";
exit 0;
fi
echo "Current ${GETH_OLD_VERSION}";
echo "New ${GETH_NEW_VERSION}";
# Remove old binary
echo -n "Removing old geth... "
rm -f $GETH_DEPLOY_PATH
echo "OK"
# Deploy new binary
echo -n "Installing new geth... "
mv $GETH_BUILD_PATH $GETH_DEPLOY_PATH
echo "OK"
# Ensure new binary executable
echo -n "Make new geth executable... "
chmod +x $GETH_DEPLOY_PATH
echo "OK"
# Ensure SELinux context for systemd
TEST_SELINUX=`sestatus | grep mode`
if [${#TEST_SELINUX} -gt 0 ]; then
echo -n "Give geth bin_t context... "
chcon -R -t bin_t $GETH_DEPLOY_PATH
echo "OK"
fi
# Restart Geth
echo -n "Restart geth service... "
service geth restart
echo "OK"
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment