Belzebub

autorun.lua

Feb 28th, 2021 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. -- Запускает команду/скрипт при ребуте пк
  2. -- Поместите в /autorun.lua
  3.  
  4. local StartTime = 5
  5. local ScriptPath = "/home/start.lua"
  6.  
  7. --————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————--
  8.  
  9. local event = require("event")
  10. local component = require("component")
  11. local process = require("process")
  12. local gpu, screen = component.gpu, component.screen
  13.  
  14. require("term").clear()
  15.  
  16. print("Запуск программы произойдёт через ".. StartTime .." секунд")
  17. print("Нажмите любую клавишу что-бы отменить запуск.")
  18.  
  19. for i = 1, StartTime / 0.01 do
  20. local eventType = event.pull(0)
  21. if eventType == "key_down" then
  22. print("Отмена запуска программы!")
  23. return
  24. end
  25. end
  26.  
  27. os.execute(ScriptPath)
  28.  
  29. event.timer(10, function()
  30. if gpu.getScreen() ~= screen.address then -- на многих серверах экраны тупо дохнут и их приходиться переподключать
  31. gpu.bind(screen.address)
  32. end
  33.  
  34. if (process.running()) ~= ScriptPath then -- то-же костыль. компы кривая штука, порой софт с бесконечным циклом сам по себе завершает работу
  35. os.execute(ScriptPath)
  36. end
  37. end, math.huge)
Add Comment
Please, Sign In to add comment