Advertisement
Renjestoo

startup

Aug 27th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.16 KB | None | 0 0
  1. local computerName = os.getComputerLabel()
  2. if not computerName then error("Please set the label of this computer") end
  3. local settings = {}
  4. local fileSettings = "settings.txt"
  5. shell.run("id")
  6. local files = {}
  7. local iLocal = 0
  8. local iGlobal = 0
  9.  
  10. local apis = {
  11.     gbMenu = {name="Glasses Bridge Menu", file="gbMenu", pbLink = "3phAmDLV"},
  12.     goto = {name="Go To", file="goto", pbLink="i0i9fejL"},
  13.     inventory = {name="Inventory", file="inventory", pbLink="3bMNrX57"},
  14.     pt = {name="Table Serializer", file="pt", pbLink="xeJWhzhN"},
  15.     termMenu = {name="Terminal Menu", file="termMenu", pbLink="imwqJg9N"},
  16.     tools = {name="Common Tools", file="tools", pbLink="kkgiV37C"},
  17. }
  18.  
  19. local tables = {
  20.     items = {name="Items Table", file="items.tbl"},
  21.     names = {name="Computer Names", file="names.tbl", pbLink = "UMb7exyE"},
  22.     freqs = {name="Tesseract Frequencies", file="frequencies.tbl", pbLink = "ATyqWyKg"},
  23.     recipes = {name="Recipes Table", file="recipes.tbl"}
  24. }
  25.  
  26. local programs = {
  27.     termInterface = {file="termInterface.lua", name="termInterface", pbLink="jFANs4S9", settings={
  28.             {name="freqDropOff", desc="Name of tesseract frequency to use", t="string"}
  29.         }
  30.     },
  31.     apps = {file="apps.lua", name="Apps", pbLink="xP4U7nDs", settings={
  32.             {name="name", desc="Who will be using this turtle?", t="string"}
  33.         }
  34.     },
  35.     sortMaster = {file="sortMaster.lua", name="Sort Master", pbLink="LbNcQ3S3", settings={
  36.             {name="width", desc="How many storage units wide?", t="integer", lVal=0},
  37.             {name="fuelName", desc="Type of fuel to use (ie Coal)", t="string"},
  38.             {name="up", desc="Build the wall up or down?", t="boolean", lVal="down", hVal="up"},
  39.             {name="tesseractDirection", desc="Direction from chest to tesseract (ie north)", t="string"}
  40.         }
  41.     },
  42.     crafter = {file="crafter.lua", name="Crafter", pbLink="Eske6u4i", settings={}},
  43.     retriever = {file="retriever.lua", name="Retreiver", pbLink="H2hD1Cqg", settings={
  44.             {name="pushDir", desc="Direction from DSU to turtle (ie north)", t="string"},
  45.             {name="xHome", desc="X Position or origin", t="integer", lVal=nil, hVal=nil},
  46.             {name="yHome", desc="Y Position or origin", t="integer", lVal=nil, hVal=nil},
  47.             {name="zHome", desc="Z Position or origin", t="integer", lVal=nil, hVal=nil},
  48.             {name="minFuel", desc="Level at which to refuel", t="integer", lVal = 100},
  49.             {name="maxFuel", desc="Level at which to stop refuelling", t="integer", lVal = 1000}
  50.         }
  51.     },
  52.     lavaBuckets = {file="lavaBuckets.lua", name="Lava Buckets", pbLink=nil, settings={}},
  53.     itemBuffer = {file="itemBuffer.lua", name="Item Buffer", pbLink="XSDW1Vrh", settings={
  54.             {name="dropDir", desc="Direction to drop the items (up/down/fwd)", t="string"},
  55.             {name="sleepTime", desc="Seconds to sleep before dropping items", t="integer", lVal=1, hVal=nil}
  56.         }
  57.     },
  58.     sorter = {file="sorter.lua", name="Sorter", pbLink="gkbKFL2c", settings={
  59.             {name="pushDir", desc="Direction from DSU to turtle (ie north)", t="string"},
  60.             {name="xHome", desc="X Position or origin", t="integer", lVal=nil, hVal=nil},
  61.             {name="yHome", desc="Y Position or origin", t="integer", lVal=nil, hVal=nil},
  62.             {name="zHome", desc="Z Position or origin", t="integer", lVal=nil, hVal=nil}
  63.         }
  64.     },
  65.     bridge = {file="bridge.lua", name="Bridge", pbLink="TSxdHwzW", settings={}},
  66.     engineMonitor = {file="engineMonitor.lua", name="Engine Monitor", pbLink="zzfmkbK9", settings={}},
  67.     engineStack = {file="engineStack.lua", name="Engine Stack", pbLink="5gwVvR04", settings={
  68.             {name="stackNum", desc="Which stack of engines is this?", t="integer"},
  69.             {name="lowLevel", desc="Level to turn the engines back on", t="integer", lVal=0, hVal=100},
  70.             {name="highLevel", desc="Level to turn the engines off", t="integer", lVal=0, hVal=100},
  71.             {name="batSide", desc="Which side the battery is on", t="string"},
  72.             {name="cableSide", desc="Which side the rednet cable is on", t="string"},
  73.             {name="sleepTime", desc="Time between taking readings", t="integer", lVal=1}
  74.         }
  75.     },
  76.     grapher = {file="grapher.lua", name="Grapher", pbLink="c38hZ7yA", settings={}},
  77.     oilL = {file="oilL.lua", name="Oil Well Large", pbLink="KDUw1Zne", settings={}},
  78.     tunnel = {file="tunnel.lua", name="Tunnel", pbLink="GqXCYPta", settings={}},
  79.     turtleMonitor = {file="turtleMonitor.lua", name="Turtle Monitor", pbLink="W8VrYsZj", settings={}},
  80.     startup = {file="startup", name="Startup", pbLink="ZzHfdqdA", settings={}},
  81.     queue = {file="queue.lua", name="Item Queue", pbLink="DWPDXv58", settings={
  82.             {name="gbNum", desc="terminal_glasses_bridge_X", t="integer", lVal=0}
  83.         }
  84.     },
  85.     gbInterface = {file="gbInterface.lua", name="Glasses Bridge Interface", pbLink="C8bfDE9U", settings={
  86.             {name="defaultDest", desc="Name of tesseract freq to default to", t="string"},
  87.             {name="destResetDelay", desc="Time to wait before reseting to default (s)", t="integer", lVal = 10},
  88.             {name="gbNum", desc="terminal_glasses_bridge_X", t="integer", lVal=0}
  89.         }
  90.     },
  91.     itemID = {file="itemID.lua", name="Item Identifier", pbLink="0NrC60wJ", settings={}},
  92.     wallBuilder = {file="wallBuilder.lua", name="Wall Builder", pbLink="gMZeRLbR", settings={}},
  93.     fuelSupply = {file="fuelSupply.lua", name="Fuel Supplier", pbLink="SbzXmTQv", settings={
  94.             {name="pushDir", desc="Direction from DSU to tesseract (ie north)", t="string"}
  95.         }
  96.     },
  97.     dutyCycle = {file="dutyCycle.lua", name="Duty Cycle", pbLink="H0KkGPSY", settings={
  98.             {name="period", desc="Period of cycle (s)", t="integer", lVal=0},
  99.             {name="dutyCycle", desc="Percent of time to be on", t="integer", lVal=0, hVal=100},
  100.             {name="outputSide", desc="Side to output redstone (ie top)", t="string"},
  101.             {name="onState", desc="Is on high or low?", t="boolean", hVal="high", lVal="low"}
  102.         }
  103.     },
  104.     topOff = {file="topOff.lua", name="Top Off", pbLink="EJJrE9zp", settings={
  105.             {name="pSide", desc="Side of peripheral (ie top)", t="string"},
  106.             {name="amount", desc="Amount to order when empty", t="integer", lVal=0, hVal=1024},
  107.             {name="itemName", desc="Name of item (ie Coal)", t="string"},
  108.             {name="invSlot", desc="Slot of peripheral to monitor", t="integer", lVal=0},
  109.             {name="sleepTime", desc="Seconds between checking", t="integer", lVal=0},
  110.             {name="freqName", desc="Name of tesseract frequency", t="string"}
  111.         }
  112.     }
  113. }
  114.  
  115. local function fileNames(tbl)
  116.     local pathGlobal = "/rom/shared/"
  117.     local pathLocal = "/files/"
  118.     for k,v in pairs(tbl) do
  119.         if fs.exists(v.file) then
  120.             --No need to change the location
  121.             files[k] = v.file
  122.             iLocal = iLocal + 1
  123.         elseif fs.exists(pathGlobal..v.file) then
  124.             --Use global location
  125.             files[k] = pathGlobal..v.file
  126.             iGlobal = iGlobal + 1
  127.         elseif fs.exists(pathLocal..v.file) then
  128.             --Use local shared folder
  129.             files[k] = pathLocal..v.file
  130.             iLocal = iLocal +1
  131.         elseif v.pbLink then
  132.             print("Downloading "..v.name.." from pasteBin")
  133.             if not fs.exists(pathLocal) then fs.makeDir(pathLocal) end
  134.             local s = pathLocal..v.file
  135.             shell.run("pastebin", "get", v.pbLink, s)
  136.             sleep(1)
  137.             files[k] = s
  138.             iLocal = iLocal + 1
  139.         else
  140.             print(v.file.." not found")
  141.         end
  142.     end
  143. end
  144. --[[    Prompts the user for the desired settings   ]]
  145. function promptSettings(rS, progName)
  146.     local fSettings = fs.open("settings.txt", "w")
  147.     os.loadAPI(files.termMenu)
  148.     local w, h = term.getSize()
  149.     termMenu.new(2,2,w-2,h-2,term)
  150.     for i=1,#rS do
  151.         termMenu.drawBox(1,1,1,1)
  152.         termMenu.printCenterX(1, progName.." needs "..rS[i].t)
  153.         termMenu.printCenterX(2, rS[i].desc)
  154.  
  155.         local input ="no"
  156.         if rS[i].t == "integer" then
  157.             input = termMenu.getInputNum(rS[i].name, rS[i].lVal, rS[i].hVal)
  158.         elseif rS[i].t == "boolean" then
  159.             input = termMenu.getInputBoolean(rS[i].name, rS[i].hVal, rS[i].lVal)
  160.         elseif rS[i].t == "string" then
  161.             input = termMenu.getInputString(rS[i].name)
  162.         end
  163.         if type(input)~="string" then input = tostring(input) end
  164.         fSettings.writeLine("#"..rS[i].desc)
  165.         fSettings.writeLine(rS[i].name.."="..input)
  166.     end
  167.     fSettings.close()
  168. end
  169.  
  170. local function getSettings()
  171.     if fs.exists(fileSettings) then
  172.         file = fs.open(fileSettings, "r")
  173.         local count = 0
  174.         local line = file.readLine()
  175.         while line ~= nil do
  176.             if string.sub(line, 1, 1)~="#" then --# is comment character
  177.                 local split, split2 = string.find(line, "=")
  178.                 local key = string.sub(line, 1, split-1)
  179.                 local value = string.sub(line, split+1)
  180.                 local n = tonumber(value)
  181.                 if n~=nil then value = n end
  182.                 if value=="true" then value = true end
  183.                 if value=="false" then value = false end
  184.                 settings[key] = value
  185.                 count = count + 1
  186.             end
  187.             line = file.readLine()
  188.         end
  189.         file.close()
  190.         print("Loaded "..count.." settings")
  191.     elseif next(programs[computerName].settings) then
  192.         promptSettings(programs[computerName].settings, computerName)
  193.         os.reboot()
  194.     else
  195.         print("No settings needed")
  196.     end
  197. end
  198.  
  199. if not programs[computerName] then error(computerName.." not in list of programs") end
  200. print("Checking for APIs")
  201. fileNames(apis)
  202. print("Checking for Tables")
  203. fileNames(tables)
  204. print("Checking for Programs")
  205. fileNames(programs)
  206. print("Getting settings")
  207. getSettings()
  208. sleep(.1)
  209.  
  210. if fs.exists(files[computerName]) then
  211.     print(files[computerName])
  212.     --sleep(2)
  213.     return os.run({settings = settings, files = files, idMe = os.computerID()}, files[computerName])
  214. else
  215.     error(files[computerName].." not found")
  216. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement