SHOW:
|
|
- or go back to the newest paste.
| 1 | #Switch to root | |
| 2 | - | sudo passwd pi |
| 2 | + | |
| 3 | sudo su - | |
| 4 | ||
| 5 | #Enable testing updates | |
| 6 | nano /etc/apt/sources.list | |
| 7 | deb http://mirrordirector.raspbian.org/raspbian/ testing main contrib non-free rpi | |
| 8 | ||
| 9 | nano /etc/apt/sources.list.d/raspi.list | |
| 10 | no change (testing not available here, nor stable, only wheezy) | |
| 11 | ||
| 12 | #Update the system | |
| 13 | aptitude update | |
| 14 | aptitude dist-upgrade | |
| 15 | ||
| 16 | #Enable automatic (security) upgrades | |
| 17 | aptitude install unattended-upgrades apticron | |
| 18 | nano /etc/apt/apt.conf.d/50unattended-upgrades | |
| 19 | nano /etc/apt/apt.conf.d/02periodic | |
| 20 | // Enable the update/upgrade script (0=disable) | |
| 21 | - | nano /etc/apt/apt.conf.d/02periodic (new file) |
| 21 | + | |
| 22 | ||
| 23 | // Do "apt-get update" automatically every n-days (0=disable) | |
| 24 | APT::Periodic::Update-Package-Lists "1"; | |
| 25 | ||
| 26 | // Do "apt-get upgrade --download-only" every n-days (0=disable) | |
| 27 | APT::Periodic::Download-Upgradeable-Packages "1"; | |
| 28 | ||
| 29 | // Run the "unattended-upgrade" security upgrade script | |
| 30 | // every n-days (0=disabled) | |
| 31 | // Requires the package "unattended-upgrades" and will write | |
| 32 | // a log in /var/log/unattended-upgrades | |
| 33 | APT::Periodic::Unattended-Upgrade "1"; | |
| 34 | ||
| 35 | // Do "apt-get autoclean" every n-days (0=disable) | |
| 36 | APT::Periodic::AutocleanInterval "7"; | |
| 37 | nano /etc/apticron/apticron.conf | |
| 38 | #Security updates are enabled by default, feel free to accept more | |
| 39 | ||
| 40 | #FSCK repair when HD have inconistencies | |
| 41 | nano /etc/default/rcS | |
| 42 | FSCKFIX=yes | |
| 43 | ||
| 44 | #Let's configure the system for cgminer | |
| 45 | groupadd btc | |
| 46 | useradd -g btc btc | |
| 47 | mkdir /home/btc/ | |
| 48 | - | usermod -a -G dialout btc |
| 48 | + | cp -R .ssh /home/btc/ |
| 49 | cp -R .ssh /home/pi/ | |
| 50 | - | groups btc |
| 50 | + | echo "#!/bin/sh\n\ncgminer -c /home/btc/cgminer.conf -S auto\nsleep 300\n" > /home/btc/cgminer.sh |
| 51 | echo "#!/bin/sh\n\nscreen -dmS cgminer /home/btc/cgminer.sh\n" > /home/btc/cgminer-screen.sh | |
| 52 | echo "#!/bin/sh\n\nsu btc -c /home/btc/cgminer-screen.sh\n" > /home/btc/cgminer-screen-as-btc.sh | |
| 53 | - | echo '#!/bin/sh |
| 53 | + | echo "#!/bin/sh\n\necho "Press CTRL+A then D to leave cgminer running"\necho "Run ls -laR /var/run/screen/S-btc to see all running screens for user btc"\nsleep 2\nscreen -r btc/cgminer\n" > /home/btc/view-cgminer-screen.sh |
| 54 | echo "if [ -f ~/.bashrc ]; then\n . ~/.bashrc\nfi\n" > /home/btc/.bash_profile | |
| 55 | - | cgminer -c /home/btc/cgminer.conf -S auto |
| 55 | + | echo "~/view-cgminer-screen.sh" > /home/btc/.bashrc |
| 56 | - | sleep 300'> /home/btc/cgminer.sh |
| 56 | + | echo "multiuser on\nacladd root\nacladd pi" > /home/btc/.screenrc |
| 57 | - | echo '#!/bin/sh |
| 57 | + | |
| 58 | ln -s /home/btc/cgminer.sh /home/pi/cgminer.sh | |
| 59 | - | screen -dmS cgminer /home/btc/cgminer.sh' > /home/btc/cgminer-screen.sh |
| 59 | + | |
| 60 | - | echo '#!/bin/sh |
| 60 | + | |
| 61 | ln -s /home/btc/cgminer-screen-as-btc.sh /root/cgminer-screen-as-btc.sh | |
| 62 | - | su btc -c /home/btc/cgminer-screen.sh' > /home/btc/cgminer-screen-as-btc.sh |
| 62 | + | |
| 63 | - | echo '#!/bin/sh |
| 63 | + | |
| 64 | ln -s /home/btc/view-cgminer-screen.sh /home/pi/view-cgminer-screen.sh | |
| 65 | - | echo "Press CTRL+A then D to leave cgminer running" |
| 65 | + | |
| 66 | - | echo "Run ls -laR /var/run/screen/S-btc to see all running screens for user btc" |
| 66 | + | |
| 67 | - | sleep 2 |
| 67 | + | |
| 68 | - | screen -r btc/cgminer' > /home/btc/view-cgminer-screen.sh |
| 68 | + | |
| 69 | - | echo 'if [ -f ~/.bashrc ]; then |
| 69 | + | |
| 70 | - | . ~/.bashrc |
| 70 | + | |
| 71 | - | fi' > /home/btc/.bash_profile |
| 71 | + | |
| 72 | - | echo '~/view-cgminer-screen.sh' > /home/btc/.bashrc |
| 72 | + | |
| 73 | - | echo 'multiuser on |
| 73 | + | |
| 74 | - | acladd root |
| 74 | + | |
| 75 | - | acladd pi' > /home/btc/.screenrc |
| 75 | + | |
| 76 | /home/btc/cgminer-screen-as-btc.sh | |
| 77 | ||
| 78 | #Install things :) Some are required by cgminer to compile, others will be used later | |
| 79 | aptitude install fail2ban autoconf libtool libncurses-dev yasm curl libcurl4-openssl-dev pkg-config git screen mailx watchdog chkconfig | |
| 80 | ||
| 81 | #Retrieve and install cgminer | |
| 82 | cd /root | |
| 83 | git clone https://github.com/ckolivas/cgminer.git cgminer | |
| 84 | cd cgminer | |
| 85 | aclocal | |
| 86 | ./autogen.sh | |
| 87 | export LIBCURL_CFLAGS='-I/usr/include/curl' | |
| 88 | export LIBCURL_LIBS='-L/usr/lib -lcurl' | |
| 89 | ./configure --enable-bitforce | |
| 90 | make | |
| 91 | make install | |
| 92 | ||
| 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 |
| 93 | + | |
| 94 | #Watch dog the system | |
| 95 | - | #Update RPI firmware (needs git, that's why we didn't did it before) |
| 95 | + | |
| 96 | - | wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && chmod +x /usr/bin/rpi-update |
| 96 | + | Load watchdog drivers: |
| 97 | - | rpi-update |
| 97 | + | |
| 98 | nano /etc/modules | |
| 99 | bcm2708_wdog | |
| 100 | ||
| 101 | #Software watchdog, that will also feed the hardware watchdog | |
| 102 | nano /etc/watchdog.conf | |
| 103 | #ping = 8.8.8.8 #doesn't work, make the system to reboot continuously | |
| 104 | watchdog-device = /dev/watchdog | |
| 105 | max-load-15 = 18 | |
| 106 | chkconfig watchdog on | |
| 107 | - | ./configure --enable-bitforce --enable-icarus --enable-modminer --enable-ztex |
| 107 | + | |
| 108 | ||
| 109 | #Cron job that will ensure cgminer is always running and will restart it if not | |
| 110 | echo "#!/bin/bash\n#\n# watchdog\n#\n# Run as a cron job to keep an eye on what_to_monitor which should always\n# be running. Restart what_to_monitor and send notification as needed.\n#\n# This needs to be run as root or a user that can start system services.\n#\n# Revisions: 0.1 (20100506), 0.2 (20100507)\n\nNAME=cgminer.sh\nSTART=/home/btc/cgminer-screen-as-btc.sh\n#NOTIFY=person1email\n#NOTIFYCC=person2email\nGREP=/bin/grep\nPS=/bin/ps\nNOP=/bin/true\nDATE=/bin/date\n#MAIL=/usr/bin/mail\n#RM=/bin/rm\n\n$PS -ef|$GREP -v grep|$GREP $NAME >/dev/null 2>&1\ncase \"$?\" in\n0)\n# It is running in this case so we do nothing.\necho \"$NAME is running, nothing to do\"\n$NOP\n;;\n1)\necho \"$NAME is NOT RUNNING. Starting $NAME and sending notices.\"\n$START 2>&1 >/dev/null &\nNOTICE=/tmp/cgminer-watchdog.log\necho \"$NAME was not running and was started on `$DATE`\" >> $NOTICE\n#$MAIL -n -s \"watchdog notice\" -c $NOTIFYCC $NOTIFY < $NOTICE\n#$RM -f $NOTICE\n;;\nesac\n\nexit\n" > /root/cgminer-watchdog.sh | |
| 111 | ||
| 112 | chmod +x /root/cgminer-watchdog.sh | |
| 113 | crontab -e | |
| 114 | - | #Load watchdog drivers: |
| 114 | + | |
| 115 | ||
| 116 | ||
| 117 | #Update script that will upgrade cgminer. It won't run automatically, so run it when you want to upgrade your cgminer | |
| 118 | echo "#!/bin/sh\n\naptitude update\n\ncd /root/cgminer\ngit remote update\ngit pull\naclocal\n./autogen.sh\nexport LIBCURL_CFLAGS='-I/usr/include/curl'\nexport LIBCURL_LIBS='-L/usr/lib -lcurl'\n./configure --enable-bitforce\nmake\nmake install\n" > /root/Update.sh | |
| 119 | ||
| 120 | ||
| 121 | #Check BFL boxes are recognized: | |
| 122 | ls -l /dev/ttyUSB* | |
| 123 | ||
| 124 | ||
| 125 | #Make the image public compatible, clean some things | |
| 126 | passwd | |
| 127 | passwd pi | |
| 128 | - | echo '#!/bin/bash |
| 128 | + | |
| 129 | - | # |
| 129 | + | |
| 130 | - | # watchdog |
| 130 | + | echo "{\n\"pools\": [\n {\n \"url\": \"http://eu.ozco.in:8332\",\n \"user\": \"crazydownloaded.raspi\",\n \"pass\": \"x\"\n },\n {\n \"url\": \"http://mining.bitcoin.cz:8332\",\n \"user\": \"crazydownloaded.raspi\",\n \"pass\": \"x\"\n },\n {\n \"url\": \"http://mergedmining.btcguild.com:8332\",\n \"user\": \"crazydownloaded_raspi\",\n \"pass\": \"x\"\n }\n],\n\n\"donation\": \"false\"\n}\n" > /home/btc/cgminer.conf
|
| 131 | - | # |
| 131 | + | |
| 132 | - | # Run as a cron job to keep an eye on what_to_monitor which should always |
| 132 | + | echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\nupdate_config=1\n" > /etc/wpa_supplicant/wpa_supplicant.conf |
| 133 | - | # be running. Restart what_to_monitor and send notification as needed. |
| 133 | + | |
| 134 | - | # |
| 134 | + | |
| 135 | - | # This needs to be run as root or a user that can start system services. |
| 135 | + | |
| 136 | - | # |
| 136 | + | |
| 137 | - | # Revisions: 0.1 (20100506), 0.2 (20100507) |
| 137 | + | |
| 138 | rm -rf /home/btc/.ssh | |
| 139 | - | NAME=cgminer.sh |
| 139 | + | |
| 140 | - | START=/home/btc/cgminer-screen-as-btc.sh |
| 140 | + | |
| 141 | - | #NOTIFY=person1email |
| 141 | + | |
| 142 | - | #NOTIFYCC=person2email |
| 142 | + | |
| 143 | - | GREP=/bin/grep |
| 143 | + | |
| 144 | - | PS=/bin/ps |
| 144 | + | |
| 145 | - | NOP=/bin/true |
| 145 | + | |
| 146 | - | DATE=/bin/date |
| 146 | + | |
| 147 | - | #MAIL=/usr/bin/mail |
| 147 | + | |
| 148 | - | #RM=/bin/rm |
| 148 | + | |
| 149 | echo "" | tee /var/log/*.err | |
| 150 | - | $PS -ef|$GREP -v grep|$GREP $NAME >/dev/null 2>&1 |
| 150 | + | |
| 151 | - | case "$?" in |
| 151 | + | |
| 152 | - | 0) |
| 152 | + | |
| 153 | - | # It is running in this case so we do nothing. |
| 153 | + | |
| 154 | - | echo "$NAME is running, nothing to do" |
| 154 | + | |
| 155 | - | $NOP |
| 155 | + | |
| 156 | - | ;; |
| 156 | + | |
| 157 | - | 1) |
| 157 | + | |
| 158 | - | echo "$NAME is NOT RUNNING. Starting $NAME and sending notices." |
| 158 | + | |
| 159 | - | $START 2>&1 >/dev/null & |
| 159 | + | |
| 160 | - | NOTICE=/tmp/cgminer-watchdog.log |
| 160 | + |