Advertisement
Guest User

clientInstall.lua

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local term=require("term")
  2. local file=require("filesystem")
  3. local serial=require("serialization")
  4. local autostart= {"dnsclient"}
  5. local process=require("process")
  6. local shell=require("shell")
  7. function addeProgs(line)
  8.   for _, daemon in pairs(autostart) do
  9.     local found=false
  10.     local i=1
  11.     last=i
  12.     for key, value in pairs(line["enabled"]) do
  13.       if value==daemon then
  14.         found=true
  15.       end
  16.       i=i+1
  17.       last=i
  18.     end
  19.     if not found then
  20.       line["enabled"][last]=daemon
  21.     end
  22.   end
  23.   return line
  24. end
  25.  
  26. function configRC()
  27.   lines={}
  28.   local line=""
  29.   local i=1
  30.   local dat=io.open("/etc/rc.cfg", "r")  
  31.   local newtext=""
  32.   repeat
  33.     local c=dat:read(1)
  34.     if c=="\n" then
  35.       lines[i]=line
  36.       i=i+1
  37.       line=""
  38.     end
  39.     line=line .. (c or " ")
  40.   until not c
  41.   dat:close()
  42.   for key, value in pairs(lines) do
  43.     local l=serial.unserialize("{"..value.."}")
  44.     if l~=nil and  l["enabled"]~=nil then
  45.       l=addeProgs(l)
  46.       value=serial.serialize(l)
  47.       value=string.sub(value, 2, #value-1)      
  48.     end
  49.     newtext=newtext .. value .. "\n"
  50.   end
  51.   dat=io.open("/etc/rc.cfg", "w")
  52.   dat:write(newtext)
  53.   dat:close()
  54. end
  55.  
  56. function copyFiles()
  57.   file.remove("/lib/dns.lua")
  58.   file.remove("/etc/rc.d/dnsclient.lua")
  59.   file.remove("/etc/dns.cfg")
  60.   shell.execute("pastebin get 3ZWNnPKZ /etc/rc.d/dnsclient.lua")
  61.   shell.execute("pastebin get avL7Zwxt /lib/dns.lua
  62.  shell.execute("pastebin get UGpiAYFp /etc/dns.cfg
  63. end
  64.  
  65. function namePC()
  66.   local dat=io.open("/etc/dns.cfg","r")
  67.   local text=dat:read("*all")
  68.   dat:close()
  69.   local config=serial.unserialize(text)
  70.   if not config["server"] then
  71.     term.clear()
  72.     term.write("Computernamen bitte eingeben: ")
  73.     config["computername"]=io.read()
  74.   else
  75.     config["computername"]=config["dnsserver"]
  76.   end
  77.   dat=io.open("/etc/dns.cfg","w")
  78.   dat:write(serial.serialize(config))
  79.   dat:close()  
  80. end
  81.  
  82. copyFiles()
  83. namePC()
  84. configRC()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement