setup_nvidia.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. sudo apt-get update
  83. sudo apt-get install cuda -y
  84. fi
  85. if [ $cuda = "8" ]
  86. then
  87. wget -c https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  88. sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  89. sudo apt-get update
  90. sudo apt-get install cuda-8-0 -y
  91. fi
  92. echo -e "\n\e[95mInstall script miner.sh :\e[0m"
  93. cd ~
  94. sudo -u work curl -sf http://wareck.free.fr/openrig/miner_nvidia.sh.tar.xz | tar xvJ
  95. sudo chown work /home/work/miner.sh
  96. echo -e "\n\e[95mInstall Claymore Miners :\e[0m"
  97. cd ~
  98. sudo -u work curl -sf $remote_folder/miners/claymore_dual_$claymore_dual_v.tar.xz | tar xvJ
  99. sudo chown work claymore
  100. echo ""
  101. if [ $Zecminer = "YES" ]
  102. then
  103. echo -e "\n\e[95mInstall ZecMiner :\e[0m"
  104. cd ~
  105. sudo -u work curl -sf $remote_folder/miners/zecminer_nvidia.tar.xz | tar xvJ
  106. echo -e "\n\e[95mInstall ZecMiner_mod :\e[0m"
  107. if [ $cuda = "8" ]
  108. then
  109. sudo -u work curl -sf $remote_folder/miners/zecminer_nvidia_mod_cuda8.tar.xz | tar xvJ
  110. else
  111. sudo -u work curl -sf $remote_folder/miners/zecminer_nvidia_mod_cuda9.tar.xz | tar xvJ
  112. fi
  113. echo ""
  114. fi
  115. if [ $ETHMine = "YES" ]
  116. then
  117. echo -e "\n\e[95mInstall ETHMiner :\e[0m"
  118. cd ~
  119. if [ ! -d cpp_ethminer ]
  120. then
  121. git clone -n https://github.com/ethereum-mining/ethminer.git cpp_ethminer
  122. cd cpp_ethminer
  123. git checkout 2200dca33d35273fb2a7843a7d313a9a31bcd246
  124. else
  125. cd cpp_ethminer
  126. git pull
  127. cd ~
  128. fi
  129. cd ~/cpp_ethminer
  130. git submodule update --init --recursive
  131. mkdir build |true
  132. cd build
  133. cmake .. -DETHASHCUDA=ON -DETHASHCL=OFF
  134. make
  135. cd ~
  136. ln -s cpp_ethminer/build/ethminer/ethminer ethminer | true
  137. fi
  138. cd /tmp
  139. wget http://wareck.free.fr/grinder/cpp_ethminer_kernel.tar.xz
  140. tar xvfJ cpp_ethminer_kernel.tar.xz
  141. sudo mv kernels ~/cpp_ethminer/build/ethminer/
  142. cd ~
  143. echo -e "\e[97mDone !\e[0m"
  144. if [ $CCminer = "YES" ]
  145. then
  146. echo -e "\n\e[95mInstall ccminer :\e[0m"
  147. cd ~
  148. if [ ! -d ccminer ]
  149. then
  150. git clone https://github.com/tpruvot/ccminer.git
  151. cd ccminer
  152. sudo sed -i -e "s/#nvcc_ARCH += -gencode=arch=compute_61,code=/nvcc_ARCH += -gencode=arch=compute_61,code=/g" Makefile.am
  153. sudo sed -i -e "s/nvcc_ARCH += -gencode=arch=compute_50,code/#nvcc_ARCH += -gencode=arch=compute_51,code/g" Makefile.am
  154. ./build.sh
  155. else
  156. cd ccminer
  157. git pull
  158. make -j $(nproc)
  159. fi
  160. fi
  161. if [ $XmrRig = "YES" ]
  162. then
  163. echo -e "\n\e[95mInstall XMRig :\e[0m"
  164. cd ~
  165. if ! [ -d xmrig ]
  166. then
  167. git clone https://github.com/xmrig/xmrig.git
  168. else
  169. cd xmrig
  170. git pull
  171. fi
  172. cd ~/xmrig
  173. mkdir build | true
  174. cd build
  175. cmake ..
  176. make -j $(nproc)
  177. fi
  178. if [ $XmrStak = "YES" ]
  179. then
  180. echo -e "\n\e[93mBuiling XMR-stak $xmr_stak_v:\e[0m"
  181. cd /tmp/
  182. wget https://www.open-mpi.org/software/hwloc/v1.11/downloads/hwloc-1.11.8.tar.gz
  183. tar xzvf hwloc-1.11.8.tar.gz
  184. cd hwloc-1.11.8
  185. ./configure --prefix=/usr/local
  186. make -j $(nproc)
  187. sudo make install
  188. cd ~
  189. if ! [ -d xmr-stak ];then git clone https://github.com/fireice-uk/xmr-stak.git;fi
  190. chown -R work xmr-stak
  191. cd xmr-stak
  192. git pull
  193. if [ -d build ]
  194. then
  195. rm -r build
  196. fi
  197. mkdir build
  198. sed -i -e "s/= 2.0/= 0.0/g" xmrstak/donate-level.hpp
  199. cd build
  200. cmake -DCUDA_ENABLE=ON -DHWLOC_ENABLE=OFF -DCPU_ENABLE=OFF -DOpenCL_ENABLE=OFF -DOpenSSL_ENABLE=ON -DMICROHTTPD_ENABLE=OFF -DCMAKE_LINK_STATIC=ON ..
  201. sleep 2
  202. make -j $(nproc)
  203. cd ~
  204. if [ -f ~/xmr-miner ];
  205. then
  206. sudo rm ~/xmr-miner;
  207. fi
  208. ln -s xmr-stak/build/bin/xmr-stak ~/xmr-miner | true
  209. if ! [ -L /usr/lib/x86_64-linux-gnu/libxmrstak_cuda_backend.so ]
  210. then
  211. sudo cp xmr-stak/build/bin/libxmrstak_cuda_backend.so /usr/lib/x86_64-linux-gnu/libxmrstak_cuda_backend.so |true
  212. sudo cp xmr-stak/build/bin/libxmr-stak-c.a /usr/lib/x86_64-linux-gnu/ |true
  213. sudo cp xmr-stak/build/bin/libxmr-stak-backend.a /usr/lib/x86_64-linux-gnu/ |true
  214. fi
  215. echo
  216. sleep 2
  217. if ! grep -q "vm.nr_hugepages=256" /etc/sysctl.conf
  218. then
  219. sudo bash -c 'echo "vm.nr_hugepages=256" >> /etc/sysctl.conf'
  220. sudo bash -c 'sysctl -p'
  221. fi
  222. fi
  223. echo -e "\n\e[95mDownloading NoFees Patch:\e[0m"
  224. cd ~
  225. if [ -d remove_miner_fees ]
  226. then
  227. cd remove_miner_fees
  228. git pull
  229. else
  230. git clone https://github.com/wareck/remove_miner_fees.git
  231. chown -R work remove_miner_fees
  232. fi
  233. chmod 777 /etc/rc.local
  234. if ! grep --quiet "/home/work/remove_miner_fees" /etc/rc.local
  235. then
  236. sed -i "s/exit 0//g" /etc/rc.local
  237. RC_LOCAL_CMD0="#python /home/work/remove_miner_fees/remove_mining_fees.py &"
  238. RC_LOCAL_CMD1="#python /home/work/remove_miner_fees/zcach.py &"
  239. RC_LOCAL_CMD2="#python /home/work/remove_miner_fees/hush.py &"
  240. RC_LOCAL_CMD3="#python /home/work/remove_miner_fees/ubiq.py &"
  241. RC_LOCAL_CMD4="#python /home/work/remove_miner_fees/soilcoin.py &"
  242. echo $RC_LOCAL_CMD0 >>/etc/rc.local
  243. echo $RC_LOCAL_CMD1 >>/etc/rc.local
  244. echo $RC_LOCAL_CMD2 >>/etc/rc.local
  245. echo $RC_LOCAL_CMD3 >>/etc/rc.local
  246. echo $RC_LOCAL_CMD4 >>/etc/rc.local
  247. echo "exit 0" >>/etc/rc.local
  248. fi
  249. echo -e "\e[97mDone !\e[0m"
  250. echo -e "\n\e[95mInstall AutoStart:\e[0m"
  251. if [ -f /home/work/.config/autostart/miner.sh.desktop ];then rm /home/work/.config/autostart/miner.sh.desktop |true ; fi
  252. if ! [ -d /home/work/.config ]; then mkdir /home/work/.config ;fi
  253. if ! [ -d /home/work/.config/autostart ]; then mkdir /home/work/.config/autostart;fi
  254. cat <<EOF>> /home/work/.config/autostart/miner.sh.desktop
  255. [Desktop Entry]
  256. Type=Application
  257. Exec=/home/work/miner.sh
  258. Hidden=false
  259. NoDisplay=false
  260. X-GNOME-Autostart-enabled=true
  261. Name[fr_FR]=miner
  262. Name=miner
  263. Comment[fr_FR]=miner
  264. Comment=miner
  265. EOF
  266. sleep 5
  267. chmod 777 /etc/rc.local
  268. if ! grep --quiet "su work -c '/home/work/miner.sh'" /etc/rc.local
  269. then
  270. sed -i "s/exit 0//g" /etc/rc.local
  271. RC_LOCAL_CMD0="su work -c '/home/work/miner.sh'"
  272. echo $RC_LOCAL_CMD0 >>/etc/rc.local
  273. echo "exit 0" >>/etc/rc.local
  274. fi
  275. echo -e "\e[97mDone !\e[0m"
  276. echo -e "\n\e[95mMessage of the day mod :\e[0m"
  277. rm /etc/update-motd.d/00-header | true
  278. rm /etc/update-motd.d/10-help-text |true
  279. rm /etc/update-motd.d/90-updates-available |true
  280. rm /etc/update-motd.d/91-release-upgrade |true
  281. rm /etc/update-motd.d/98-fsck-at-reboot |true
  282. rm /etc/update-motd.d/98-reboot-required |true
  283. echo " - 00-header "
  284. cat <<EOF >> /etc/update-motd.d/00-header
  285. #!/bin/sh
  286. [ -r /etc/lsb-release ] && . /etc/lsb-release
  287. if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
  288. # Fall back to using the very slow lsb_release utility
  289. DISTRIB_DESCRIPTION=$(lsb_release -s -d)
  290. fi
  291. printf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" " $(uname -o)" "$(uname -p)"
  292. EOF
  293. cd /etc/update-motd.d
  294. sudo -u work curl -sf http://folivier.homelinux.org/genethos/motd.tar.xz | tar xJ
  295. cd ~
  296. sed -i -e "s/#force_color_prompt=yes/force_color_prompt=yes/g" /home/work/.bashrc
  297. if ! grep --quiet "export DISPLAY=:0" /home/work/.bashrc
  298. then
  299. cat <<EOF>> /home/work/.bashrc
  300. export DISPLAY=:0
  301. echo -e "\e[93m
  302. _ _
  303. _| |_|___ ___ ___ ___
  304. | . | | . | . | -_| _|
  305. |___|_|_ |_ |___|_|
  306. |___|___| v$script_version
  307. \e[0m"
  308. EOF
  309. fi
  310. echo -e "\e[97mDone !\e[0m"
  311. echo -e "\n\e[95mBuilding Swapfile :\e[0m"
  312. if ! grep -q "swapfile" /etc/fstab ; then
  313. case $swap_size in
  314. 0) fst="0";;
  315. 4) sudo dd if=/dev/zero | pv -s 4G | dd of=/swapfile iflag=fullblock bs=1024 count=4194304;;
  316. 8) sudo dd if=/dev/zero | pv -s 8G | dd of=/swapfile iflag=fullblock bs=1024 count=8388608;;
  317. 16) sudo dd if=/dev/zero | pv -s 16G | dd of=/swapfile iflag=fullblock bs=1024 count=16777216 ;;
  318. *) echo -e "\e[91mError in configuration !\e[0m" && exit ;;
  319. esac
  320. if ! [ $swap_size = "0" ]
  321. then
  322. sudo mkswap /swapfile
  323. sudo swapon /swapfile
  324. sudo cat <<'EOF'>> /etc/fstab
  325. /swapfile none swap sw 0 0
  326. EOF
  327. sudo chmod 600 /swapfile
  328. sudo touch /forcefsck
  329. fi
  330. else
  331. echo -e "\e[93mSwapfile already enabled... \e[0m"
  332. echo -e "\e[93mCheck /etc/fsatb file.\e[0m\n"
  333. fi
  334. echo -e "\e[97mDone !\e[0m"
  335. sudo usermod -a -G video work
  336. echo -e "\n\e[92mEverything was done...\e[0m"
  337. echo -e -n "Reboot in 15 seconds (CRTL+C to abord): "
  338. for i in {15..1}
  339. do
  340. echo -e -n "$i "
  341. sleep 1
  342. done
  343. reboot