#!/bin/bash

# If you don't want to build, but just run coinye on Ubuntu 14, 
# You can use this script to install the needed dependencies.

# It needs root access for a few tasks, so the whole
# script must be ran as root. But because we don't 
# want everything to be done by Root, and we want to 
# keep our system clean, we'll ask which username
# be used for the more mundane stuff. This users name
# will be kept in $COINYEUSER. If /home/$COINYEUSER does 
# not exist, we'll assume it's a new user and create it
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 

   # -k force password, despite timestamp
   sudo -k /bin/bash $0 $USER
   exit
fi

set -e # Quit on any errors

COINYEUSER=$1
echo install coinye for $COINYEUSER, using sudo/root only where needed.




# I did not get past this in Debian 10 though...! )-:
echo -e "\n\n**************** update repositories ********************\n"

add-apt-repository ppa:bitcoin/bitcoin -y

apt update
# Don't... apt upgrade!!!

apt install -y vim \
               libdb4.8 \
               libdb4.8++ \
               libboost-filesystem1.54.0 \
               libboost-program-options1.54.0 \
               libboost-thread1.54.0 \
               # libboost-system-dev \
               # libboost-filesystem-dev \
               # libboost-program-options-dev \
               # libboost-thread-dev \
               # libminiupnpc-dev \

               #libdb++-dev \
               # build-essential \
               # git \
               # libssl-dev \
               # libboost-all-dev \
               # qt4-qmake \
               # libqt4-dev \


echo -e "\n\n**************** Get Coinye Binary ********************\n"
sudo -u $COINYEUSER wget http://www.coinye.net/downloads/ubuntu_14_64/coinyecoin-qt
sudo -u $COINYEUSER chmod +x coinyecoin-qt


# echo -e "\n\n**************** Generate extra files  ********************\n"
# # Make a config file for test/run, disable this if you only want to build! ###

# DATADIR=/home/$COINYEUSER/build_coinye/sample_datadir/
# CONF=$DATADIR/coinyecoin.conf

# echo "Creating dir $DATADIR for $COINYEUSER"
# sudo -u $COINYEUSER mkdir $DATADIR
# sudo -u $COINYEUSER chmod 700 $DATADIR

# sudo -u $COINYEUSER touch $CONF # To make it owned by $COINYEUSER
# sudo -u $COINYEUSER echo rpcuser=coinyecoinrpc >> $CONF
# RND=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 6 ; echo '')
# sudo -u $COINYEUSER echo rpcpassword=ChangeThisIfYouWantToUseRpc_$RND >> $CONF
# sudo -u $COINYEUSER echo "upnp=1" >> $CONF
# sudo -u $COINYEUSER echo "" >> $CONF

# sudo -u $COINYEUSER wget http://www.coinye.net/schmapi/nodes.php -O nodes.txt
# sudo -u $COINYEUSER cat nodes.txt | grep addnode >> $CONF

# ## Make a test/run script:
# STARTFILE=test_coinye-qt.sh
# sudo -u $COINYEUSER touch $STARTFILE
# sudo -u $COINYEUSER chmod +x $STARTFILE
# sudo -u $COINYEUSER echo "#!/bin/bash" > $STARTFILE
# sudo -u $COINYEUSER echo "/home/$COINYEUSER/build_coinye/coinyecoin-qt --datadir=$DATADIR" >> $STARTFILE

# echo "DONE. "
# echo "output files in: /home/$COINYEUSER/build_coinye/"
# echo "You can test your coinye build by running build_coine/$STARTFILE"


# ./coinyecoin-qt
