Last active
November 29, 2023 15:16
-
-
Save tommyv1987/4dca7cc175b70742c9ecb3d072eb8539 to your computer and use it in GitHub Desktop.
Update your Nym Binaries
This file contains hidden or 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 | |
set -x | |
if [[ $EUID -ne 0 ]]; then | |
echo "you need to root :)" | |
exit 1 | |
fi | |
read -rp "enter the service file to stop (e.g., nym-mixnode.service): " SERVICE_NAME | |
read -rp "supply the release branch for the component (e.g., 2023.4-galaxy): " RELEASE_BRANCH | |
read -rp "please supply the full path to your existing running location of the binary (e.g., /home/nym/): " EXISTING_PATH | |
read -rp "supply the NYM component you want to update (e.g., nym-mixnode, nym-gateway): " COMPONENT_NAME | |
GET_CURRENT_VERSION=$("$EXISTING_PATH/$COMPONENT_NAME" --version | grep 'Build Version' | awk '{print $3}') | |
COMPONENT_URL="https://github.com/nymtech/nym/releases/download/nym-binaries-v$RELEASE_BRANCH/$COMPONENT_NAME" | |
if ! curl --output /dev/null --silent --head --fail "$COMPONENT_URL"; then | |
echo "url does not exist :( $COMPONENT_URL" | |
exit 1 | |
fi | |
if systemctl is-active --quiet "$SERVICE_NAME"; then | |
echo "stopping service: $SERVICE_NAME" | |
sleep 2 | |
sudo systemctl stop "$SERVICE_NAME" | |
else | |
echo "service $SERVICE_NAME is not running." | |
fi | |
EXISTING_BINARY="$EXISTING_PATH/$COMPONENT_NAME" | |
BACKUP_BINARY="$EXISTING_BINARY-$(date '+%Y-%m-%d-%H-%M-%S')" | |
if [[ -f $EXISTING_BINARY ]]; then | |
echo "backing up existing binary - $BACKUP_BINARY" | |
cp "$EXISTING_BINARY" "$BACKUP_BINARY" | |
rm -f "$EXISTING_BINARY" | |
else | |
echo "no existing binary found to backup." | |
fi | |
echo "getching latest binary from $COMPONENT_URL" | |
curl -L -o "$COMPONENT_NAME" "$COMPONENT_URL" | |
if [[ ! -f $COMPONENT_NAME ]]; then | |
echo "Failed to download the binary." | |
exit 1 | |
fi | |
echo "download successful." | |
echo "execute permissions on the new binary." | |
chmod 755 "$COMPONENT_NAME" | |
#get version | |
NEW_VERSION=$(./"$COMPONENT_NAME" --version | grep 'Build Version' | awk '{print $3}') | |
NYM_HOME=$(getent passwd $(whoami) | cut -d: -f6) | |
case $COMPONENT_NAME in | |
nym-mixnode) | |
sed -i "s/version = '$GET_CURRENT_VERSION'/version = '$NEW_VERSION'/" $NYM_HOME/.nym/mixnodes/*/config/config.toml | |
;; | |
nym-gateway) | |
sed -i "s/version = '$GET_CURRENT_VERSION'/version = '$NEW_VERSION'/" $NYM_HOME/.nym/gateways/*/config/config.toml | |
;; | |
nym-network-requester) | |
sed -i "s/version = '$GET_CURRENT_VERSION'/version = '$NEW_VERSION'/" $NYM_HOME/.nym/service-providers/network-requester/*/config/config.toml | |
;; | |
*) | |
echo "invalid component name. try following: nym-mixnode, nym-gateway, nym-network-requester." | |
;; | |
esac | |
read -rp "input the path to move the new binary (e.g., /home/nym/): " EXECUTABLE_BINARY_PATH | |
mv "$COMPONENT_NAME" "$EXECUTABLE_BINARY_PATH" | |
if [[ ! -f "$EXECUTABLE_BINARY_PATH/$COMPONENT_NAME" ]]; then | |
echo "failed to move the binary to $EXECUTABLE_BINARY_PATH." | |
exit 1 | |
fi | |
echo "starting service $SERVICE_NAME" | |
sudo systemctl start "$SERVICE_NAME" | |
echo "update process complete." | |
exit 0; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to add the comments about what the script does right into it as comments? I can do it as well, I have the notes from you.