#!/bin/bash
echo Installing needed packages
sudo apt install wget build-essential yasm

echo Retrieving needed files.
wget http://ck.kolivas.org/apps/soloproxy/soloproxy-0.9.5.tar.bz2

echo Extracting proxy files
tar xf soloproxy-0.9.5.tar.bz2
cd soloproxy-0.9.5

echo Configuring
CFLAGS="-O2 -march=native" ./configure --prefix=/usr

echo Building
make -j2 2>/dev/null

echo You may configure your proxy now or press enter for defaults to edit it later
echo -n "Enter your bitcoin address (14BMjogz69qe8hk9thyzbmR5pg34mVKB1e): "
read BTC
echo -n "Enter your starting mining difficulty (10000): "
read DIFF
if [ $BTC ]; then
	echo Updating config to mine to BTC address $BTC
	sed -i 's/14BMjogz69qe8hk9thyzbmR5pg34mVKB1e/'$BTC'/' ckproxy.conf
fi
if [ $DIFF ]; then
	echo Updating config to mine at starting diff $DIFF
	sed -i 's/10000/'$DIFF'/' ckproxy.conf
fi

echo Installing now
sudo make install

echo Updating system limits to allow 100,000 open files
echo "* 	 soft     nofile         100000" | sudo tee -a /etc/security/limits.conf
echo "* 	 hard     nofile         100000" | sudo tee -a /etc/security/limits.conf

echo You may edit the ckproxy.conf file if you wish to change your configuration
echo If you have more than 1000 devices you will need to log out and in again
echo for the open file limits to take effect.
echo Enter the soloproxy-0.9.5 directory and start ckproxy by typing 'ckproxy' and enter
echo Point your miners to the IP address of this machine on port 3334
