Advertisement
D_Puppy

wm_install.lua

Jul 30th, 2017
3,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. local component = require("component")
  2. local fs = require("filesystem")
  3. local internet = require("internet")
  4. local shell = require("shell")
  5.  
  6. if not component.isAvailable("internet") then
  7.   io.stderr:write("This program requires an internet card to run.")
  8.   return
  9. end
  10.  
  11. local function get(filename)
  12.   local f, reason = io.open(filename, "w")
  13.   if not f then
  14.     io.stderr:write("Failed opening file for writing: " .. reason)
  15.     return
  16.   end
  17.  
  18.   io.write("Downloading http://www.carr-ireland.com/mc/" .. filename .. " ")
  19.   local url = "http://www.carr-ireland.com/mc/" .. filename
  20.   local result, response = pcall(internet.request, url)
  21.   if result then
  22.     io.write("OK.\nSaving " .. filename)
  23.     for chunk in response do
  24.       io.write(".")
  25.       string.gsub(chunk, "\r\n", "\n")
  26.       f:write(chunk)
  27.     end
  28.  
  29.     f:close()
  30.     io.write("OK\n")
  31.   else
  32.     io.write("failed.\n")
  33.     f:close()
  34.     fs.remove(filename)
  35.     io.stderr:write("HTTP request failed: " .. response .. "\n")
  36.   end
  37. end
  38.  
  39. local path = shell.getWorkingDirectory()
  40. --print(path)
  41.  
  42. if fs.exists("/usr/lib") == false then
  43.   fs.makeDirectory("/usr/lib")
  44. end
  45. fs.makeDirectory("/usr/lib/windowmanager")
  46. fs.makeDirectory("/etc/windowmanager")
  47.  
  48. shell.setWorkingDirectory("/usr/lib/windowmanager")
  49.  
  50. get("windowmanager.tar")
  51. get("tar.lua")
  52. shell.execute("tar -x -f -v windowmanager.tar", _ENV)
  53. print("Removing windowmanager.tar ")
  54. fs.remove("/usr/lib/windowmanager/windowmanager.tar")
  55. print("Removing tar.lua ")
  56. fs.remove("/usr/lib/windowmanager/tar.lua")
  57.  
  58. if fs.exists("/usr/bin") == false then
  59.   fs.makeDirectory("/usr/bin")
  60. end
  61. shell.setWorkingDirectory("/usr/bin")
  62.  
  63. get("windowmanager.lua")
  64.  
  65. shell.setWorkingDirectory(path)
  66. shell.execute("windowmanager save-config")
  67.  
  68. print("Done")
  69. print("Start windowmanager.lua and enjoy")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement