setup_nvidia.sh 11 KB

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