Created
February 24, 2018 01:27
-
-
Save Znuff/2d1276628ad0acb92f43d108ad44001b to your computer and use it in GitHub Desktop.
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 | |
daemon="smartcashd" | |
cli="smartcash-cli" | |
stopcli="stop" | |
# environment setup, make it pretty | |
tred=$(tput setaf 1) | |
tgreen=$(tput setaf 2) | |
tyellow=$(tput setaf 3) | |
tblue=$(tput setaf 4) | |
tmagenta=$(tput setaf 5) | |
tcyan=$(tput setaf 6) | |
treset=$(tput sgr0) | |
tclear=$(tput clear) | |
# starting blank | |
echo $tclear | |
echo "------------------------------" | |
echo $tblue"Masternode Upgrade Script$treset" | |
echo "------------------------------" | |
# checking for current user id, we should be running as root | |
if (( $(id -u) != 0 )); then | |
echo $tred"I need to be root to run this. Please run this with $(tput setab 7)sudo$treset$tred or log in directly as root.$treset" | |
echo -e "\n" | |
exit 1 | |
fi | |
# grabbing the details of the currently running daemon | |
BINPID=$(pidof $daemon) | |
if (( $BINPID )); then | |
echo "Found $tcyan$daemon$treset running with:" | |
echo " * PID: $tyellow$BINPID$treset." | |
BINPATH=$(readlink -f /proc/$BINPID/exe) | |
echo " * Path: $tyellow$BINPATH$treset." | |
BINUID=$(awk '/^Uid:/{print $2}' /proc/$BINPID/status) | |
BINUSER=$(getent passwd $BINUID | awk -F: '{print $1}') | |
echo " * Running as: $tyellow$BINUSER$treset." | |
DISTRO=$(lsb_release -s -c) | |
echo " * Running under: $tyellow$DISTRO$treset." | |
echo "------------------------------" | |
else | |
echo $tred"No $daemon found running. Exiting.$treset" | |
exit 1 | |
fi | |
# stopping currently running daemon | |
BINDIR=$(dirname $BINPATH) | |
chmod +x $BINDIR/$cli | |
su - $BINUSER -c "$BINDIR/$cli $stopcli" | |
# just in case... | |
killall -9 $daemon 2> /dev/null | |
apt update | |
apt install smartcashd | |
su - $BINUSER -c "$daemon" | |
echo "Upgrade procedure$tgreen COMPLETE$treset. Happy masternode-ing." | |
echo -e "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment