#!/bin/bash
# Easy pepecoin resync script. 
# wallet.dat and pepecoin.conf are backed up by default. Edit this script if you need to back up other files or .pepecoin/backups
#
# Assumes ~/pepecoin and ~/.pepecoin
#

echo
echo Easy pepecoin resync script.
echo
echo wallet.dat and pepecoin.conf are backed up to ~/resync by default.
echo
echo
echo Stopping pepecoind.
~/pepecoin/src/pepecoind stop

echo Waiting 7 sconds for pepecoind to stop.
sleep 7

echo
echo Force killing pepecoind just in case.
echo
pkill -9 pepecoind

echo Copying pepecoin.conf and wallet.dat to /home/USER/resync
echo

mkdir -p ~/resync
cp ~/.pepecoin/pepecoin.conf ~/resync
cp ~/.pepecoin/wallet.dat ~/resync

echo
echo Done. Downloading latest blockchain snapshot to ~/resync. . .
echo

wget http://snap.memetic.ai/latest.tar.gz -O ~/resync/latest.tar.gz

tar xvf ~/resync/latest.tar.gz -C ~/resync/

echo
echo Moving snap files to ~/.pepecoin and restoring wallet.dat and pepecoin.conf
echo
rm -rf ~/.pepecoin/*
mv ~/resync/latest/* ~/.pepecoin

cp ~/resync/pepecoin.conf ~/.pepecoin/
cp ~/resync/wallet.dat ~/.pepecoin/

echo
echo Removing downloaded snap. Backed up files are left in ~/resync.
echo

rm -rf ~/resync/latest
rm -rf ~/resync/latest.tar.gz

echo
echo Restarting pepecoind...
echo
~/pepecoin/src/pepecoind &

echo Done.

