#!/bin/bash
echo 'Nym mix-node auto-updater'
if [ ! -x /usr/bin/wget ] ; then
    sudo apt install wget -y -qq< "/dev/null"
fi
. $HOME/.bash_profile
curl -s https://api.nodes.guru/logo.sh | bash
version=$(nym-mixnode --version | grep "Nym Mixnode" | awk '{print $3}')
node_id=$(systemctl status nym-mixnode | grep '\-\-id ' | sed 's#.*--id \(\)#\1#' | sed 's/\s.*$//')
echo "reading node id..."
sleep 10
echo 'export node_id='${node_id} >> $HOME/.bash_profile
echo "You are running mixnode version" $version "with id" $node_id
echo "Stopping mixnode"
sudo systemctl stop nym-mixnode
echo "Downloading new binaries (v0.12.1)"
wget -O nym-mixnode https://github.com/nymtech/nym/releases/download/v0.12.1/nym-mixnode && chmod +x nym-mixnode
sudo mv nym-mixnode /usr/bin
version=$(nym-mixnode --version | grep "Build Version" | awk '{print $3}')
echo "Current mixnode version:" $version
echo "Initialize your mixmode"
nym-mixnode init --id $node_id --host $(curl ifconfig.me) --wallet-address $wallet
echo "Upgrading your mixnode config"
nym-mixnode upgrade --id $node_id
echo "DefaultLimitNOFILE=65535" >> /etc/systemd/system.conf
sudo systemctl daemon-reload
sudo systemctl enable nym-mixnode
sudo systemctl start nym-mixnode
echo "Upgrade complete!"
echo "Current mixnode version:" $version