initc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env lua
  2. package.path = "/usr/milis/mps/lua/?.lua" .. ";".. package.path
  3. package.path = "/etc/init/?.lua" .. ";".. package.path
  4. local c = require ("config")
  5. local serpent = require('serpent')
  6. local config_file="/etc/init/config.lua"
  7. local key=arg[1]
  8. local val=arg[2]
  9. function tprint(tablo)
  10. local data=serpent.block(tablo)
  11. if val ~=nil then
  12. -- açık çıktıyı kullan
  13. io.output(io.open(config_file, "w"))
  14. io.write("local config=")
  15. io.write(data)
  16. io.write("\n")
  17. io.write("return config")
  18. io.write("\n")
  19. io.close()
  20. else
  21. print(data)
  22. end
  23. end
  24. function cprint(value)
  25. print(value)
  26. os.exit()
  27. end
  28. if key~= nil then
  29. local poz=key:find(".",1,true)
  30. if poz ~= nil then
  31. key1=key:sub(1,poz-1)
  32. key2=key:sub(poz+1,-1)
  33. if key2 == "1" then key2=1 end
  34. if key2 == "2" then key2=2 end
  35. if key2 == "3" then key2=3 end
  36. if val ~=nil then
  37. if val == "nil" then c[key1][key2]=nil
  38. elseif val == "" then c[key1][key2]=""
  39. else c[key1][key2]=val end
  40. else
  41. cprint(c[key1][key2])
  42. end
  43. elseif key == "action" then
  44. if val == "execute" then
  45. c.action=os.execute
  46. else
  47. c.action=print
  48. end
  49. else
  50. if val ~=nil then
  51. c[key]=val
  52. else
  53. cprint(c[key])
  54. end
  55. end
  56. end
  57. tprint(c)