Created
April 29, 2018 17:14
-
-
Save sascha1337/f48c8b9a60dcfcf286959f79f7298e04 to your computer and use it in GitHub Desktop.
Upgrade IRI to 1.4.2.4_RC to keep existing database # By Nuriel Shem-Tov http://iri-playbook.readthedocs.io/ #experimental
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 | |
# Upgrade IRI to 1.4.2.4_RC to keep existing database | |
# By Nuriel Shem-Tov http://iri-playbook.readthedocs.io/ | |
# WARNING BACKUP BEFORE TESTING THIS OR WAIT FOR MAIN RELEASE | |
# If you set first argument to the script "i-trust-nuriel" it will download | |
# a precompiled version from x-vps.com. | |
set -e | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
echo "Please change to root: 'sudo su -' and re-run" | |
exit 1 | |
fi | |
cat <<EOF | |
****************************************** | |
Welcome to IOTA IRI Upgrade to 1.4.2.4_RC! | |
****************************************** | |
What is this script going to do? | |
1. Check the distribution (Ubuntu or CentOS) | |
2. Check if you want to compile the jar yourself or download a precompiled one. | |
3. Stop IRI | |
4. Download or pre-compile the jar (which will install maven as it is a requirement) | |
5. Copy the resulting jar to the target directory and create a symbolic link | |
6. Configure the IRI configuration files (version and set RESCAN_DB = true). | |
7. Restart IRI | |
8. Remove the RESCAN_DB = true (it is needed once) | |
By pressing 'y' you agree to upgrade to 1.4.2.4_RC and keep the existing database. | |
In addition, note that this script will only work with installations done by | |
the iri-playbook. | |
EOF | |
read -p "Do you wish to proceed? [y/N] " yn | |
if echo "$yn" | grep -v -iq "^y"; then | |
echo Cancelled | |
exit 1 | |
fi | |
echo | |
echo "Do you want to download the pre-compiled source from Nuriel's server? Otherwise the jar will compile on your server." | |
read -p "Click 'y' to download the pre-compiled source from Nuriel. Any other key to compile it on your server (CTRL-C to exit now)." DOWNLOAD_NURIEL | |
function set_dist() { | |
if [ -f /etc/os-release ]; then | |
# freedesktop.org and systemd | |
. /etc/os-release | |
OS=$NAME | |
VER=$VERSION_ID | |
elif type lsb_release >/dev/null 2>&1; then | |
# linuxbase.org | |
OS=$(lsb_release -si) | |
VER=$(lsb_release -sr) | |
elif [ -f /etc/lsb-release ]; then | |
# For some versions of Debian/Ubuntu without lsb_release command | |
. /etc/lsb-release | |
OS=$DISTRIB_ID | |
VER=$DISTRIB_RELEASE | |
elif [ -f /etc/debian_version ]; then | |
# Older Debian/Ubuntu/etc. | |
OS=Debian | |
VER=$(cat /etc/debian_version) | |
elif [ -f /etc/SuSe-release ]; then | |
# Older SuSE/etc. | |
echo "Unsupported OS." | |
exit 1 | |
elif [ -f /etc/redhat-release ]; then | |
# Older Red Hat, CentOS, etc. | |
echo "Old OS version. Minimum required is 7." | |
exit 1 | |
else | |
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc. | |
OS=$(uname -s) | |
VER=$(uname -r) | |
fi | |
} | |
# Auto-detect distribution | |
set_dist | |
# Set variables | |
IRI_LATEST=1.4.2.4 | |
IRI_CONFIG=/etc/default/iri | |
if [[ "$OS" =~ ^(CentOS|Red) ]]; then | |
IRI_CONFIG=/etc/sysconfig/iri | |
fi | |
echo "Stopping current IRI. This might take a moment..." | |
systemctl stop iri | |
# Download from Nuriel, or compile locally | |
if echo "$DOWNLOAD_NURIEL" | grep -iq "^y"; then | |
echo "Download pre-compiled iri-1.4.2.4_RC.jar ..." | |
curl -L https://x-vps.com/iri-1.4.2.4_RC.jar --output /var/lib/iri/target/iri-1.4.2.4_RC.jar | |
else | |
if [[ "$OS" =~ ^Ubuntu ]]; then | |
# Install maven | |
apt-get install oracle-java8-installer maven -y | |
elif [[ "$OS" =~ ^(CentOS|Red) ]]; then | |
# Install maven | |
yum install maven -y | |
fi | |
echo "Clone and compile iri-1.4.2.4_RC.jar" | |
rm -rf /tmp/iri | |
cd /tmp | |
git clone -b "v1.4.2.4_RC" https://github.com/iotaledger/iri && cd iri | |
mvn clean compile | |
mvn package | |
# No typo here, backslash to force overwrite if file already exists | |
\cp target/iri-1.4.2.4_RC.jar /var/lib/iri/target/. | |
fi | |
echo "Creating symbolic link from /var/lib/iri/target/iri-1.4.2.4_RC.jar to /var/lib/iri/target/iri-1.4.2.4.jar" | |
ln -sf /var/lib/iri/target/iri-1.4.2.4_RC.jar /var/lib/iri/target/iri-1.4.2.4.jar | |
echo "Setting new version in config files" | |
sed -i "s/^IRI_VERSION=.*$/IRI_VERSION=$IRI_LATEST/" $IRI_CONFIG | |
sed -i "s/^api_version.*$/api_version: $IRI_LATEST/" $HOME/.nbctl | |
echo "Setting 'RESCAN_DB = true' in /var/lib/iri/iri.ini." | |
grep -q "^RESCAN_DB = true" /var/lib/iri/iri.ini || echo "RESCAN_DB = true" >>/var/lib/iri/iri.ini | |
echo "Starting up IRI..." | |
systemctl start iri | |
echo "Removing the rescan flag (it is only needed once)." | |
sed -i '/RESCAN_DB = true/d' /var/lib/iri/iri.ini | |
echo "Done... IRI is starting up. Please note that the API port and peering ports will not be available during the rescan process." | |
echo "You can view the logs using 'journalctl -u iri -f'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment