Advertisement
LDDestroier

install CraftBang

Sep 21st, 2016
2,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local url = "https://raw.github.com/LDDestroier/CraftBang/master/craftbang/"
  2. local files = {}
  3. local filelist = {
  4.     'desktop.lua';
  5.     'dialog.lua';
  6.     'panel.lua';
  7.     'session.lua';
  8.     'terminal.lua';
  9.     'lib/arealib.lua';
  10.     'lib/redirect.lua';
  11. }
  12.  
  13. local function clear()
  14.     term.clear()
  15.     term.setCursorPos(1,1)
  16. end
  17.  
  18. clear()
  19. local errors = false
  20. for i=1, #filelist do
  21.     local filename = filelist[i]
  22.     local fullurl = url .. filename
  23.     local localpath = '/craftbang/'..filename
  24.  
  25.     local download = http.get(fullurl)
  26.     if download then
  27.         print("Fetching "..filename)
  28.         files[localpath] = download.readAll()
  29.         download.close()
  30.     else
  31.         print("Couldn't get '"..filename .. "'.")
  32.         print "Installation failed."
  33.         return
  34.     end
  35. end
  36. sleep(1)
  37.  
  38. local installed = false
  39. if fs.exists('/craftbang') then
  40.     clear()
  41.     installed = true
  42.  
  43.     write "Overwrite current installation? [Y/n] "
  44.     local input = read():lower():sub(1,1)
  45.     if input == 'n' then
  46.         print "Will not write files."
  47.         return
  48.     end
  49.     fs.delete('/craftbang')
  50. end
  51.  
  52. clear()
  53. fs.makeDir('/craftbang')
  54. fs.makeDir('/craftbang/lib')
  55. for path, content in pairs(files) do
  56.     print("Writing "..path)
  57.     local file = fs.open(path, 'w')
  58.     file.write(content)
  59.     file.close()
  60. end
  61. print "Installation complete!"
  62. sleep(1)
  63.  
  64. if not installed then
  65.     clear()
  66.  
  67.     local startupContent = [[
  68.     shell.run("craftbang/session.lua")
  69.     ]]
  70.  
  71.     write "Run CraftBang on startup? "
  72.     if fs.exists('startup.lua') then
  73.         print "\nYour current startup file will be renamed to 'startup-old.lua'."
  74.     end
  75.     write "[Y/n] "
  76.  
  77.     local input = read():lower():sub(1,1)
  78.  
  79.     if input == 'n' then
  80.         print "In that case, run 'craftbang/session.lua' to start CraftBang."
  81.     else
  82.         if fs.exists('startup.lua') then
  83.             if fs.exists('startup-old.lua') then
  84.                 fs.delete('startup-old.lua')
  85.             end
  86.             fs.move('startup.lua','startup-old.lua')
  87.         end
  88.  
  89.         local startup = fs.open('startup.lua', 'w')
  90.         startup.write(startupContent)
  91.         startup.close()
  92.         print "CraftBang will now run on startup."
  93.     end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement