SHARE
TWEET

Swarminer Installer

Wojbie Oct 13th, 2013 (edited) 4,638 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Wojbie's Swarm Miner Wireless Floppy Disk Instaler
  2. --Instaler for all programs that are part of Wojbie's Swarm Miner
  3. --Designed to be run from Floppy Disk- should not be used other way.
  4. --Downloads all other parts if http Api is online
  5.  
  6. local tArgs = {...}
  7.  
  8. local code=
  9. {
  10. startup="LXLBZK25",
  11. swarminer="2h1RmbAR",
  12. swarmstart="aFgPSyGe",
  13. scanner="4wgEDymE",
  14. cycle="7tWnxwLU",
  15. recovery="pPqghm6F"
  16. }
  17.  
  18. --File Useage
  19.  
  20. local function save(A,B) local file = fs.open(tostring(A),"w") file.write(B) file.close() end
  21. local function saveT(A,B) save(A,textutils.serialize(B)) end
  22. local function saveTH(A,B) save(A,string.gsub(textutils.serialize(B),"},","},\r\n")) end
  23. local function get(A) local file = fs.open(tostring(A),"r") if not file then return false end local data = file.readAll() file.close() if data then return data end end
  24. local function getT(A) local data = get(A) if data then data = textutils.unserialize(data) end if data then return data end end
  25.  
  26.  
  27. --pastebin downloads system
  28.  
  29. local function pasteget(A,B)
  30.         if not http then
  31.                 print( "Http Api is offline" )
  32.                 printError( "Set enableAPI_http to true in ComputerCraft.cfg" )
  33.                 return false
  34.         end
  35.         print("Downloading "..B)
  36.         local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(A))
  37.         if response then
  38.                 local sResponse = response.readAll()
  39.                 response.close()
  40.                 save(B,sResponse)
  41.                 print("Download Successful")
  42.                 return true
  43.                
  44.         else
  45.                 print("Download Failed")
  46.                 return false
  47.         end
  48. end
  49.                
  50. -- Yes/No Questions
  51.  
  52. local function yn(A)
  53. if not A then return false end
  54. local key
  55. write(A.."[y/n]:")
  56. while true do
  57.         _,key = os.pullEvent("key")
  58.         if key==21 then write(keys.getName(key).."\n") sleep(0.01) return true
  59.         elseif key==49 then write(keys.getName(key).."\n") sleep(0.01) return false
  60.         end
  61. end
  62.  
  63. end
  64.  
  65. --Asking for position
  66.  
  67. local function getpos()
  68.         local temp={}
  69.         while true do
  70.                 print("Enter data from F3 Screen")
  71.                 write("Please enter x coordinate:") temp.x=tonumber(read())
  72.                 write("Please enter y coordinate:") temp.y=tonumber(read())
  73.                 write("Please enter z coordinate:") temp.z=tonumber(read())
  74.                 if temp.x and temp.y and temp.z then
  75.                         print("x:"..temp.x.." y:"..temp.y.." z:"..temp.z)
  76.                         if yn("Are thise correct?") then break end
  77.                 end
  78.         end
  79.         return temp
  80. end
  81.  
  82. ---------------------------------Start of progam-----------------------------------
  83.  
  84.  
  85. --Basic self-discovery
  86. local diskPath="/"..string.gsub(shell.getRunningProgram(),"startup","")
  87. local i,side
  88. if diskPath=="/" then print("This program is designed to be run stright from Floppy Disk. Copy this program onto Floppy Disk before using. Terminating") return true end
  89.  
  90. for _,i in pairs(redstone.getSides()) do
  91.         if disk.getMountPath(i) then
  92.                 if "/"..disk.getMountPath(i).."/" == diskPath then side=i break end
  93.         end
  94. end
  95.  
  96. print("This instaler Floppy Disk is run from \""..diskPath.."\" Directory")
  97. if side then
  98.  print("Its connected to "..side.." side of device")
  99.  disk.setLabel(side,"Swarm Floppy nr:"..disk.getID(side))
  100. else
  101.  print("Its connected by remote drive/wired modem network")
  102. end
  103.  
  104. --Cheacking if called argumants
  105.  
  106. if #tArgs==1 then
  107.         if tArgs[1]=="help" or tArgs[1]=="?" then
  108.                 print("Only commands here are \"update\" and \"addzone\" ") return true
  109.         elseif tArgs[1]=="update" then
  110.                 if not http then
  111.                         print("Http Api is offline. Please update files manualy.") return true
  112.                 else
  113.                         print("Http Api is online! Downloading latest versions.")
  114.                         sleep(1)
  115.                         for i,k in pairs(code) do
  116.                                 pasteget(k,diskPath..i)
  117.                         end
  118.                         print("Download complete. Rebotting") os.reboot()  return true
  119.                 end
  120.         elseif tArgs[1]=="addzone" then
  121.                 local order=getT(diskPath.."order.log")
  122.                 if order then
  123.                         print()
  124.                         print("Adding forbidden zone nr "..(#order.zone).." to Order File")
  125.                         print("Zone is a Cuboid defined by 2 point on oposite corners of it.")
  126.                         print("You can choose any oposite corners.")
  127.                         print("If you want to set one block as forbidden simply enter it's coord as both points.")
  128.                         print("Enter coords for point 1")
  129.                         local point1 = getpos()
  130.                         print("Enter coords for point 2")
  131.                         local point2 = getpos()
  132.                         print("Point 1 is x:"..point1.x.." y:"..point1.y.." z:"..point1.z)
  133.                         print("Point 2 is x:"..point2.x.." y:"..point2.y.." z:"..point2.z)
  134.                         print("Cuboid size will is x:"..(math.abs(point1.x-point2.x)+1).." y:"..(math.abs(point1.y-point2.y)+1).." z:"..(math.abs(point1.z-point2.z)+1))
  135.                         if not yn("Is that correct?") then print("Canceling") return false end
  136.                         order.zone[#order.zone+1]={xl=point1.x,yl=point1.y,zl=point1.z,xu=point2.x,yu=point2.y,zu=point2.z}
  137.                         saveTH(diskPath.."order.log",order)    
  138.                 else
  139.                         print("You can addzone only when Floppy Disk contains preformated order")
  140.                 end
  141.                 return true
  142.         end
  143. end
  144.  
  145. --Cheacking if has all needed files
  146. local ok=true
  147. for i,k in pairs(code) do
  148.         if not fs.exists(diskPath..i) then ok=false break end
  149. end
  150.  
  151. if not ok then
  152.         if not http then
  153.                 print("I am missing some files. Http Api is offline. Please replace them manualy.")
  154.                 for i,k in pairs(code) do
  155.                 if not fs.exists(diskPath..i) then print("File "..i.." is missing") end
  156.                 end
  157.         else
  158.                 print("I am missing some files. Http Api is online! Downloading latest versions.")
  159.                 for i,k in pairs(code) do
  160.                         if not fs.exists(diskPath..i) then pasteget(k,diskPath..i) end
  161.                 end
  162.         end
  163. end
  164.  
  165. --running instalators
  166.  
  167. if turtle then
  168.         if not gps.locate(2) then print("No GPS detected") return end
  169.         if rs.getInput("back") then -- Deployed Activated startup.
  170.                 fs.delete("/swarminer")
  171.                 fs.delete("/startup")
  172.                 fs.copy(diskPath.."swarminer","/swarminer")
  173.                 fs.copy(diskPath.."swarmstart","/startup")
  174.                 print("Auto-Installed")
  175.                 print("Starting swarminer configuration")
  176.                 sleep(1)
  177.                 shell.run("/swarminer","instalation",diskPath)
  178.                 return true
  179.         end    
  180.         if yn("Do you want to instal latest swarminer?") then
  181.                 fs.delete("/swarminer")
  182.                 fs.delete("/startup")
  183.                 fs.copy(diskPath.."swarminer","/swarminer")
  184.                 fs.copy(diskPath.."swarmstart","/startup")
  185.                 print("Installed")
  186.                 print("Starting swarminer configuration")
  187.                 sleep(1)
  188.                 shell.run("/swarminer","instalation",diskPath)
  189.                 return true
  190.         end
  191. else
  192.         if yn("Do you want to instal scanner?") then
  193.                 fs.delete("/scanner")
  194.                 fs.delete("/startup")
  195.                 fs.delete("/gps.log")
  196.                 fs.copy(diskPath.."scanner","/scanner")
  197.                 fs.copy(diskPath.."swarmstart","/startup")
  198.                 if yn("Do you want this scanner to act like gps host too??") then
  199.                         local pos={gps.locate(2,true)}
  200.                         if pos[1] then
  201.                                 print("x:"..pos[1].." y:"..pos[2].." z:"..pos[3])
  202.                                 if not yn("Are thise correct?") then return false end
  203.                                 saveT("/gps.log",{x=pos[1],y=pos[2],z=pos[3]})
  204.                         else print("No gps online - Enter Scanner Position manualy") saveT("/gps.log",getpos()) end
  205.                 end
  206.                 shell.run("/scanner")
  207.                 return true
  208.         end
  209. end
  210. if yn("Do you want to preformat order and settings onto Floppy Disk?") then
  211.         shell.run(diskPath.."swarminer","create",diskPath)
  212. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top