minif

setup

Jan 24th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. --Minif OS Setup
  2. --Functions and Variables
  3. osSetupUser = ""
  4. osSetupPassword = ""
  5.  
  6. local function createUser(user,password)
  7. local pref = fs.open("/system/user/".. user.."/config", "w")
  8. pref.writeLine("/system/images/minif")
  9. pref.writeLine("true")
  10. pref.close()
  11.  
  12. local pref = fs.open("/system/user/".. user.."/.pass", "w")
  13. pref.writeLine(password)
  14. pref.close()
  15.  
  16. fs.delete("/user/".. user)
  17. fs.makeDir("/user/".. user)
  18. fs.delete("/system/user/".. user.."/icon")
  19. if fs.exists("system/images/user1") then
  20. fs.copy("system/images/user1","/system/user/".. user.."/icon")
  21. end
  22. end
  23.  
  24. local function drawUser()
  25. paintutils.drawFilledBox(3,5,osScreenSizeX-2,osScreenSizeY-4,colors.white)
  26. paintutils.drawBox(2,4,osScreenSizeX-1,osScreenSizeY-3,colors.black)
  27. term.setBackgroundColor(colors.white)
  28. term.setTextColor(colors.black)
  29. term.setCursorPos(5,7)
  30. term.write("Create User: ")
  31. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  32. term.setTextColor(colors.black)
  33. term.setCursorPos(5,9)
  34. if osSetupUser == "" then
  35. term.write("Set Username")
  36. else
  37. term.write(osSetupUser)
  38. end
  39. paintutils.drawBox(4,11,osScreenSizeX-3,11, colors.lightBlue)
  40. term.setTextColor(colors.black)
  41. term.setCursorPos(5,11)
  42. if osSetupPassword == "" then
  43. term.write("Set Password")
  44. else
  45. term.write("********")
  46. end
  47. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.lightBlue)
  48. term.setTextColor(colors.black)
  49. term.setCursorPos(5,13)
  50. term.write("Create User")
  51. end
  52.  
  53. local function runUser()
  54. osSettingsSelectedUser = osEnteredUser
  55. while true do
  56. drawUser()
  57. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  58. if osPX >= 3 and osPX <= osScreenSizeX-2 then
  59. if osPY == 9 then
  60. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  61. term.setTextColor(colors.black)
  62. term.setCursorPos(5,9)
  63. osSetupUser = read()
  64. else
  65. if osPY == 11 then
  66. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightBlue)
  67. term.setTextColor(colors.black)
  68. term.setCursorPos(5,11)
  69. local temppass = read("*")
  70.  
  71. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightBlue)
  72. term.setTextColor(colors.black)
  73. term.setCursorPos(5,11)
  74. term.write("Confirm: ")
  75. local temppassc = read("*")
  76.  
  77. if temppass == temppassc then
  78. osSetupPassword = temppass
  79. end
  80. else
  81. if osPY == 13 then
  82. if osSetupUser == "" then else
  83. createUser(osSetupUser, osSetupPassword)
  84. if fs.exists("/user/".. osSetupUser) then
  85. term.setBackgroundColor(colors.white)
  86. term.setTextColor(colors.black)
  87. term.setCursorPos(5,15)
  88. term.write("User ".. osSetupUser .. " Created!")
  89. local data = fs.open("system/setupdata","w")
  90. data.writeLine("User Created!")
  91. data.close()
  92. sleep(2)
  93. return
  94. end
  95. end
  96. end
  97. end
  98. end
  99. end
  100. end
  101. end
  102.  
  103. --Execution
  104.  
  105. drawUser()
  106. runUser()
Advertisement
Add Comment
Please, Sign In to add comment