Skip to content

Instantly share code, notes, and snippets.

@abrkn
Last active October 31, 2018 04:10
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save abrkn/ea3496b675373c93adbf5540487d111e to your computer and use it in GitHub Desktop.
Automatic installation of Drivechain TestDrive
#!/usr/bin/env bash
# AutoTestDrive v7
# Automation Drivechain TestDrive installation for Ubuntu
# Uses Drivenet-9, UTXO-7, Sidechain-8, Payment-1
#
# Changelog
#
# Revision 8
# - Do not restore wallet unless revision 8
# - Fix typo in wallet restore code (payment restored sidechain wallet)
# - Upgrade to Sidechain-9
# - Upgrade to Payment-2
# - Upgrade to Drivenet-10
# - Do not download utxo (loaded coins)
# - Store install script revision number in ~/.drivechain-install-version
#
# Revision 7
# - Fix wallet restore
# - Upgrade to Drivenet-9
# - Upgrade to Sidechain-8
# - Add Payment-1
#
# Revision 6
# - Upgrade to Drivenet-8
#
# Revision 5
# - Add executables drivenet-cli and sidechain-cli to reduce naming confusion
#
# Revision 4
# - Backup and restore wallets
#
set -e
#set -x
# settings
utxo_url='https://drive.google.com/uc?export=download&id=10UQJcwG8R1_KopGdvJZsVcCYY9S-BvR5'
utxo_fn='DriveNet_LoadedCoins_Core_543543.tar.gz'
drivenet_url='https://drive.google.com/uc?export=download&id=1xGZUAqAxAyDVxopqZk4-xtWQAl9N7LOP'
sidechain_url='https://drive.google.com/uc?export=download&id=1EOLYkGEOVTSr2HQVG-4e9yueVLvuS4X5'
payment_url='https://drive.google.com/uc?export=download&id=1dH7ArRboO7iZLV96-D5-okRFLatp7Wl3'
version_fn=~/.drivechain-install-version
[ -f "$version_fn" ] && prev_version=$(cat $version_fn)
version="8"
# constants
utxo_torrent_fn='loaded_coins.dat.torrent'
echo "GIVE ME ROOT PLEASE"
sudo echo
pushd "$HOME"
if [ "$prev_version" = "8" ]; then
# Backup wallets
echo "Attempting to back up wallets"
[ -d .sidechain/wallets ] && tar -czf sidechain-wallets.tar.gz .sidechain/wallets
[ -d .drivenet/wallets ] && tar -czf drivenet-wallets.tar.gz .drivenet/wallets
[ -d .payment/wallets ] && tar -czf payment-wallets.tar.gz .payment/wallets
#[ -f .drivenet/loaded_coins.dat ] && mv .drivenet/loaded_coins.dat .
fi
echo "YOUR .sidechain, .payment and .drivenet data folders WILL BE DELETED. OK? (OR CTRL-C)"
read
rm -rf .drivenet .sidechain .payment drivenet sidechain payment || true
#echo "-- YOU NEED TO PRESS CTRL-C WHEN TORRENT IS FINISHED --"
#echo "PRESS <ENTER>"
#read
# TODO: Only do this if loaded_coins.dat is incorrect. Use sha256sum
#if [ ! -f "$utxo_fn" ]; then
# which transmission-cli || (echo Please install transmission-cli; exit 1)#
#
# rm "$utxo_torrent_fn" || true
# wget -O "$utxo_torrent_fn" "$utxo_url"
# transmission-cli -w . "$utxo_torrent_fn"
#fi
#[ -f $utxo_fn ] && tar zxvf $utxo_fn
# Remove loaded coins from revision 7 or earlier
[ -f "$utxo_fn" ] && rm $utxo_fn
# TODO: This can be generalized in a loop
killall -9 drivenet-qt || true
killall -9 sidechain-qt || true
killall -9 payment-qt || true
wget -O sidechain.tar.gz "$sidechain_url"
mv $(tar zxvf sidechain.tar.gz | rev | rev | head -n1 | sed 's/.$//') sidechain
rm sidechain.tar.gz
wget -O payment.tar.gz "$payment_url"
mv $(tar zxvf payment.tar.gz | rev | rev | head -n1 | sed 's/.$//') payment
rm payment.tar.gz
wget -O drivenet.tar.gz "$drivenet_url"
mv $(tar zxvf drivenet.tar.gz | rev | rev | head -n1 | sed 's/.$//') drivenet
rm drivenet.tar.gz
pushd "/usr/local/bin/"
sudo ln -fs $HOME/drivenet/bin/* .
sudo ln -fs $HOME/sidechain/bin/* .
sudo ln -fs $HOME/payment/bin/* .
echo '#!/usr/bin/env bash
bitcoin-cli -datadir=$HOME/.drivenet -conf=/$HOME/.drivenet/drivenet.conf $@' | sudo tee drivenet-cli
sudo chmod +x drivenet-cli
# $HOME
popd
# NOTE: Removed until loaded coins are back
# will crash
#drivenetd || true
#mv loaded_coins.dat .drivenet/
mkdir -p .drivenet
mkdir -p .sidechain
mkdir -p .payment
# config files (create if dont exist)
touch drivenet.conf
ln -fs $(readlink -f drivenet.conf) $HOME/.drivenet/drivenet.conf
touch sidechain.conf
ln -fs $(readlink -f sidechain.conf) $HOME/.sidechain/sidechain.conf
touch payment.conf
ln -fs $(readlink -f payment.conf) $HOME/.payment/payment.conf
if [ "$prev_version" = "8" ]; then
# Restore wallets
[ -f sidechain-wallets.tar.gz ] && tar -xzf sidechain-wallets.tar.gz
[ -f payment-wallets.tar.gz ] && tar -xzf payment-wallets.tar.gz
[ -f drivenet-wallets.tar.gz ] && tar -xzf drivenet-wallets.tar.gz
fi
echo "All done. You can now run drivenetd or sidechaind"
echo "For your convenience, config files are linked from your homedir"
if [ -d Desktop ]; then
pushd Desktop
ln -fs /usr/local/bin/sidechain-qt
ln -fs /usr/local/bin/drivenet-qt
ln -fs /usr/local/bin/payment-qt
echo "Desktop links for QT created!"
popd
fi
echo -n "$version" > $version_fn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment