Advertisement
Second_Fry

Second_Fry's openbee modular fork install script

Jul 8th, 2016
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. --- Second_Fry's openbee modular fork (v2.0.0)
  2. --- Original code and idea by Forte40 @ GitHub (forked at v2.2.1)
  3. --- Hosted at http://pastebin.com/XxjND24H
  4.  
  5. local branch = 'master'
  6. local url = 'https://raw.github.com/secondfry/openbee/' .. branch .. '/'
  7. local filenames = {'openbee-install.lua', 'openbee.lua', 'matron.lua', 'openbee/BreederApiary.lua', 'openbee/StorageAE.lua'}
  8. local folders = {'openbee'}
  9.  
  10. term.setTextColor(colors.green)
  11. io.write('> Installing openbee\n')
  12. term.setTextColor(colors.white)
  13.  
  14. if not http then error('No access to web') end
  15.  
  16. term.setTextColor(colors.lightBlue)
  17. io.write('  Installing folders\n')
  18. term.setTextColor(colors.white)
  19. for _, folder in ipairs(folders) do
  20.   io.write('    ' .. folder .. '\n')
  21.   fs.makeDir(folder)
  22. end
  23.  
  24. term.setTextColor(colors.lightBlue)
  25. io.write('  Installing files\n')
  26. term.setTextColor(colors.white)
  27. for _, filename in ipairs(filenames) do
  28.   io.write('    ' .. filename .. ': ')
  29.  
  30.   local data, dataCurrent = '', ''
  31.   if fs.exists(filename) then
  32.     local file = fs.open(filename, "r")
  33.     dataCurrent = file.readAll()
  34.     file.close()
  35.     io.write('updating')
  36.   else
  37.     io.write('installing')
  38.   end
  39.  
  40.   local request = http.get(url .. filename)
  41.   if request == nil then error('  Request failed') end
  42.   if request.getResponseCode() == 200 then
  43.     data = request.readAll()
  44.  
  45.     if data == dataCurrent then
  46.       term.setTextColor(colors.gray)
  47.       io.write(' same file\n')
  48.       term.setTextColor(colors.white)
  49.     elseif dataCurrent == '' then
  50.       local file = fs.open(filename, "w")
  51.       file.write(data)
  52.       file.close()
  53.       term.setTextColor(colors.gray)
  54.       io.write(' success\n')
  55.       term.setTextColor(colors.white)      
  56.     else
  57.       -- TODO implement coroutines
  58.       if filename == 'openbee-install.lua' then
  59.         filename = '.' .. filename
  60.       end
  61.       local file = fs.open(filename, "w")
  62.       file.write(data)
  63.       file.close()
  64.       term.setTextColor(colors.gray)
  65.       io.write(' success\n')
  66.       term.setTextColor(colors.white)
  67.  
  68.       if filename == '.openbee-install.lua' then
  69.         term.setTextColor(colors.yellow)
  70.         io.write('  Install file updated, manual user console inputs required:\nmove .openbee-install.lua openbee-install.lua\nopenbee-install.lua\n')
  71.         term.setTextColor(colors.white)
  72.         return
  73.       end
  74.     end
  75.   else error('  Bad HTTP response code') end
  76.   os.sleep(0.1)
  77. end
  78.  
  79. term.setTextColor(colors.green)
  80. io.write('> Installation successful\n')
  81. term.setTextColor(colors.white)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement