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

Legion - mass labeling and program installing

Started by baturinsky, 15 November 2012 - 05:15 PM
baturinsky #1
Posted 15 November 2012 - 06:15 PM
It is a simple program that should be placed to disk in "disk/startup" directory.
It does two things - copies contents of "install" directory on floppy to root directory of computer/turtle, and sets label to whatever is in "disk/label", incrementing numeral inside. So, if you have "T-1000" in "label", then first nameless turtle you place near it will have label "T-1000", second "T-1001", etc, and all will have same programs installed.

Computers with labels will keep label and programs even after picking up, but will no longer stack.

Pastebin: http://pastebin.com/VuQuMF0V

Code:

if shell.getRunningProgram() == "disk/startup" then
  print("Installing...")
  if fs.isDir("disk/install") then
	local files = fs.list("disk/install")
	for _,file in ipairs( files ) do
	  print("disk/install/"..file.." -> "..file)
	  fs.delete(file)
	  fs.copy("disk/install/"..file,file)
	end
  else
	print "No files to install. Put install files to directory 'disk/install'"
  end
  if not os.getComputerLabel("label") then
	labelFile = fs.open("disk/label", "r")
	if labelFile then
	  label = labelFile.readAll()
	  labelFile.close()
	  os.setComputerLabel(label)
	  label = string.gsub(label, '[0-9]+', function (x) return x+1 end)
	  labelFile = fs.open("disk/label", "w")
	  labelFile.write(label)
	  labelFile.close()
	  print("Set label to " .. label)
	else
	  print "No label file. Put label to file 'disk/label'nIt should contain number, that will be incremented each time"
	end
  end
  print("Done!")
else
  print "Place a disk drive with floppy near computer and copy this program to disk/startup"
end

Btw, if you want to remove label to many computers (turtles) and don't want to type "label clear" by hand for each, you can use a floppy with "os.setComputerLabel()" indisk/startup
Tiin57 #2
Posted 17 November 2012 - 02:28 PM
/Programs/
NOT
/Programs/APIs and Utilities/
'Nuff said.
Orwell #3
Posted 17 November 2012 - 02:48 PM
I believe it could qualify as a utility… Since when are you a backseat mod? You could as easily report it, instead of bashing on someone's perfectly good program for an irrelevant reason.

On topic:
Good job baturinsky, programs like this often come in handy. :)/>/>
Tiin57 #4
Posted 17 November 2012 - 03:43 PM
Right… Sorry about that. Not sure why I said that.
baturinsky, the program is good. I think that this has many practical uses.
billysback #5
Posted 17 November 2012 - 11:41 PM
I thought Utitlities were outside applications to do with CC; such as CCEmu or CTR
Tiin57 #6
Posted 18 November 2012 - 12:19 AM
I thought Utitlities where outside applications to do with CC; such as CCEmu or CTR
And this is why I posted. ^.^
Whatever.