Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #
- # MinerOS bootup manager for CoinCraft-based systems
- #
- # Copyright (C) 2013-2014 BITMINE AG
- #
- import RPIO
- import os
- import pylcdlib
- import time
- import sqlite3
- import pexpect
- import sys
- MINEROS_DB_LOCATION = '/mineros/mineros.db'
- FW_UPDATE_LOCATION = '/update.tar.bz2'
- def init_empty_db():
- try:
- os.remove("/mineros/mineros.db")
- except:
- pass
- os.system("sqlite3 /mineros/mineros.db < /mineros/initdb.sql")
- def start_webui():
- os.system('start-stop-daemon --start --background -m --oknodo --pidfile /run/mineroswebd.pid --exec python -- /mineros/web/index.py')
- def stop_webui():
- os.system('start-stop-daemon --stop --pidfile /run/mineroswebd.pid --exec python -- /mineros/web/index.py')
- def start_cgminer():
- conn = sqlite3.connect(MINEROS_DB_LOCATION)
- c = conn.cursor()
- c.execute('SELECT * FROM cgminer LIMIT 1')
- row = c.fetchone()
- a1_options='16000:800000:8000'
- if row[13]=='0':
- a1_options='16000:600000:4000'
- elif row[13]=='1':
- a1_options='16000:800000:8000'
- elif row[13]=='2':
- a1_options='16000:1000000:8000'
- os.system('start-stop-daemon --start --background -m --oknodo --pidfile /run/cgminer.pid --exec cgminer -- --text-only --lowmem --bitmine-a1-options '+a1_options+' -o '+row[1]+' -O '+row[2]+':'+row[3]+' -o '+row[4]+' -O '+row[5]+':'+row[6]+' -o '+row[7]+' -O '+row[8]+':'+row[9]+' '+row[10]+' --api-allow '+row[12]+' --api-listen --queue 50 '+row[13]+' &')
- c.close()
- def stop_cgminer():
- os.system('start-stop-daemon --stop --pidfile /run/cgminer.pid --exec cgminer')
- def start():
- # Load necessary kernel modules
- os.system("modprobe i2c-bcm2708")
- os.system("modprobe i2c-dev")
- os.system("modprobe w1-gpio")
- os.system("modprobe w1-therm")
- lcd = pylcdlib.lcd(0x21,1)
- lcd.lcd_puts("CoinCraft Desk",1)
- lcd.lcd_puts("booting...",2)
- time.sleep(1)
- # Check if system settings database exists already, otherwise create it
- if os.path.exists(MINEROS_DB_LOCATION) != True:
- init_empty_db()
- # Check if there's a firmware upgrade to decompress
- if os.path.exists(FW_UPDATE_LOCATION) == True:
- lcd.lcd_puts("Firmware upgrade",1)
- lcd.lcd_puts("DO NOT POWER OFF",2)
- time.sleep(5)
- os.chdir("/")
- os.system("tar xjf " + FW_UPDATE_LOCATION)
- os.remove(FW_UPDATE_LOCATION)
- lcd.lcd_puts("Done. Rebooting",2)
- time.sleep(3)
- os.system("reboot")
- sys.exit(0)
- # Check if we have to generate a static resolv.conf file
- conn = sqlite3.connect(MINEROS_DB_LOCATION)
- c = conn.cursor()
- c.execute('SELECT * FROM networking LIMIT 1')
- row = c.fetchone()
- if row[2]==0:
- f=open('/var/run/resolv.conf','w')
- f.write("nameserver "+row[6]+"\nnameserver "+row[7]+"\n")
- f.close()
- # set up GPIO output channel
- RPIO.setwarnings(False)
- RPIO.setup(22, RPIO.OUT)
- # set gpio 22 to high
- RPIO.output(22, True)
- lcd.lcd_puts("Loading WebUI ",2)
- start_webui()
- time.sleep(1)
- lcd.lcd_puts("Loading cgminer",2)
- start_cgminer()
- time.sleep(1)
- lcd.lcd_puts("Loading minerosd",2)
- os.system("python /mineros/minerosd.py start")
- time.sleep(1)
- def stop():
- os.system("python /mineros/minerosd.py stop")
- lcd = pylcdlib.lcd(0x21,1)
- lcd.lcd_puts("CoinCraft Desk",1)
- lcd.lcd_puts("Shutting down",2)
- stop_webui()
- stop_cgminer()
- # set up GPIO output channel
- RPIO.setwarnings(False)
- RPIO.setup(22, RPIO.OUT)
- # set gpio 22 to low
- RPIO.output(22, False)
- lcd.lcd_puts("", 1)
- lcd.lcd_puts("", 2)
- # Entry point
- if sys.argv[1] == 'start':
- start()
- elif sys.argv[1] == 'stop':
- stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement