Created
August 27, 2022 20:35
-
-
Save AlexanderGW/5f1baab44098bc1950ec62f680ec9b12 to your computer and use it in GitHub Desktop.
Geth (go-ethereum) service auto-update
This file contains 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/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