This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
corbett's profile picture

Help getting pastebin get to work in a script.

Started by corbett, 31 May 2013 - 04:35 PM
corbett #1
Posted 31 May 2013 - 06:35 PM
Help getting pastebin get to work in a script.

hey im working on an custom collaberation os for myself and i want to have a script to detect if a program is installed. if it is i want it to tun and if not get it from pastebin. have any strings for me?
Lyqyd #2
Posted 31 May 2013 - 11:25 PM
Split into new topic.
Bomb Bloke #3
Posted 01 June 2013 - 12:07 AM
There are various scripts around for pulling things from pastebin, so I assume you want to know how to check if you've already got a given script? For that, refer to the fs API.
corbett #4
Posted 01 June 2013 - 03:17 AM
There are various scripts around for pulling things from pastebin, so I assume you want to know how to check if you've already got a given script? For that, refer to the fs API.

I've tried that but then it says expected =. can you mock up script that i can plug in all my data? it just needs to be a couple of lines and it be a function. i can plug in everything
Bomb Bloke #5
Posted 01 June 2013 - 04:56 AM
Very well. Assuming you just want the programs dumped on the root of each computer's drive;

local scripttable = {{"SomeScript1","PastebinAddress1"},
                          {"SomeScript2","PastebinAddress2"},
                          {"SomeScript3","PastebinAddress3"}}
                          -- Add extra scripts/Pastebin codes as desired.

local function runScriptIMayNotHave(script)
  if fs.exists(script) then
    shell.run(script) -- We have this script, so run it.
    return
  end

  -- Or, if we don't have the script...

  local scriptindex = 0

  for i=1,table.getn(scripttable) do if scripttable[i][1] == script then
    scriptindex = i
    break
  end end

  if scriptindex == 0 then
    print("Error: I've been asked to run a script I don't have and don't know a PasteBin address for.")
    return
  end

  -- If we've reached this point we're ready to download.
  -- Choose your pastebin script and dump it here. Something like:
  -- shell.run("PastebinGrabberScriptname",scripttable[scriptindex][1],scripttable[scriptindex][2])

  -- Make sure the download worked:

  if not fs.exists(script) then
    print("Error: Looks like I've been given a bad URL or something, download failed.")
    return
  end

  -- The script should definitely be on the computer's drive now, so run it.

  shell.run(script)
end