Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. Usage()
  4. {
  5. echo "$(basename $0): Downloads and installs litecoind, p2pool, and other coins for merged mining." >&2
  6. echo "Usage:" >&2
  7. echo "To download the source code and compile yourself (slower but more secure):" >&2
  8. echo " ./$(basename $0) --compile" >&2
  9. echo "To download precompiled binaries (faster but less secure):" >&2
  10. echo " ./$(basename $0) --download" >&2
  11. echo "You may also choose to download the litetcoin blockchain via http. Add the following to the command line:" >&2
  12. echo " --http" >&2
  13. echo "If you don't use this, the blockchain will instead download using the built-in peer-to-peer process." >&2
  14. echo "Note: If you choose the --download option to update your current install, it will OVERWRITE your config files!" >&2
  15. echo >&2
  16. exit 1
  17. } # Usage()
  18.  
  19. declare -A CoinUser
  20. declare -A CoinPassword
  21. declare -A CoinPort
  22. declare -A CoinRPCPort
  23. declare -A CoinRPCAllowIP
  24. declare -A CoinSourceDownload
  25. declare -A CoinSourceUpdate
  26. declare -A CoinCompileCommand
  27. declare -A CoinSymbol
  28.  
  29. #Litecoin
  30. CoinUser["litecoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40`
  31. CoinPassword["litecoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40`
  32. CoinPort["litecoin"]=10332
  33. CoinRPCPort["litecoin"]=10333
  34. CoinRPCAllowIP["litecoin"]=127.0.0.1
  35. CoinSourceDownload["litecoin"]="git clone https://github.com/litecoin-project/litecoin"
  36. CoinSourceUpdate["litecoin"]="git pull"
  37. CoinCompileCommand["litecoin"]="make -f Makefile"
  38. CoinSymbol["litecoin"]=LTC
  39.  
  40. #Viacoin
  41. CoinUser["viacoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40`
  42. CoinPassword["viacoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40`
  43. CoinPort["viacoin"]=5223
  44. CoinRPCPort["viacoin"]=5222
  45. CoinRPCAllowIP["viacoin"]=127.0.0.1
  46. CoinSourceDownload["viacoin"]="git clone https://github.com/viacoin/viacoin"
  47. CoinSourceUpdate["viacoin"]="git pull"
  48. CoinCompileCommand["viacoin"]="make -f Makefile"
  49. CoinSymbol["viacoin"]=VIA
  50.  
  51. #Dogecoin
  52. CoinUser["dogecoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40`
  53. CoinPassword["dogecoin"]=`< /dev/urandom tr -dc A-Za-z0-9 | head -c40`
  54. CoinPort["dogecoin"]=7333
  55. CoinRPCPort["dogecoin"]=7332
  56. CoinRPCAllowIP["dogecoin"]=127.0.0.1
  57. CoinSourceDownload["dogecoin"]="git clone https://github.com/dogecoin/dogecoin"
  58. CoinSourceUpdate["dogecoin"]="git pull"
  59. CoinCompileCommand["dogecoin"]="make -f Makefile.unix"
  60. CoinSymbol["dogecoin"]=DOGE
  61.  
  62. CompileCoins="viacoin dogecoin"
  63. AllCoins="litecoin $CompileCoins"
  64.  
  65. GetSettings()
  66. {
  67. if [ $# -lt 1 -o $# -gt 2 -o -z "$1" ] ; then
  68. return 98
  69. fi
  70.  
  71. local filepath
  72. if [ -n "$2" ] ; then
  73. filepath="$2"
  74. else
  75. filepath="$HOME/.$1/$1.conf"
  76. fi
  77.  
  78. if [ ! -r "$filepath" ] ; then
  79. return 99
  80. fi
  81.  
  82. local user password port rpcport rpcallowip
  83. user="$(grep -ie "^rpcuser" "$filepath" | awk -F= '{print $2}')"
  84. password="$(grep -ie "^rpcpassword" "$filepath" | awk -F= '{print $2}')"
  85. port="$(grep -ie "^port" "$filepath" | awk -F= '{print $2}')"
  86. rpcport="$(grep -e "^rpcport" "$filepath" | awk -F= '{print $2}')"
  87. rpcallowip="$(grep -ie "^rpcallowip" "$filepath" | awk -F= '{print $2}')"
  88.  
  89. [ -n "$user" ] && CoinUser["$1"]="$user"
  90. [ -n "$password" ] && CoinPassword["$1"]="$password"
  91. [ -n "$port" ] && CoinPort["$1"]="$port"
  92. [ -n "$rpcport" ] && CoinRPCPort["$1"]="$rpcport"
  93. [ -n "$rpcallowip" ] && CoinRPCAllowIP["$1"]="$rpcallowip"
  94.  
  95. [ -z "$user" -o -z "$password" -o -z "$port" -o -z "$rpcport" -o -z "$rpcallowip" ] && return 1
  96. return 0
  97. } # GetSettings()
  98.  
  99. AddSetting()
  100. {
  101. if [ $# -lt 1 -o $# -gt 4 -o -z "$1" -o -z "$2" -o -z "$3" ] ; then
  102. return 98
  103. fi
  104.  
  105. local filepath
  106. if [ -n "$4" ] ; then
  107. filepath="$4"
  108. else
  109. filepath="$HOME/.$1/$1.conf"
  110. fi
  111.  
  112. if [ ! -r "$filepath" ] ; then
  113. return 99
  114. fi
  115.  
  116. local matchstring=$(echo "$2" | sed -e 's/[]\/$*.^|[]/\\&/g')
  117.  
  118. if ! grep -qe "^${matchstring}=" "$filepath" ; then
  119. echo "$2=$3" >> "$filepath"
  120. return 0
  121. fi
  122. return 1
  123.  
  124. } # AddSetting()
  125.  
  126. ReplaceSetting()
  127. {
  128. if [ $# -lt 1 -o $# -gt 4 -o -z "$1" -o -z "$2" -o -z "$3" ] ; then
  129. return 98
  130. fi
  131.  
  132. local filepath
  133. if [ -n "$4" ] ; then
  134. filepath="$4"
  135. else
  136. filepath="$HOME/.$1/$1.conf"
  137. fi
  138.  
  139. if [ ! -r "$filepath" ] ; then
  140. return 99
  141. fi
  142.  
  143. local matchstring=$(echo "$2" | sed -e 's/[]\/$*.^|[]/\\&/g')
  144.  
  145. if ! grep -qe "^${matchstring}=" "$filepath" ; then
  146. echo -e "$2=$3" >> "$filepath"
  147. return 0
  148. fi
  149.  
  150. # If we get here, the setting does exist. Update it.
  151. grep -ve "^${matchstring}=" "$filepath" > "$filepath.tmp"
  152. mv "$filepath.tmp" "$filepath"
  153. echo "$2=$3" >> "$filepath"
  154. return 1
  155.  
  156. } # ReplaceSetting()
  157.  
  158. UpdateSettings()
  159. {
  160. if [ $# -lt 1 -o $# -gt 2 -o -z "$1" ] ; then
  161. return 98
  162. fi
  163.  
  164. local filepath
  165. if [ -n "$2" ] ; then
  166. filepath="$2"
  167. else
  168. filepath="$HOME/.$1/$1.conf"
  169. fi
  170.  
  171. if [ ! -r "$filepath" ] ; then
  172. return 99
  173. fi
  174.  
  175. AddSetting "$1" "server" "1" "$filepath"
  176. AddSetting "$1" "daemon" "1" "$filepath"
  177. AddSetting "$1" "rpcuser" "${CoinUser[$1]}" "$filepath"
  178. AddSetting "$1" "rpcpassword" "${CoinPassword[$1]}" "$filepath"
  179. ReplaceSetting "$1" "port" "${CoinPort[$1]}" "$filepath"
  180. ReplaceSetting "$1" "rpcport" "${CoinRPCPort[$1]}" "$filepath"
  181. AddSetting "$1" "rpcallowip" "${CoinRPCAllowIP[$1]}" "$filepath"
  182.  
  183. [ -n "$(tail -1 "$1")" ] && echo "" >> "$filepath"
  184. } # UpdateSettings()
  185.  
  186. if [ $# -eq 0 ] ; then
  187. Usage
  188. else
  189. while [ $# -gt 0 ] ; do
  190. if [ "--download" = "$1" ] ; then
  191. Method="download"
  192. elif [ "--compile" = "$1" ] ; then
  193. Method="compile"
  194. # elif [ "--torrent" = "$1" ] ; then
  195. # Blockchain="torrent"
  196. elif [ "--http" = "$1" ] ; then
  197. Blockchain="http"
  198. else
  199. echo "Error: Unrecognized parameter on command line. Aborting" >2
  200. Usage
  201. fi
  202. shift
  203. done
  204. fi
  205.  
  206. if [ -z "$Method" ] ; then
  207. echo "Error: No installation method specified (compile or download). Aborting" >2
  208. Usage
  209. fi
  210.  
  211. cat <<EOF >~/sudoscript.sh
  212. #!/bin/sh
  213.  
  214. # Install the pre-req for add-apt-repository
  215. #apt-get -y install software-properties-common
  216.  
  217. # Add the litecoin repository
  218. #add-apt-repository -y ppa:litecoin-project/litecoin
  219.  
  220. # Update installed packages
  221. apt-get -y update
  222. apt-get -y dist-upgrade
  223.  
  224. # Install needed packages
  225. # Note that litecoind is always installed as a binary, not compiled.
  226. 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
  227.  
  228. # Firewall
  229. ufw default deny # Deny everything unless expressly permitted
  230. ufw allow 22/tcp # SSH
  231. ufw allow 10333/tcp # litecoin peer to peer
  232. ufw allow 5223/tcp # viacoin peer to peer
  233. ufw allow 7333/tcp # dogecoin peer to peer
  234. ufw allow 9326/tcp # P2pool peer to peer
  235. ufw allow 9327/tcp # P2Pool connections and Web interface
  236. ufw --force enable # Turn it on
  237.  
  238. EOF
  239.  
  240. echo "Trust me"
  241. sleep 2
  242. sudo sh ~/sudoscript.sh
  243. #rm ~/sudoscript.sh
  244.  
  245. # Install p2pool
  246. if [ -d ~/p2pool/ ] ; then
  247. cd ~/p2pool
  248. git pull
  249. else
  250. cd
  251. git clone https://github.com/jtoomim/p2pool -b 1mb_segwit p2pool
  252. fi
  253.  
  254. # download or compile the binaries.
  255. if [ "$Method" = "download" ] ; then
  256.  
  257. cd
  258. wget http://91.121.66.157/p2pool-coins-bin.tar.gz
  259.  
  260. # Some security on binaries (trust is a must)- (Switch "false" to "true")
  261. if true; then
  262. checksum="$(md5sum p2pool-coins-bin.tar.gz | awk '{print $1;}')"
  263. if [ "$checksum" != "aaadd59c981daec6012dcc197e233646" ] ; then
  264. 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
  265. echo "https://discord.gg/aP4XGw" >&2
  266. exit 3
  267. fi
  268. fi
  269.  
  270. Status="$Status\nDownload succeeded."
  271.  
  272. tar vxfz p2pool-coins-bin.tar.gz
  273. rm p2pool-coins-bin.tar.gz
  274.  
  275. elif [ "$Method" = "compile" ] ; then
  276.  
  277. mkdir -p ~/bin
  278.  
  279. mkdir -p ~/coin_source
  280.  
  281. for Coin in $CompileCoins ; do
  282.  
  283. cd ~/coin_source
  284. if [ -d ~/coin_source/$Coin/ ] ; then
  285. cd ~/coin_source/$Coin
  286. ${CoinSourceUpdate[$Coin]}
  287. else
  288. ${CoinSourceDownload[$Coin]}
  289. fi
  290. cd ~/coin_source/$Coin/src
  291. ${CoinCompileCommand[$Coin]}
  292. if [ -f ${Coin}d ] ; then
  293. Status="$Status\n${Coin} compilation succeeded."
  294. strip ${Coin}d
  295. cp ${Coin}d ~/bin
  296. else
  297. Status="$Status\n${Coin} compilation FAILED."
  298. fi
  299. done
  300.  
  301. else
  302. # This should never happen! It means there's an error in this script itself.
  303. echo "Unhandled error! Monkey wanna bannana? Fix the script code first!" >&2
  304. exit 2
  305. fi
  306.  
  307. for Coin in $AllCoins ; do
  308.  
  309. mkdir -p ~/.${Coin}
  310.  
  311. ConfigFile=$HOME/.${Coin}/${Coin}.conf
  312. [ ! -f "$ConfigFile" ] && touch "$ConfigFile"
  313.  
  314. GetSettings "$Coin" "$ConfigFile"
  315.  
  316. UpdateSettings "$Coin" "$ConfigFile"
  317. done
  318.  
  319. # Create the startup script for all coins and p2pool.
  320. cat >~/start-p2pool <<EOF
  321. #!/bin/sh
  322. ~/bin/litecoind -daemon
  323. ~/bin/viacoind -daemon
  324. ~/bin/dogecoind -daemon
  325. screen -d -m -S p2pool \\
  326. ~/p2pool/run_p2pool.py --net litecoin -f 0 --give-author 0 \\
  327. EOF
  328.  
  329. for Coin in $CompileCoins
  330. do
  331. echo " --merged http://${CoinUser[$Coin]}:${CoinPassword[$Coin]}@127.0.0.1:${CoinRPCPort[$Coin]} \\" >>~/start-p2pool
  332. done
  333. echo "" >>~/start-p2pool
  334. echo "" >>~/start-p2pool
  335. chmod 755 ~/start-p2pool
  336.  
  337. # Create a script for coin balance.
  338. cat >~/bin/coinbalance <<EOF
  339. #!/bin/sh
  340. echo "LTC: \$(litecoin-cli getbalance)"
  341. EOF
  342.  
  343. for Coin in $CompileCoins
  344. do
  345. cat >>~/bin/coinbalance <<EOF
  346. echo "${CoinSymbol[$Coin]}: \$(${Coin}-cli getbalance)"
  347. EOF
  348.  
  349. done
  350.  
  351. chmod 755 ~/bin/coinbalance
  352.  
  353. # If requested, download the blockchain.
  354. if [ "$Blockchain" = "http" ] ; then
  355. cd ~/.litecoin
  356.  
  357. wget http://147.135.10.45/blockchains/current/Litecoin_blockchain.zip
  358.  
  359. unzip Litecoin_blockchain.zip
  360. #elif [ "$Blockchain" = "torrent" ] ; then
  361. # @TODO: fill this in for torrent download option
  362. fi
  363.  
  364. # Almost finished ...
  365. echo
  366. echo
  367. echo
  368. echo "Installation results:"
  369. echo -e "$Status"
  370. echo
  371. echo "Thank you for helping to protect the litecoin network by running p2pool"
  372. echo "Good luck with your merged mining!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement