setup_nvidia.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #!/bin/bash
  2. set -e
  3. script_version="0.1b"
  4. rdate="10/07/2018"
  5. remote_folder="http://wareck.free.fr/openrig"
  6. cuda="9.2"
  7. #### OPTIONS ####
  8. ETHMine="YES"
  9. CCminer="YES"
  10. XmrRig="YES"
  11. XmrStak="YES"
  12. swap_size="0" # 0/4/8/16 Go
  13. #script_version=`grep version version.txt | awk '{ print $2 }'`
  14. #rdate=`grep release version.txt | awk '{ print $2 }'`
  15. if [ $UID -ne 0 ]
  16. then
  17. echo -e "\n\e[91mPlease run this script as ROOT : sudo ./setup.sh \e[0m"
  18. echo
  19. sleep 1
  20. exit
  21. fi
  22. claymore_dual_v="`curl -s $remote_folder/version.txt | awk 'NR==1 {print$3; exit}'`"
  23. claymore_zcash_v="`curl -s $remote_folder/version.txt | awk 'NR==2 {print$3; exit}'`"
  24. claymore_xmr_v="`curl -s $remote_folder/version.txt | awk 'NR==3 {print$3; exit}'`"
  25. echo ""
  26. echo -n -e " \e[97m\u2554"
  27. for i in {1..40}; do echo -e -n "\u2550"; done
  28. echo -e "\u2557\e[0m"
  29. echo -e " \e[97m\u2551 NVIDIA Mining Rig Auto-install \e[93m"V$script_version"\e[0m\e[97m \u2551\e[0m"
  30. echo -e " \e[97m\u2551 Release date: \e[93m"$rdate"\e[0m\e[97m \u2551\e[0m"
  31. echo -e " \e[97m\u2551 wareck@gmail.com \u2551\e[0m"
  32. echo -n -e " \e[97m\u255A"
  33. for j in {1..40}; do echo -e -n "\u2550";done
  34. echo -e -n "\u255D\e[0m"
  35. echo
  36. echo -e "\e[97m +\e[91m Cuda toolkit v$cuda \e[0m\e[97m"
  37. if [ $ETHMine = "YES" ]; then echo -e "\e[97m +\e[91m Etherminer \e[0m\e[97m";fi
  38. if [ $CCminer = "YES" ]; then echo -e "\e[97m +\e[91m CCminer \e[0m\e[97m";fi
  39. if [ $XmrRig = "YES" ]; then echo -e "\e[97m +\e[91m XMR_Rig \e[0m\e[97m";fi
  40. if [ $XmrStak = "YES" ]; then echo -e "\e[97m +\e[91m XMR_Stak \e[0m\e[97m";fi
  41. echo -e "\e[97m +\e[91m Claymore dualminer $claymore_dual_v\e[0m\e[97m"
  42. #echo -e "\e[97m +\e[91m Claymore zcash $claymore_zcash_v\e[0m\e[97m"
  43. #echo -e "\e[97m +\e[91m Claymore xmr $claymore_xmr_v\e[0m\e[97m"
  44. sleep 4
  45. sed -i -e "s/# set const/set const/g" /etc/nanorc
  46. echo -e "\n\e[95mExpand Disk :\e[0m"
  47. sudo growpart `df -h | grep /dev/sd | awk ' { print $1 }'| cut -c -8` 1 |true
  48. sudo resize2fs `df -h | grep /dev/sd | awk ' { print $1 }'` |true
  49. echo -e "\e[97mDone !\e[0m"
  50. echo -e "\n\e[95mSystem Update :\e[0m"
  51. sudo apt-get update
  52. #sudo add-apt-repository -y ppa:ethereum/ethereum -y
  53. #sudo apt-get update
  54. sudo apt install git screen htop curl ntp pv git cmake libcryptopp-dev libleveldb-dev libjsoncpp-dev \
  55. build-essential libcurl4-gnutls-dev libgmp-dev \
  56. libreadline-dev libmicrohttpd-dev libjansson-dev libgmp-dev libssl-dev unzip python-nfqueue python-scapy -y
  57. if [ $CCminer = "YES" ]
  58. then
  59. sudo apt-get install libcurl4-openssl-dev libssl-dev libjansson-dev automake autotools-dev build-essential -y
  60. fi
  61. if [ $XmrRig = "YES" ]
  62. then
  63. sudo apt-get install git build-essential cmake libuv1-dev libmicrohttpd-dev -y
  64. fi
  65. cd ~
  66. sleep 5
  67. sudo sed -i -e "s/quiet splash/text/g" /etc/default/grub
  68. sudo sed -i -e 's#GRUB_CMDLINE_LINUX=""#GRUB_CMDLINE_LINUX="amddgpu.vm_fragment_size=9"#g' /etc/default/grub
  69. sudo update-grub2
  70. sudo apt dist-upgrade -y
  71. echo -e "\n\e[95mInstall Nvidia Drivers :\e[0m"
  72. sudo add-apt-repository ppa:graphics-drivers/ppa -y
  73. sudo apt-get update
  74. sudo apt-get install nvidia-375 -y
  75. cd /tmp
  76. if [ $cuda = "9.2" ]
  77. then
  78. wget -c http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.2.148-1_amd64.deb
  79. sudo dpkg -i cuda-repo-ubuntu1604_9.2.148-1_amd64.deb
  80. sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
  81. fi
  82. if [ $cuda = "8" ]
  83. then
  84. wget -c https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  85. sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  86. fi
  87. sudo apt-get update
  88. sudo apt-get install cuda -y
  89. echo -e "\n\e[95mInstall Claymore Miners :\e[0m"
  90. cd /home/work/
  91. sudo -u work curl -sf $remote_folder/miners/claymore_dual_$claymore_dual_v.tar.xz | tar xvJ
  92. echo ""
  93. echo -e "\n\e[95mInstall ZecMiner :\e[0m"
  94. cd /home/work/
  95. sudo -u work curl -sf $remote_folder/miners/zecminer_nvidia.tar.xz | tar xvJ
  96. echo ""
  97. sudo -u work curl -sf http://wareck.free.fr/openrig/miner_nividia.sh.tar.xz | tar xvJ
  98. sudo chown work claymore
  99. sudo chown work /home/work/miner.sh
  100. if [ $ETHMine = "YES" ]
  101. then
  102. echo -e "\n\e[95mInstall ETHMiner :\e[0m"
  103. cd ~
  104. if [ ! -d cpp_ethminer ]
  105. then
  106. git clone https://github.com/ethereum-mining/ethminer.git cpp_ethminer
  107. else
  108. cd cpp_ethminer
  109. git pull
  110. cd ~
  111. fi
  112. cd cpp_ethminer
  113. git submodule update --init --recursive
  114. mkdir build |true
  115. cd build
  116. cmake .. -DETHASHCUDA=ON -DETHASHCL=OFF
  117. make
  118. cd ~
  119. ln -s cpp_ethminer/build/ethminer/ethminer ethminer | true
  120. fi
  121. echo -e "\e[97mDone !\e[0m"
  122. if [ $CCminer = "YES" ]
  123. then
  124. echo -e "\n\e[95mInstall ccminer :\e[0m"
  125. cd ~
  126. if [ ! -d ccminer ]
  127. then
  128. git clone https://github.com/tpruvot/ccminer.git
  129. else
  130. cd ccminer
  131. git pull
  132. cd ~
  133. fi
  134. cd ccminer
  135. sudo sed -i -e "s/#nvcc_ARCH += -gencode=arch=compute_61,code=/nvcc_ARCH += -gencode=arch=compute_61,code=/g" Makefile.am
  136. sudo sed -i -e "s/nvcc_ARCH += -gencode=arch=compute_50,code/#nvcc_ARCH += -gencode=arch=compute_51,code/g" Makefile.am
  137. ./build.sh
  138. cd ~
  139. fi
  140. if [ $XmrRig = "YES" ]
  141. then
  142. echo -e "\n\e[95mInstall XMRig :\e[0m"
  143. cd ~
  144. if ! [ -d xmrig ]
  145. then
  146. git clone https://github.com/xmrig/xmrig.git
  147. else
  148. cd xmrig
  149. git pull
  150. if ! [ -d build ];then mkdir build ;fi
  151. fi
  152. cd build
  153. cmake ..
  154. make
  155. fi
  156. if [ $XmrStak = "YES" ]
  157. then
  158. echo -e "\n\e[93mBuiling XMR-stak $xmr_stak_v:\e[0m"
  159. cd /tmp/
  160. wget https://www.open-mpi.org/software/hwloc/v1.11/downloads/hwloc-1.11.8.tar.gz
  161. tar xzvf hwloc-1.11.8.tar.gz
  162. cd hwloc-1.11.8
  163. ./configure --prefix=/usr/local
  164. make
  165. sudo make install
  166. cd ~
  167. if ! [ -d xmr-stak ];then git clone https://github.com/fireice-uk/xmr-stak.git;fi
  168. chown -R work xmr-stak
  169. cd xmr-stak
  170. git pull
  171. if [ -d build ]
  172. then
  173. rm -r build
  174. fi
  175. mkdir build
  176. sed -i -e "s/= 2.0/= 0.0/g" xmrstak/donate-level.hpp
  177. cd build
  178. cmake -DCUDA_ENABLE=ON -DHWLOC_ENABLE=OFF -DCPU_ENABLE=OFF -DOpenCL_ENABLE=OFF -DOpenSSL_ENABLE=ON -DMICROHTTPD_ENABLE=OFF -DCMAKE_LINK_STATIC=ON ..
  179. sleep 2
  180. make $(if $(THREADS="-j$(($(tail -c 2 /sys/devices/system/node/node0/cpulist 2>/dev/null)+2))"); then echo $THREADS; fi)
  181. cd ~
  182. if [ -f ~/xmr-miner ];
  183. then
  184. sudo rm ~/xmr-miner;
  185. fi
  186. ln -s xmr-stak/build/bin/xmr-stak ~/xmr-miner | true
  187. if ! [ -L /usr/lib/x86_64-linux-gnu/libxmrstak_opencl_backend.so ]
  188. then
  189. sudo cp xmr-stak/build/bin/libxmrstak_opencl_backend.so /usr/lib/x86_64-linux-gnu/libxmrstak_opencl_backend.so |true
  190. sudo cp xmr-stak/build/bin/libxmr-stak-c.a /usr/lib/x86_64-linux-gnu/ |true
  191. sudo cp xmr-stak/build/bin/libxmr-stak-backend.a /usr/lib/x86_64-linux-gnu/ |true
  192. fi
  193. echo
  194. sleep 2
  195. if ! grep -q "vm.nr_hugepages=256" /etc/sysctl.conf
  196. then
  197. sudo bash -c 'echo "vm.nr_hugepages=256" >> /etc/sysctl.conf'
  198. sudo bash -c 'sysctl -p'
  199. fi
  200. fi
  201. echo -e "\n\e[95mDownloading NoFees Patch:\e[0m"
  202. cd ~
  203. if [ -d remove_miner_fees ]
  204. then
  205. cd remove_miner_fees
  206. git pull
  207. else
  208. git clone https://github.com/wareck/remove_miner_fees.git
  209. chown -R work remove_miner_fees
  210. fi
  211. chmod 777 /etc/rc.local
  212. if ! grep --quiet "/home/work/remove_miner_fees" /etc/rc.local
  213. then
  214. sed -i "s/exit 0//g" /etc/rc.local
  215. RC_LOCAL_CMD0="#python /home/work/remove_miner_fees/remove_mining_fees.py &"
  216. RC_LOCAL_CMD1="#python /home/work/remove_miner_fees/zcach.py &"
  217. RC_LOCAL_CMD2="#python /home/work/remove_miner_fees/hush.py &"
  218. RC_LOCAL_CMD3="#python /home/work/remove_miner_fees/ubiq.py &"
  219. RC_LOCAL_CMD4="#python /home/work/remove_miner_fees/soilcoin.py &"
  220. echo $RC_LOCAL_CMD0 >>/etc/rc.local
  221. echo $RC_LOCAL_CMD1 >>/etc/rc.local
  222. echo $RC_LOCAL_CMD2 >>/etc/rc.local
  223. echo $RC_LOCAL_CMD3 >>/etc/rc.local
  224. echo $RC_LOCAL_CMD4 >>/etc/rc.local
  225. echo "exit 0" >>/etc/rc.local
  226. fi
  227. echo -e "\e[97mDone !\e[0m"
  228. echo -e "\n\e[95mInstall AutoStart:\e[0m"
  229. if [ -f /home/work/.config/autostart/miner.sh.desktop ];then rm /home/work/.config/autostart/miner.sh.desktop |true ; fi
  230. if ! [ -d /home/work/.config ]; then mkdir /home/work/.config ;fi
  231. if ! [ -d /home/work/.config/autostart ]; then mkdir /home/work/.config/autostart;fi
  232. cat <<EOF>> /home/work/.config/autostart/miner.sh.desktop
  233. [Desktop Entry]
  234. Type=Application
  235. Exec=/home/work/miner.sh
  236. Hidden=false
  237. NoDisplay=false
  238. X-GNOME-Autostart-enabled=true
  239. Name[fr_FR]=miner
  240. Name=miner
  241. Comment[fr_FR]=miner
  242. Comment=miner
  243. EOF
  244. sleep 5
  245. chmod 777 /etc/rc.local
  246. if ! grep --quiet "su work -c '/home/work/miner.sh'" /etc/rc.local
  247. then
  248. sed -i "s/exit 0//g" /etc/rc.local
  249. RC_LOCAL_CMD0="su work -c '/home/work/miner.sh'"
  250. echo $RC_LOCAL_CMD0 >>/etc/rc.local
  251. echo "exit 0" >>/etc/rc.local
  252. fi
  253. echo -e "\e[97mDone !\e[0m"
  254. cd /home/work/
  255. sudo rm -r tempo | true
  256. echo -e "\n\e[95mMessage of the day mod :\e[0m"
  257. rm /etc/update-motd.d/00-header | true
  258. rm /etc/update-motd.d/10-help-text |true
  259. rm /etc/update-motd.d/90-updates-available |true
  260. rm /etc/update-motd.d/91-release-upgrade |true
  261. rm /etc/update-motd.d/98-fsck-at-reboot |true
  262. rm /etc/update-motd.d/98-reboot-required |true
  263. echo " - 00-header "
  264. cat <<EOF >> /etc/update-motd.d/00-header
  265. #!/bin/sh
  266. [ -r /etc/lsb-release ] && . /etc/lsb-release
  267. if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
  268. # Fall back to using the very slow lsb_release utility
  269. DISTRIB_DESCRIPTION=$(lsb_release -s -d)
  270. fi
  271. printf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" " $(uname -o)" "$(uname -p)"
  272. EOF
  273. cd /etc/update-motd.d
  274. sudo -u work curl -sf http://folivier.homelinux.org/genethos/motd.tar.xz | tar xJ
  275. cd ~
  276. sed -i -e "s/#force_color_prompt=yes/force_color_prompt=yes/g" /home/work/.bashrc
  277. if ! grep --quiet "export DISPLAY=:0" /home/work/.bashrc
  278. then
  279. cat <<EOF>> /home/work/.bashrc
  280. export DISPLAY=:0
  281. echo -e "\e[93m
  282. _ _
  283. _| |_|___ ___ ___ ___
  284. | . | | . | . | -_| _|
  285. |___|_|_ |_ |___|_|
  286. |___|___| v$script_version
  287. \e[0m"
  288. EOF
  289. fi
  290. echo -e "\e[97mDone !\e[0m"
  291. echo -e "\n\e[95mBuilding Swapfile :\e[0m"
  292. if ! grep -q "swapfile" /etc/fstab ; then
  293. case $swap_size in
  294. 0) fst="0";;
  295. 4) sudo dd if=/dev/zero | pv -s 4G | dd of=/swapfile iflag=fullblock bs=1024 count=4194304;;
  296. 8) sudo dd if=/dev/zero | pv -s 8G | dd of=/swapfile iflag=fullblock bs=1024 count=8388608;;
  297. 16) sudo dd if=/dev/zero | pv -s 16G | dd of=/swapfile iflag=fullblock bs=1024 count=16777216 ;;
  298. *) echo -e "\e[91mError in configuration !\e[0m" && exit ;;
  299. esac
  300. if ! [ $swap_size = "0" ]
  301. then
  302. sudo mkswap /swapfile
  303. sudo swapon /swapfile
  304. sudo cat <<'EOF'>> /etc/fstab
  305. /swapfile none swap sw 0 0
  306. EOF
  307. sudo chmod 600 /swapfile
  308. sudo touch /forcefsck
  309. fi
  310. else
  311. echo -e "\e[93mSwapfile already enabled... \e[0m"
  312. echo -e "\e[93mCheck /etc/fsatb file.\e[0m\n"
  313. fi
  314. echo -e "\e[97mDone !\e[0m"
  315. sudo usermod -a -G video work
  316. echo -e "\n\e[92mEverything was done...\e[0m"
  317. echo -e -n "Reboot in 15 seconds (CRTL+C to abord): "
  318. for i in {15..1}
  319. do
  320. echo -e -n "$i "
  321. sleep 1
  322. done
  323. reboot