miner.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. #!/bin/bash
  2. set -e
  3. Version=18.4.1
  4. Cuda=No
  5. kernel_custom=YES
  6. Miners=Yes
  7. kernel_dkms="5.15.0-71-generic"
  8. driver=NVIDIA
  9. if (( $EUID != 0 )); then
  10. echo -e "$(tput setaf 11)This must be run as root. Try 'sudo $0'.$(tput sgr0)"
  11. exit 1
  12. fi
  13. clear
  14. if [ ! -f /home/wareck/.ipass ]
  15. then
  16. echo "passe=1" > /home/wareck/.ipass
  17. fi
  18. source /home/wareck/.ipass
  19. export TERM=xterm-256color
  20. Cuda=${Cuda^^}
  21. kernel_custom=${kernel_custom^^}
  22. driver=${driver^^}
  23. Miners=${Miners^^}
  24. cpass=""
  25. function ubuntu_version_check {
  26. if [[ $(lsb_release -rs) == "20.04" ]]
  27. then
  28. Ubuntu_version="20.04.6"
  29. else
  30. echo "Non-compatible version !"
  31. exit 0
  32. fi
  33. }
  34. function print_centered {
  35. [[ $# == 0 ]] && return 1
  36. declare -i TERM_COLS="$(tput cols)"
  37. declare -i str_len="${#1}"
  38. [[ $str_len -ge $TERM_COLS ]] && {
  39. echo "$1";
  40. return 0;
  41. }
  42. declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
  43. [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
  44. filler=""
  45. for (( i = 0; i < filler_len; i++ )); do
  46. filler="${filler}${ch}"
  47. done
  48. printf "%s%s%s" "$filler" "$1" "$filler"
  49. [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
  50. printf "\n"
  51. return 0
  52. }
  53. function decompte_ {
  54. echo -e "$(tput setaf 10)\nReboot in 10 seconds (CRTL+C to abord):$(tput sgr0)"
  55. for i in {9..0}
  56. do
  57. echo -e -n "$i "
  58. sleep 1
  59. done
  60. echo ""
  61. sudo reboot
  62. }
  63. function intro_ {
  64. print_centered "$(tput setaf 5)"
  65. print_centered "░ ░░░░ ░░ ░░ ░░░ ░░ ░░ ░░░░ ░░ ░░"
  66. print_centered "▒ ▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒ ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒ ▒▒ ▒▒▒▒ ▒"
  67. print_centered "▓ ▓▓▓▓▓ ▓▓▓▓▓ ▓ ▓ ▓▓ ▓▓▓▓ ▓▓▓▓ ▓▓ ▓▓"
  68. print_centered "█ █ █ █████ █████ ██ ██ ████████ ████ ██ ███ ██"
  69. print_centered "█ ████ ██ ██ ███ ██ ███ ███ ████ █"
  70. echo -n "$(tput sgr0)"
  71. print_centered "Simple miner installation script v$Version"
  72. print_centered "Ubuntu version 20.04.6"
  73. if [ $Cuda = "YES" ]
  74. then
  75. print_centered "CUDA Compute Drivers"
  76. fi
  77. print_centered "Stage $passe/4"
  78. }
  79. function update_ {
  80. case $passe in
  81. 1)
  82. echo -e "$(tput setaf 10)\nUpdate and install packages (second pass):$(tput sgr0)"
  83. sudo apt-get update
  84. echo -e ""
  85. sudo apt-get install git build-essential libtool pkg-config automake autoconf ethtool net-tools \
  86. tasksel lzma-dev lzma cmake libuv1-dev libssl-dev msr-tools openssh-server -y
  87. echo -e ""
  88. sudo apt-get install zstd pixz pbzip2 pigz btrfs-progs \
  89. libcurl4-openssl-dev screen libudev-dev libjansson-dev libncurses5-dev libmicrohttpd-dev curl nvme-cli -y
  90. echo -e ""
  91. sudo apt-get install libglib2.0-dev libgtk2.0-dev htop vlc locate cmake -y
  92. echo -e "Done."
  93. ;;
  94. 2)
  95. if [ $Cuda = "YES" ]
  96. then
  97. echo -e "$(tput setaf 10)\nInstall Cuda packages:$(tput sgr0)"
  98. sudo apt-get install libgmp-dev libnuma-dev cmake libuv1-dev nvidia-cuda-dev libmicrohttpd-dev gcc-8 g++-8 nvidia-cuda-toolkit -y
  99. fi
  100. echo -e "Done.\n"
  101. ;;
  102. esac
  103. }
  104. function kernel_check_ {
  105. unamestr=$(uname -r)
  106. if [ -f /tmp/ksource.txt ]; then rm /tmp/ksource.txt;fi
  107. wget -c -q http://192.168.1.8:3000/wareck/custom_kernel/raw/master/ksource.txt -O /tmp/ksource.txt
  108. source /tmp/ksource.txt
  109. if ! [[ "$unamestr" == $KLversion ]]
  110. then
  111. echo -e "\n$(tput setaf 10)Custom kernel install $(tput setaf 9)$KLversion$(tput setaf 10) (fix DKMS/WOL) :$(tput sgr0)"
  112. cd /tmp/
  113. wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/custom_kernel/$kernel_version
  114. chmod +x $kernel_version
  115. sudo ./$kernel_version
  116. if ! [ -f /etc/modprobe.d/blacklist-nvidia-nouveau.conf ]
  117. then
  118. echo "Blacklist nvidia-nouveau driver..."
  119. echo "System will reboot"
  120. sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
  121. sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
  122. fi
  123. fi
  124. }
  125. function nvidia_driver_ {
  126. if [ $passe = "1" ]
  127. then
  128. if ! [ -f /etc/modprobe.d/blacklist-nvidia-nouveau.conf ]
  129. then
  130. echo "Blacklist nvidia-nouveau driver..."
  131. echo "System will reboot"
  132. sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
  133. sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
  134. fi
  135. if [ $Cuda = "NO" ]
  136. then
  137. sudo apt-get install build-essential libglvnd-dev cmake -y
  138. else
  139. sudo apt-get install build-essential libglvnd-dev cmake libhugetlbfs-dev libc-dev libc6-dev g++ -y
  140. fi
  141. echo "passe=2" > /home/wareck/.ipass
  142. decompte_
  143. fi
  144. if [ $passe = "2" ]
  145. then
  146. case $Cuda in
  147. NO)
  148. echo -e "$(tput setaf 10)\nInstall NVIDIA T4:$(tput sgr0)"
  149. sleep 3
  150. wget -c http://folivier.homelinux.org/cube/pack/NVIDIA-Linux-x86_64-550.90.07_dc.run
  151. chmod +x NVIDIA-Linux-x86_64-550.90.07_dc.run
  152. sudo ./NVIDIA-Linux-x86_64-550.90.07_dc.run --silent --driver
  153. sudo rm NVIDIA-Linux-x86_64-550.90.07_dc.run
  154. echo "passe=3" > /home/wareck/.ipass
  155. decompte_
  156. ;;
  157. YES)
  158. echo -e "$(tput setaf 10)\nInstall CUDA Drivers :$(tput sgr0)"
  159. cd /home/wareck/
  160. echo -e "Download MegaDownload:"
  161. git clone https://github.com/wareck/megadown.git
  162. sudo cp /home/wareck/megadown/megadown /usr/local/bin/megadown
  163. sudo rm -r /home/wareck/megadown
  164. wget -c https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda_12.4.1_550.54.15_linux.run
  165. chmod +x cuda_12.4.1_550.54.15_linux.run
  166. sudo ./cuda_12.4.1_550.54.15_linux.run --silent --driver --toolkit
  167. sudo rm cuda_12.4.1_550.54.15_linux.run
  168. echo "passe=3" > /home/wareck/.ipass
  169. decompte_
  170. ;;
  171. esac
  172. fi
  173. }
  174. function download_packs_ {
  175. echo -e "$(tput setaf 10)\nDownload complement packs:$(tput sgr0)"
  176. wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/chia-miner.tar.xz -O /home/wareck/Build_Cube/pack/chia-miner.tar.xz
  177. wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/xmrig.tar.xz -O /home/wareck/Build_Cube/pack/xmrig.tar.xz
  178. wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/gpu-miners.tar.xz -O /home/wareck/Build_Cube/pack/gpu-miners.tar.xz
  179. cp /home/wareck/Build_Cube/pack/gpu-miners.tar.xz /home/wareck
  180. cp /home/wareck/Build_Cube/pack/pack1.tar.xz /home/wareck
  181. cp /home/wareck/Build_Cube/pack/pack2.tar.xz /home/wareck
  182. cp /home/wareck/Build_Cube/pack/pack3.tar.xz /home/wareck
  183. cp /home/wareck/Build_Cube/pack/xmrig.tar.xz /home/wareck
  184. echo -e "Done."
  185. echo -e "$(tput setaf 10)\nDownloading miners:$(tput sgr0)"
  186. cd /home/wareck
  187. if ! [ -d miners ]; then mkdir -p miners;fi
  188. cd /home/wareck/miners
  189. if ! [ -d xmrig ]
  190. then
  191. git clone https://github.com/xmrig/xmrig.git
  192. echo -e ""
  193. fi
  194. }
  195. function build_miners_ {
  196. cmake_ #check cmake version
  197. cd /home/wareck
  198. tar xfJ gpu-miners.tar.xz
  199. cd /home/wareck/miners
  200. echo -e "$(tput setaf 10)\nUncompress xmr files:$(tput sgr0)"
  201. tar xfJ /home/wareck/xmrig.tar.xz --checkpoint=.100
  202. echo "Done."
  203. echo -n -e "\n"
  204. echo -e "$(tput setaf 10)\nBuild xmrig:$(tput sgr0)"
  205. cd xmrig
  206. git config --global --add safe.directory /home/wareck/miners/xmrig
  207. git pull
  208. sed -i "s/kDefaultDonateLevel = 5;/kDefaultDonateLevel = 0;/g" src/donate.h
  209. sed -i "s/kMinimumDonateLevel = 1;/kMinimumDonateLevel = 0;/g" src/donate.h
  210. cd scripts
  211. ./build_deps.sh
  212. cd ..
  213. cd build
  214. cmake .. -DXMRIG_DEPS=scripts/deps
  215. make -j$((`nproc`))
  216. cd ..
  217. echo "Done."
  218. if [ -d /home/wareck/miners/xmrig-upx ];then rm -r /home/wareck/miners/xmrig-upx;fi
  219. if [ -d /home/wareck/miners/xmr-stak ];then rm -r /home/wareck/miners/xmr-stak;fi
  220. if [ -d /home/wareck/miners/xmr-stak-rx ];then rm -r /home/wareck/miners/xmr-stak-rx;fi
  221. sudo chmod -R 775 /home/wareck/miners
  222. }
  223. function configure_ {
  224. echo -e "$(tput setaf 10)\nConfig files:$(tput sgr0)"
  225. cd /home/wareck/
  226. zip="['firefox.desktop', 'org.gnome.Nautilus.desktop', 'org.gnome.Terminal.desktop']"
  227. cat <<'EOF'>> zap
  228. #!/bin/bash
  229. gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 32
  230. gsettings set org.gnome.desktop.background picture-uri /home/wareck/Images/mr-robot-wallpapers.jpg
  231. gsettings set org.gnome.shell favorite-apps "XXX"
  232. #su wareck -c 'gsettings set org.gnome.shell.extensions.dash-to-dock show-mounts false'
  233. dconf load /org/gnome/terminal/ < /usr/local/bin/zap2
  234. EOF
  235. sed -i "s/XXX/$zip/g" zap
  236. UUID=$(gsettings get org.gnome.Terminal.ProfilesList default | tr -d \')
  237. cat <<'EOF'>> zap2
  238. [legacy/profiles:/:XXX]
  239. default-size-columns=110
  240. font='Monospace 9'
  241. use-system-font=false
  242. use-theme-colors=false
  243. EOF
  244. sed -i "s/XXX/$UUID/g" zap2
  245. chmod +x zap
  246. sudo cp zap /usr/local/bin
  247. sudo cp zap2 /usr/local/bin
  248. sudo rm zap
  249. sudo rm zap2
  250. sleep 1
  251. sudo rm -r -f /etc/update-motd.d/*
  252. tar xfJ pack1.tar.xz --checkpoint=.10
  253. echo -n -e "\n"
  254. sudo cp /home/wareck/pack2.tar.xz /
  255. sudo cp /home/wareck/pack3.tar.xz /
  256. cd /
  257. sudo tar xfJ pack2.tar.xz --checkpoint=.10
  258. sudo tar xfJ pack3.tar.xz --checkpoint=.10
  259. echo -n -e "\n"
  260. cd /home/wareck
  261. sudo sed -i -e "s/# set constantshow/set constantshow/g" /etc/nanorc
  262. if ! grep "wareck" /etc/sudoers >/dev/null
  263. then
  264. sudo sh -c "echo \"wareck ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
  265. fi
  266. echo -e "$(tput setaf 10)\nBashrc mod:$(tput sgr0)"
  267. if [ $Cuda = "YES" ]
  268. then
  269. if ! grep "#mod for cuda" /home/wareck/.bashrc >/dev/null
  270. then
  271. echo '#mod for cuda' >>/home/wareck/.bashrc
  272. echo 'export PATH=/usr/local/cuda-12.3/bin/:$PATH'>>/home/wareck/.bashrc
  273. echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.3/lib64:$LD_LIBRARY_PATH'>>/home/wareck/.bashrc
  274. echo '' >>/home/wareck/.bashrc
  275. fi
  276. fi
  277. if ! grep "#mod for tightvncserver" /home/wareck/.bashrc >/dev/null
  278. then
  279. echo '#mod for tightvncserver' >>/home/wareck/.bashrc
  280. echo 'cd ~' >>/home/wareck/.bashrc
  281. fi
  282. echo "Done."
  283. echo -e "$(tput setaf 10)\nDisable IPv6:$(tput sgr0)"
  284. if ! grep "ipv6.disable=1" /etc/default/grub >/dev/null
  285. then
  286. sed -i -e "s/quiet splash/quiet splash ipv6.disable=1/g" /etc/default/grub
  287. sed -i -e "s/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"ipv6.disable=1 acpi_enforce_resources=lax/g" /etc/default/grub
  288. sudo update-grub2
  289. fi
  290. sudo chown -R wareck:wareck /home/wareck/miners/xmr*
  291. sudo apt-get remove light-locker* -y
  292. echo "Done."
  293. echo "passe=4" >/home/wareck/.ipass
  294. decompte_
  295. }
  296. function cleaning_ {
  297. echo -e "$(tput setaf 10)\nCleaning install files:$(tput sgr0)"
  298. if [ -f /pack2.tar.xz ]; then sudo rm /pack2.tar.xz ;fi
  299. if [ -f /pack3.tar.xz ]; then sudo rm /pack3.tar.xz ;fi
  300. if [ -f /home/wareck/pack1.tar.xz ]; then rm /home/wareck/pack1.tar.xz ;fi
  301. if [ -f /home/wareck/pack2.tar.xz ]; then rm /home/wareck/pack2.tar.xz ;fi
  302. if [ -f /home/wareck/pack3.tar.xz ]; then rm /home/wareck/pack3.tar.xz ;fi
  303. if [ -f /home/wareck/xmrig.tar.xz ]; then rm /home/wareck/xmrig.tar.xz ;fi
  304. if [ -f /home/wareck/gpu-miners.tar.xz ]; then rm /home/wareck/gpu-miners.tar.xz;fi
  305. if [ -r /home/wareck/Music ]; then sudo rm -r -f /home/wareck/Music ;fi
  306. if [ -r /home/wareck/Public ]; then sudo rm -r -f /home/wareck/Public ;fi
  307. if [ -r /home/wareck/Templates ]; then sudo rm -r -f /home/wareck/Templates ;fi
  308. if [ -r /home/wareck/Vidéos ]; then sudo rm -r -f /home/wareck/Vidéos ;fi
  309. if [ -f /home/wareck/NVIDIA-Linux-x86_64-470.74.run ]; then rm /home/wareck/NVIDIA-Linux-x86_64-470.74.run ;fi
  310. if [ -f /home/wareck/NVIDIA-Linux-x86_64-470.82.00.run ]; then rm /home/wareck/NVIDIA-Linux-x86_64-470.82.00.run ;fi
  311. if [ -f /home/wareck/.ipass ]; then rm /home/wareck/.ipass ;fi
  312. if [ -f /usr/local/bin/zap ]; then sudo rm /usr/local/bin/zap* ;fi
  313. if [ -f /home/wareck/.config/autostart/install_os.desktop ];then sudo rm /home/wareck/.config/autostart/install_os.desktop;fi
  314. if [ -f /home/wareck/.config/autostart/zappy.desktop ];then sudo rm /home/wareck/.config/autostart/zappy.desktop;fi
  315. if [ -r /lib/modules/5.15.0-60-generic ]; then sudo rm -r /lib/modules/5.15.0-60-generic ;fi
  316. if [ -r /lib/modules/5.15.0-46-generic ]; then sudo rm -r /lib/modules/5.15.0-46-generic ;fi
  317. if [ -r /lib/modules/5.15.0-70-generic ]; then sudo rm -r /lib/modules/5.15.0-70-generic ;fi
  318. cd /home/wareck/Build_Cube/pack
  319. sudo chown -R wareck:wareck /home/wareck/miners
  320. sudo chmod -R 775 /home/wareck/miners
  321. ./clean.sh
  322. echo -e "Done. \n"
  323. echo `date` "install/update" >/home/wareck/.buildcube
  324. sudo apt-get autoremove -y
  325. sleep 1
  326. }
  327. function autoroot_ {
  328. if ! grep "#color putty" ~/.bashrc >/dev/null
  329. then
  330. echo "#color putty" >> ~/.bashrc
  331. echo "export TERM=xterm-256color" >> ~/.bashrc
  332. fi
  333. if [ ! -d /home/wareck/.config/autostart ]
  334. then
  335. echo -e "$(tput setaf 10)\nInit install & autostart:$(tput sgr0)"
  336. mkdir /home/wareck/.config/autostart
  337. echo -e "Done."
  338. sleep 1
  339. fi
  340. if [ ! -f /home/wareck/.config/autostart/install_os.desktop ]
  341. then
  342. cat <<'EOF'>> /home/wareck/.config/autostart/install_os.desktop
  343. [Desktop Entry]
  344. # VERSION=3.36.2
  345. Name=Terminal
  346. Comment=Use the command line
  347. Keywords=shell;prompt;command;commandline;cmd;
  348. TryExec=gnome-terminal
  349. Exec=gnome-terminal -- bash -c "sudo /home/wareck/Build_Cube/miner.sh; exec bash"
  350. Icon=org.gnome.Terminal
  351. Type=Application
  352. Categories=GNOME;GTK;System;TerminalEmulator;
  353. StartupNotify=true
  354. X-GNOME-SingleWindow=false
  355. OnlyShowIn=GNOME;Unity;
  356. Actions=new-window;preferences;
  357. X-Ubuntu-Gettext-Domain=gnome-terminal
  358. [Desktop Action new-window]
  359. Name=New Window
  360. Exec=gnome-terminal --window
  361. [Desktop Action preferences]
  362. Name=Preferences
  363. Exec=gnome-terminal --preferences
  364. EOF
  365. chmod +x /home/wareck/.config/autostart/install_os.desktop
  366. fi
  367. if [ ! -f /home/wareck/.config/autostart/zappy.desktop ]
  368. then
  369. cat <<'EOF'>> /home/wareck/.config/autostart/zappy.desktop
  370. [Desktop Entry]
  371. # VERSION=3.36.2
  372. Name=Terminal
  373. Comment=Use the command line
  374. Keywords=shell;prompt;command;commandline;cmd;
  375. TryExec=gnome-terminal
  376. Exec=gnome-terminal -- bash -c "/usr/local/bin/zap"
  377. Icon=org.gnome.Terminal
  378. Type=Application
  379. Categories=GNOME;GTK;System;TerminalEmulator;
  380. StartupNotify=true
  381. X-GNOME-SingleWindow=false
  382. OnlyShowIn=GNOME;Unity;
  383. Actions=new-window;preferences;
  384. X-Ubuntu-Gettext-Domain=gnome-terminal
  385. [Desktop Action new-window]
  386. Name=New Window
  387. Exec=gnome-terminal --window
  388. [Desktop Action preferences]
  389. Name=Preferences
  390. Exec=gnome-terminal --preferences
  391. EOF
  392. chmod +x /home/wareck/.config/autostart/zappy.desktop
  393. fi
  394. if ! grep "wareck" /etc/sudoers >/dev/null
  395. then
  396. sudo sh -c "echo \"wareck ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
  397. fi
  398. if [ $passe="2" ]
  399. then
  400. echo -e "$(tput setaf 10)\nUpdate and install packages:$(tput sgr0)"
  401. sudo apt-get update
  402. sleep 1
  403. fi
  404. }
  405. function cmake_ {
  406. pids=""
  407. /home/wareck/Build_Cube/options/tools/_cmake.sh rollback & pids="$pids $!"
  408. wait $pids
  409. sudo ldconfig
  410. }
  411. intro_
  412. case $passe in
  413. 1)
  414. autoroot_
  415. ubuntu_version_check
  416. update_
  417. kernel_check_
  418. nvidia_driver_
  419. ;;
  420. 2)
  421. nvidia_driver_
  422. update_
  423. ;;
  424. 3)
  425. download_packs_
  426. build_miners_
  427. configure_
  428. ;;
  429. 4)
  430. cleaning_
  431. dynmotd
  432. ;;
  433. *) ;;
  434. esac
  435. echo -e "$(tput setaf 10)\nEnd of script:$(tput sgr0) \n"
  436. echo -e "$(tput setaf 7)Need to install webmin manually (reboot required)$(tput sgr0)"
  437. echo -e "$(tput setaf 7)after install webmin, reboot is required $(tput sgr0)"
  438. echo -e ""