crazydownloaded

Raspberry Pi Debian Wheezy/cgminer configuration

Dec 2nd, 2012
2,608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.31 KB | None | 0 0
  1. #Switch to root
  2. sudo passwd pi
  3. sudo passwd root
  4. sudo su -
  5.  
  6. #Enable testing updates
  7. nano /etc/apt/sources.list
  8.     deb http://mirrordirector.raspbian.org/raspbian/ testing main contrib non-free rpi
  9.  
  10. nano /etc/apt/sources.list.d/raspi.list
  11.     no change (testing not available here, nor stable, only wheezy)
  12.  
  13. #Update the system
  14. aptitude update
  15. aptitude dist-upgrade
  16.  
  17. #Enable automatic (security) upgrades
  18. aptitude install unattended-upgrades apticron
  19. nano /etc/apt/apt.conf.d/50unattended-upgrades
  20.     #Security updates are enabled by default, feel free to accept more
  21. nano /etc/apt/apt.conf.d/02periodic (new file)
  22.     // Enable the update/upgrade script (0=disable)
  23.     APT::Periodic::Enable "1";
  24.    
  25.     // Do "apt-get update" automatically every n-days (0=disable)
  26.     APT::Periodic::Update-Package-Lists "1";
  27.    
  28.     // Do "apt-get upgrade --download-only" every n-days (0=disable)
  29.     APT::Periodic::Download-Upgradeable-Packages "1";
  30.    
  31.     // Run the "unattended-upgrade" security upgrade script
  32.     // every n-days (0=disabled)
  33.     // Requires the package "unattended-upgrades" and will write
  34.     // a log in /var/log/unattended-upgrades
  35.     APT::Periodic::Unattended-Upgrade "1";
  36.    
  37.     // Do "apt-get autoclean" every n-days (0=disable)
  38.     APT::Periodic::AutocleanInterval "7";
  39. nano /etc/apticron/apticron.conf
  40.  
  41. #FSCK repair when HD have inconistencies
  42. nano /etc/default/rcS
  43.     FSCKFIX=yes
  44.  
  45. #Let's configure the system for cgminer
  46. groupadd btc
  47. useradd -g btc btc
  48. usermod -a -G dialout btc
  49. passwd btc
  50. groups btc
  51. mkdir /home/btc/
  52.  
  53. echo '#!/bin/sh
  54.  
  55. cgminer -c /home/btc/cgminer.conf -S auto
  56. sleep 300'> /home/btc/cgminer.sh
  57. echo '#!/bin/sh
  58.  
  59. screen -dmS cgminer /home/btc/cgminer.sh' > /home/btc/cgminer-screen.sh
  60. echo '#!/bin/sh
  61.  
  62. su btc -c /home/btc/cgminer-screen.sh' > /home/btc/cgminer-screen-as-btc.sh
  63. echo '#!/bin/sh
  64.  
  65. echo "Press CTRL+A then D to leave cgminer running"
  66. echo "Run ls -laR /var/run/screen/S-btc to see all running screens for user btc"
  67. sleep 2
  68. screen -r btc/cgminer' > /home/btc/view-cgminer-screen.sh
  69. echo 'if [ -f ~/.bashrc ]; then
  70.        . ~/.bashrc
  71. fi' > /home/btc/.bash_profile
  72. echo '~/view-cgminer-screen.sh' > /home/btc/.bashrc
  73. echo 'multiuser on
  74. acladd root
  75. acladd pi' > /home/btc/.screenrc
  76. ln -s /home/btc/cgminer.sh /root/cgminer.sh
  77. ln -s /home/btc/cgminer.sh /home/pi/cgminer.sh
  78. ln -s /home/btc/cgminer-screen.sh /root/cgminer-screen.sh
  79. ln -s /home/btc/cgminer-screen.sh /home/pi/cgminer-screen.sh
  80. ln -s /home/btc/cgminer-screen-as-btc.sh /root/cgminer-screen-as-btc.sh
  81. ln -s /home/btc/cgminer-screen-as-btc.sh /home/pi/cgminer-screen-as-btc.sh
  82. ln -s /home/btc/view-cgminer-screen.sh /root/view-cgminer-screen.sh
  83. ln -s /home/btc/view-cgminer-screen.sh /home/pi/view-cgminer-screen.sh
  84. ln -s /home/btc/cgminer.conf /root/cgminer.conf
  85. ln -s /home/btc/cgminer.conf /home/pi/cgminer.conf
  86. chmod +x /home/btc/*.sh
  87. chmod +x /root/*.sh
  88. chmod +x /home/pi/*.sh
  89. chown -R pi:pi /home/pi/
  90. chown -R btc:btc /home/btc/
  91.  
  92. #Install things :) Some are required by cgminer to compile, others will be used later
  93. aptitude install fail2ban autoconf libtool libncurses-dev yasm curl libcurl4-openssl-dev pkg-config git screen mailx watchdog chkconfig libusb-1.0-0-dev
  94.  
  95. #Update RPI firmware (needs git, that's why we didn't did it before)
  96. wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && chmod +x /usr/bin/rpi-update
  97. rpi-update
  98.  
  99. #Retrieve and install cgminer
  100. cd /root
  101. git clone https://github.com/ckolivas/cgminer.git cgminer
  102. cd cgminer
  103. aclocal
  104. ./autogen.sh
  105. export LIBCURL_CFLAGS='-I/usr/include/curl'
  106. export LIBCURL_LIBS='-L/usr/lib -lcurl'
  107. ./configure --enable-bitforce --enable-icarus --enable-modminer --enable-ztex
  108. make
  109. make install
  110.  
  111.  
  112. #Watch dog the system
  113. #Enable automatic hard reboot in case of system freeze: use the hardware Raspberry Watchdog
  114. #Load watchdog drivers:
  115. modprobe bcm2708_wdog
  116. nano /etc/modules
  117.     bcm2708_wdog
  118.  
  119. #Software watchdog, that will also feed the hardware watchdog
  120. nano /etc/watchdog.conf
  121.     #ping = 8.8.8.8 #doesn't work, make the system to reboot continuously
  122.     watchdog-device = /dev/watchdog
  123.     max-load-15 = 18
  124. chkconfig watchdog on
  125. /etc/init.d/watchdog start
  126.  
  127. #Cron job that will ensure cgminer is always running and will restart it if not
  128. echo '#!/bin/bash
  129. #
  130. # watchdog
  131. #
  132. # Run as a cron job to keep an eye on what_to_monitor which should always
  133. # be running. Restart what_to_monitor and send notification as needed.
  134. #
  135. # This needs to be run as root or a user that can start system services.
  136. #
  137. # Revisions: 0.1 (20100506), 0.2 (20100507)
  138.  
  139. NAME=cgminer.sh
  140. START=/home/btc/cgminer-screen-as-btc.sh
  141. #NOTIFY=person1email
  142. #NOTIFYCC=person2email
  143. GREP=/bin/grep
  144. PS=/bin/ps
  145. NOP=/bin/true
  146. DATE=/bin/date
  147. #MAIL=/usr/bin/mail
  148. #RM=/bin/rm
  149.  
  150. $PS -ef|$GREP -v grep|$GREP $NAME >/dev/null 2>&1
  151. case "$?" in
  152. 0)
  153. # It is running in this case so we do nothing.
  154. echo "$NAME is running, nothing to do"
  155. $NOP
  156. ;;
  157. 1)
  158. echo "$NAME is NOT RUNNING. Starting $NAME and sending notices."
  159. $START 2>&1 >/dev/null &
  160. NOTICE=/tmp/cgminer-watchdog.log
  161. echo "$NAME was not running and was started on `$DATE`" >> $NOTICE
  162. #$MAIL -n -s "watchdog notice" -c $NOTIFYCC $NOTIFY < $NOTICE
  163. #$RM -f $NOTICE
  164. ;;
  165. esac
  166.  
  167. exit' > /root/cgminer-watchdog.sh
  168.  
  169. chmod +x /root/cgminer-watchdog.sh
  170. crontab -e
  171.     * * * * * /root/cgminer-watchdog.sh
  172.  
  173.  
  174. #Enable cgminer to start with system
  175. #Let the watchdog start it, to prevent multiple executions
  176. nano /etc/rc.local
  177.     sleep 10
  178.     /root/cgminer-watchdog.sh
  179.  
  180. #Update script that will upgrade cgminer. It won't run automatically, so run it when you want to upgrade your cgminer
  181. echo '#!/bin/sh
  182.  
  183. aptitude update
  184. #/usr/bin/rpi-update
  185.  
  186. cd /root/cgminer
  187. git remote update
  188. git pull
  189. aclocal
  190. ./autogen.sh
  191. export LIBCURL_CFLAGS="-I/usr/include/curl"
  192. export LIBCURL_LIBS="-L/usr/lib -lcurl"
  193. ./configure --enable-bitforce --enable-icarus --enable-modminer --enable-ztex
  194. make
  195. make install' > /root/Update.sh
  196.  
  197. chmod +x /root/Update.sh
  198.  
  199. #Check BFL boxes are recognized:
  200. ls -l /dev/ttyUSB*
  201.  
  202.  
  203. #Make the image public compatible, clean some things
  204. passwd
  205. passwd pi
  206. passwd btc
  207.  
  208. echo '{
  209. "pools": [
  210.        {
  211.                "url": "http://eu.ozco.in:8332",
  212.                "user": "crazydownloaded.raspi",
  213.                "pass": "x"
  214.        },
  215.        {
  216.                "url": "http://mining.bitcoin.cz:8332",
  217.                "user": "crazydownloaded.raspi",
  218.                "pass": "x"
  219.        },
  220.        {
  221.                "url": "http://mergedmining.btcguild.com:8332",
  222.                "user": "crazydownloaded_raspi",
  223.                "pass": "x"
  224.        }
  225. ],
  226.  
  227. "donation": "false"
  228. }' > /home/btc/cgminer.conf
  229.  
  230. echo 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
  231. update_config=1' > /etc/wpa_supplicant/wpa_supplicant.conf
  232.  
  233. rm /home/btc/.bash_history
  234. rm /home/pi/.bash_history
  235. rm /root/.bash_history
  236.  
  237. rm -rf /home/btc/.ssh
  238. rm -rf /home/pi/.ssh
  239. rm -rf /root/.ssh
  240.  
  241. rm /var/log/*.gz
  242. rm /var/log/*.0
  243. rm /var/log/*.1
  244. rm /var/log/*.old
  245. echo "" | tee /var/log/*.log
  246. echo "" | tee /var/log/apt/*.log
  247. echo "" | tee /var/log/*.log
  248. echo "" | tee /var/log/*.err
  249. echo "" | tee /var/log/*.info
  250. echo "" > /var/log/debug
  251. echo "" > /var/log/dmesg
  252. echo "" > /var/log/syslog
  253. echo "" > /var/log/btmp
  254. echo "" > /var/log/messages
  255. echo "" > /var/log/wtmp
  256. echo "" > /var/log/faillog
  257. echo "" > /var/log/lastlog
  258. echo "" > /var/log/aptitude
  259. echo "" > /var/log/ConsoleKit/history
Advertisement
Add Comment
Please, Sign In to add comment