Hbomb_79

Titanium Developer Tools - Install

Nov 3rd, 2016
1,287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[   Titanium Developer Tools   ]]--
  2. --[[       TPM/TDT/package        ]]--
  3. --[[                              ]]--
  4. --[[    Harry Felton (hbomb79)    ]]--
  5.  
  6. --[[ Init ]]--
  7. if not http then
  8.     error "This program requires the HTTP API be loaded. Please load the HTTP API to continue (this maybe a problem with your CC configuration)"
  9. end
  10.  
  11. local isColour = term.isColour()
  12. local function out( text, colour, same )
  13.     term.setTextColour( isColour and colour or 1 )
  14.  
  15.     if same then write( text ) else print( text ) end
  16. end
  17.  
  18. if fs.exists "/.tpm" then
  19.     out("Previous Installation Detected!\n\nFiles inside of /.tpm may be overwritten during installation.\n\nThis could remove TPM installations and/or previous TDT projects. Do you wish to continue? ", colours.red, true)
  20.     out("(Y/n)", colours.blue)
  21.     while true do
  22.         local k = select( 2, os.pullEvent "key" )
  23.         os.pullEvent()
  24.         if k == keys.y then break elseif k == keys.n then out("Aborting", colours.orange) return end
  25.     end
  26. end
  27.  
  28. local fetched = {}
  29. local function fetch( url, name )
  30.     local handle = http.get( url )
  31.     if handle then
  32.         out( "Success", colours.green )
  33.         table.insert( fetched, { handle, url:match "/(%w+)[^/]*/?$" } )
  34.     else
  35.         error( "Failed to fetch '"..url.."', http GET failed. Ensure you have internet connection, otherwise try again later" )
  36.     end
  37. end
  38.  
  39. local function save()
  40.     for i = 1, #fetched do
  41.         local handle = fetched[ i ][ 1 ]
  42.         local f = fs.open( ("/.tpm/bin/%s"):format( fetched[ i ][ 2 ] ), "w" )
  43.         f.write( handle.readAll() )
  44.         f.close()
  45.  
  46.         handle.close()
  47.     end
  48. end
  49.  
  50. --[[ Download ]]--
  51. out( "\nStarting install", colours.purple )
  52. out( "Fetching Titanium Package Manager (TPM)... ", colours.blue, true )
  53. fetch "https://gitlab.com/hbomb79/Titanium-Package-Manager/raw/master/tpm"
  54.  
  55. out( "Fetching Titanium Developer Tools (TDT)... ", colours.blue, true )
  56. fetch "https://gitlab.com/hbomb79/Titanium-Package-Manager/raw/master/tdt"
  57.  
  58. out( "Fetching Titanium Packager... ", colours.blue, true )
  59. fetch "https://gitlab.com/hbomb79/Titanium/raw/develop/bin/package.lua"
  60.  
  61. --[[ Installation ]]--
  62. fs.makeDir "/.tpm"
  63. fs.makeDir "/.tpm/packages"
  64. fs.makeDir "/.tpm/bin"
  65.  
  66. fs.open("/.tpm/tpm.cfg", "w").close()
  67.  
  68. save()
  69.  
  70. --[[ Configuration ]]--
  71.  
  72. shell.setPath( shell.path() .. ":/.tpm/bin" )
  73.  
  74. out( "\nWould you like to patch your startup file so that '/.tpm/bin' is added to your PATH. This will allow you to use the developer commands without using the full paths? ", colours.orange, true )
  75. out("(Y/n)", colours.blue)
  76. while true do
  77.     local _, k = os.pullEvent "key"
  78.     os.pullEvent()
  79.     if k == keys.y then
  80.         local ok, err = loadfile( "/.tpm/bin/tpm" )
  81.         if ok then
  82.             ok "patch"
  83.             break
  84.         else
  85.             error("Failed to load TPM. Error: " .. tostring( err ))
  86.         end
  87.     elseif k == keys.n then break end
  88. end
  89.  
  90. out("\nPatch your startup file at anytime using 'tpm patch'", colours.lightBlue)
  91. out( "Installation complete", colours.green )
RAW Paste Data