Last active
November 16, 2019 22:03
-
-
Save TravisMullen/35868f1a622316a7fa74c6b278810cbd to your computer and use it in GitHub Desktop.
Update binaries (WIP)
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 -e | |
# @example | |
# ./update-cli-binaries.sh zcoin zcoinofficial/zcoin linux64 | |
# | |
BINARY_INSTALL_DIR='/usr/local/bin' | |
# get CRYPTO_NAME | |
if [ "$#" -lt 1 ] | |
then | |
read -e -p "Crypto Name: " CRYPTO_NAME | |
else | |
CRYPTO_NAME=${1} | |
fi | |
# get CRYPTO_REPO_URL | |
# example: PIVX-Project/PIVX, zcoinofficial/zcoin | |
if [ "$#" -lt 2 ] | |
then | |
read -e -p "Github USERNAME (for repo owner): " CRYPTO_REPO_USERNAME | |
read -e -p "Github REPONAME: " CRYPTO_REPONAME | |
CRYPTO_REPO_URL="${CRYPTO_REPO_USERNAME}/${CRYPTO_REPONAME}" | |
else | |
CRYPTO_REPO_URL=${2} | |
fi | |
# get CRYPTO_REPO_URL | |
# example: x86_64-linux, linux64 | |
if [ "$#" -lt 3 ] | |
then | |
read -e -p "Github binary target substring: " BINARY_FILENAME_TARGET | |
else | |
BINARY_FILENAME_TARGET=${3} | |
fi | |
# validate and download checksum file | |
CHECKSUM_FILE=$(curl -s "https://api.github.com/repos/${CRYPTO_REPO_URL}/releases/latest" | grep 'browser_' | cut -d\" -f4 | grep ".asc") | |
if [ -z CHECKSUM_FILE ] | |
then | |
echo "check shasum file (.asc) not found at repo in repo release" | |
exit | |
else | |
echo "Found shasum file: ${CHECKSUM_FILE}" | |
rm -f SHA256SUMS.asc | |
wget $CHECKSUM_FILE -O SHA256SUMS.asc | |
fi | |
# get checksum hash | |
SHA256_HASH=$(awk "/$BINARY_FILENAME_TARGET/" SHA256SUMS.asc | awk '{print $1; exit}') | |
echo "Valid file hash: ${SHA256_HASH}" | |
# validate CRYPTO_REPO_URL BINARY_FILENAME_TARGET | |
BINARY_URL=$(curl -s "https://api.github.com/repos/${CRYPTO_REPO_URL}/releases/latest" | grep 'browser_' | cut -d\" -f4 | grep "${BINARY_FILENAME_TARGET}") | |
if [ -z $BINARY_URL ] | |
then | |
echo "${BINARY_FILENAME_TARGET} file not found in repo release" | |
exit | |
else | |
echo "Found binary file: ${BINARY_URL}" | |
fi | |
# start the install/update | |
CRYPTO_NAME=$(echo $CRYPTO_NAME | awk '{print tolower($0)}') | |
echo "Updating '${CRYPTO_NAME}' node Daemon (${CRYPTO_NAME}d) and CLI (${CRYPTO_NAME}-cli)" | |
if pgrep -x "${CRYPTO_NAME}d" > /dev/null | |
then | |
echo "Stopping '${CRYPTO_NAME}' node Daemon (${CRYPTO_NAME}d)" | |
"${CRYPTO_NAME}-cli" stop | |
fi | |
if pgrep -x "monit" > /dev/null | |
then | |
echo "Stopping Monit - Process '${CRYPTO_NAME}d'" | |
sudo monit stop "${CRYPTO_NAME}d" | |
fi | |
# echo "URL of updated binary..." | |
# echo "example: https://github.com/pivxofficial/pivx/releases/download/v0.13.7.10/pivx-0.13.7.10-linux64.tar.gz" | |
# read -e -p "Github URL : " BINARY_URL | |
# read -e -p "SHA256 Hash : " SHA256_HASH | |
UPDATED_BINARY_NAME="updated-binaries.tar.gz" | |
rm -f $UPDATED_BINARY_NAME | |
wget $BINARY_URL -O $UPDATED_BINARY_NAME | |
if [[ $(shasum -a 256 $UPDATED_BINARY_NAME | awk '{print $1; exit}') == $SHA256_HASH ]] | |
then | |
echo "*** File check is valid. ***" | |
else | |
echo "SHA256 Hash not valid, file not correct, try again..." | |
exit | |
fi | |
echo "Successful download now removing old binaries before extraction." | |
sudo rm -rf $HOME/${CRYPTO_NAME}* # not to be confused with "$HOME/.${CRYPTO_NAME}" | |
tar -zxvf $UPDATED_BINARY_NAME | |
echo "Copy new ${CRYPTO_NAME} binaries" | |
sudo ln -sf $HOME/${CRYPTO_NAME}*/**/${CRYPTO_NAME}d ${BINARY_INSTALL_DIR}/${CRYPTO_NAME}d #incase make install fails (error occuring in 0.13.6.4 ) | |
sudo ln -sf $HOME/${CRYPTO_NAME}*/**/${CRYPTO_NAME}-cli ${BINARY_INSTALL_DIR}/${CRYPTO_NAME}-cli #incase make install fails | |
sudo ln -sf $HOME/${CRYPTO_NAME}*/**/${CRYPTO_NAME}-tx ${BINARY_INSTALL_DIR}/${CRYPTO_NAME}-tx | |
echo "Starting ${CRYPTO_NAME} daemon" | |
sleep 5 | |
# start it up! | |
which monit | |
if test $? -eq 0 | |
then | |
echo "Starting & Reloading Monit - Process '${CRYPTO_NAME}d'" | |
sudo monit restart "${CRYPTO_NAME}d" | |
sudo monit reload | |
else | |
$(echo "${CRYPTO_NAME}d -daemon -reindex") | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment