#!/bin/bash Usage() { echo "$(basename $0): Downloads and installs litecoind, p2pool, and other coins for merged mining." >&2 echo "Usage:" >&2 echo "To download the source code and compile yourself (slower but more secure):" >&2 echo " ./$(basename $0) --compile" >&2 echo "To download precompiled binaries (faster but less secure):" >&2 echo " ./$(basename $0) --download" >&2 echo "You may also choose to download the litetcoin blockchain via http. Add the following to the command line:" >&2 echo " --http" >&2 echo "If you don't use this, the blockchain will instead download using the built-in peer-to-peer process." >&2 echo "Note: If you choose the --download option to update your current install, it will OVERWRITE your config files!" >&2 echo >&2 exit 1 } # Usage() declare -A CoinUser declare -A CoinPassword declare -A CoinPort declare -A CoinRPCPort declare -A CoinRPCAllowIP declare -A CoinSourceDownload declare -A CoinSourceUpdate declare -A CoinCompileCommand declare -A CoinSymbol #Litecoin CoinUser["litecoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40` CoinPassword["litecoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40` CoinPort["litecoin"]=10332 CoinRPCPort["litecoin"]=10333 CoinRPCAllowIP["litecoin"]=127.0.0.1 CoinSourceDownload["litecoin"]="git clone https://github.com/litecoin-project/litecoin" CoinSourceUpdate["litecoin"]="git pull" CoinCompileCommand["litecoin"]="make -f Makefile" CoinSymbol["litecoin"]=LTC #Viacoin CoinUser["viacoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40` CoinPassword["viacoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40` CoinPort["viacoin"]=5223 CoinRPCPort["viacoin"]=5222 CoinRPCAllowIP["viacoin"]=127.0.0.1 CoinSourceDownload["viacoin"]="git clone https://github.com/viacoin/viacoin" CoinSourceUpdate["viacoin"]="git pull" CoinCompileCommand["viacoin"]="make -f Makefile" CoinSymbol["viacoin"]=VIA #Dogecoin CoinUser["dogecoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40` CoinPassword["dogecoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40` CoinPort["dogecoin"]=7333 CoinRPCPort["dogecoin"]=7332 CoinRPCAllowIP["dogecoin"]=127.0.0.1 CoinSourceDownload["dogecoin"]="git clone https://github.com/dogecoin/dogecoin" CoinSourceUpdate["dogecoin"]="git pull" CoinCompileCommand["dogecoin"]="make -f Makefile.unix" CoinSymbol["dogecoin"]=DOGE CompileCoins="viacoin dogecoin" AllCoins="litecoin $CompileCoins" GetSettings() { if [ $# -lt 1 -o $# -gt 2 -o -z "$1" ] ; then return 98 fi local filepath if [ -n "$2" ] ; then filepath="$2" else filepath="$HOME/.$1/$1.conf" fi if [ ! -r "$filepath" ] ; then return 99 fi local user password port rpcport rpcallowip user="$(grep -ie "^rpcuser" "$filepath" | awk -F= '{print $2}')" password="$(grep -ie "^rpcpassword" "$filepath" | awk -F= '{print $2}')" port="$(grep -ie "^port" "$filepath" | awk -F= '{print $2}')" rpcport="$(grep -e "^rpcport" "$filepath" | awk -F= '{print $2}')" rpcallowip="$(grep -ie "^rpcallowip" "$filepath" | awk -F= '{print $2}')" [ -n "$user" ] && CoinUser["$1"]="$user" [ -n "$password" ] && CoinPassword["$1"]="$password" [ -n "$port" ] && CoinPort["$1"]="$port" [ -n "$rpcport" ] && CoinRPCPort["$1"]="$rpcport" [ -n "$rpcallowip" ] && CoinRPCAllowIP["$1"]="$rpcallowip" [ -z "$user" -o -z "$password" -o -z "$port" -o -z "$rpcport" -o -z "$rpcallowip" ] && return 1 return 0 } # GetSettings() AddSetting() { if [ $# -lt 1 -o $# -gt 4 -o -z "$1" -o -z "$2" -o -z "$3" ] ; then return 98 fi local filepath if [ -n "$4" ] ; then filepath="$4" else filepath="$HOME/.$1/$1.conf" fi if [ ! -r "$filepath" ] ; then return 99 fi local matchstring=$(echo "$2" | sed -e 's/[]\/$*.^|[]/\\&/g') if ! grep -qe "^${matchstring}=" "$filepath" ; then echo "$2=$3" >> "$filepath" return 0 fi return 1 } # AddSetting() ReplaceSetting() { if [ $# -lt 1 -o $# -gt 4 -o -z "$1" -o -z "$2" -o -z "$3" ] ; then return 98 fi local filepath if [ -n "$4" ] ; then filepath="$4" else filepath="$HOME/.$1/$1.conf" fi if [ ! -r "$filepath" ] ; then return 99 fi local matchstring=$(echo "$2" | sed -e 's/[]\/$*.^|[]/\\&/g') if ! grep -qe "^${matchstring}=" "$filepath" ; then echo -e "$2=$3" >> "$filepath" return 0 fi # If we get here, the setting does exist. Update it. grep -ve "^${matchstring}=" "$filepath" > "$filepath.tmp" mv "$filepath.tmp" "$filepath" echo "$2=$3" >> "$filepath" return 1 } # ReplaceSetting() UpdateSettings() { if [ $# -lt 1 -o $# -gt 2 -o -z "$1" ] ; then return 98 fi local filepath if [ -n "$2" ] ; then filepath="$2" else filepath="$HOME/.$1/$1.conf" fi if [ ! -r "$filepath" ] ; then return 99 fi AddSetting "$1" "server" "1" "$filepath" AddSetting "$1" "daemon" "1" "$filepath" AddSetting "$1" "rpcuser" "${CoinUser[$1]}" "$filepath" AddSetting "$1" "rpcpassword" "${CoinPassword[$1]}" "$filepath" ReplaceSetting "$1" "port" "${CoinPort[$1]}" "$filepath" ReplaceSetting "$1" "rpcport" "${CoinRPCPort[$1]}" "$filepath" AddSetting "$1" "rpcallowip" "${CoinRPCAllowIP[$1]}" "$filepath" [ -n "$(tail -1 "$1")" ] && echo "" >> "$filepath" } # UpdateSettings() if [ $# -eq 0 ] ; then Usage else while [ $# -gt 0 ] ; do if [ "--download" = "$1" ] ; then Method="download" elif [ "--compile" = "$1" ] ; then Method="compile" # elif [ "--torrent" = "$1" ] ; then # Blockchain="torrent" elif [ "--http" = "$1" ] ; then Blockchain="http" else echo "Error: Unrecognized parameter on command line. Aborting" >2 Usage fi shift done fi if [ -z "$Method" ] ; then echo "Error: No installation method specified (compile or download). Aborting" >2 Usage fi cat <~/sudoscript.sh #!/bin/sh # Install the pre-req for add-apt-repository #apt-get -y install software-properties-common # Add the litecoin repository #add-apt-repository -y ppa:litecoin-project/litecoin # Update installed packages apt-get -y update apt-get -y dist-upgrade # Install needed packages # Note that litecoind is always installed as a binary, not compiled. apt-get -y install python-software-properties screen git python-rrdtool python-pygame python-scipy python-twisted python-twisted-web python-imaging build-essential libglib2.0-dev libglibmm-2.4-dev python-dev libssl-dev dh-autoreconf libcurl4-openssl-dev libminiupnpc-dev ufw # Firewall ufw default deny # Deny everything unless expressly permitted ufw allow 22/tcp # SSH ufw allow 10333/tcp # litecoin peer to peer ufw allow 5223/tcp # viacoin peer to peer ufw allow 7333/tcp # dogecoin peer to peer ufw allow 9326/tcp # P2pool peer to peer ufw allow 9327/tcp # P2Pool connections and Web interface ufw --force enable # Turn it on EOF echo "Trust me" sleep 2 sudo sh ~/sudoscript.sh #rm ~/sudoscript.sh # Install p2pool if [ -d ~/p2pool/ ] ; then cd ~/p2pool git pull else cd git clone https://github.com/jtoomim/p2pool -b 1mb_segwit p2pool fi # download or compile the binaries. if [ "$Method" = "download" ] ; then cd wget http://91.121.66.157/p2pool-coins-bin.tar.gz # Some security on binaries (trust is a must)- (Switch "false" to "true") if true; then checksum="$(md5sum p2pool-coins-bin.tar.gz | awk '{print $1;}')" if [ "$checksum" != "aaadd59c981daec6012dcc197e233646" ] ; then echo "ERROR: Downloaded binaries are corrupt or have been tampered with! Please try running this script again. If this error repeats, please contact the script author here:" >&2 echo "https://discord.gg/aP4XGw" >&2 exit 3 fi fi Status="$Status\nDownload succeeded." tar vxfz p2pool-coins-bin.tar.gz rm p2pool-coins-bin.tar.gz elif [ "$Method" = "compile" ] ; then mkdir -p ~/bin mkdir -p ~/coin_source for Coin in $CompileCoins ; do cd ~/coin_source if [ -d ~/coin_source/$Coin/ ] ; then cd ~/coin_source/$Coin ${CoinSourceUpdate[$Coin]} else ${CoinSourceDownload[$Coin]} fi cd ~/coin_source/$Coin/src ${CoinCompileCommand[$Coin]} if [ -f ${Coin}d ] ; then Status="$Status\n${Coin} compilation succeeded." strip ${Coin}d cp ${Coin}d ~/bin else Status="$Status\n${Coin} compilation FAILED." fi done else # This should never happen! It means there's an error in this script itself. echo "Unhandled error! Monkey wanna bannana? Fix the script code first!" >&2 exit 2 fi for Coin in $AllCoins ; do mkdir -p ~/.${Coin} ConfigFile=$HOME/.${Coin}/${Coin}.conf [ ! -f "$ConfigFile" ] && touch "$ConfigFile" GetSettings "$Coin" "$ConfigFile" UpdateSettings "$Coin" "$ConfigFile" done # Create the startup script for all coins and p2pool. cat >~/start-p2pool <>~/start-p2pool done echo "" >>~/start-p2pool echo "" >>~/start-p2pool chmod 755 ~/start-p2pool # Create a script for coin balance. cat >~/bin/coinbalance <>~/bin/coinbalance <