· 6 years ago · Jul 05, 2019, 10:58 PM
1-- Program Bundler Using Pastebin
2-- *Requires internet card to run*
3local open=io.open
4local shell=require "shell"
5local exe=shell.execute --Alias for Execute
6local fs= require "filesystem"
7local export={}
8local num=1
9local folders={}
10local input = shell.parse(...)
11local progs={}
12local keyz={}
13local lib_keyz={}
14local lib_progs={}
15local apps={}
16local mode="pastebin" --Enabled by Default 10 file per 24 hour limit uplaods
17local silent=false
18-- local mode="nodebin" -- If you have a nodebin set up this is much preferred.
19-- The bundle Function Bundles your files via pastebin or private nodebin
20-- it makes a bundled script which you manually upload to pastebin
21-- so you can now pastebin run to install all of your files.
22-- this is also a great way to back up your programs forever as you
23-- only need to copy the pastebin run %YOUR CODE HERE% into safe place to save everything
24-- Free users only get 10 pastes a day so this program will not be
25-- able to bundle large programs without a pro membership (currently sold out)
26-- Because pastebin is sold out I cannot fully test/implement recursives as it
27-- will not be a feature most can use
28-- Because of this I have built a compact pastebin replacement which you can
29-- use to have unlimited ban proof uploads and downloads of raw txt.
30-- this program supports uplaod and download up files up to 1MB
31
32function export.get_mode()
33if fs.exists(shell.resolve("/etc/bundle.config")) then
34local g=open("/etc/bundle.config", "r")
35local flag=g:read(1); g:close()
36if flag == "0" then mode="pastebin" else mode="nodebin" end
37return mode
38else local g=open("/etc/bundle.config","w")
39g:write("0") g:close()
40return "pastebin"
41end
42end
43
44function export.set_mode(mode)
45local data=""
46if mode=="pastebin" then data="0" else data="1" end
47local g=open("/etc/bundle.config","w")
48g:write(data) g:close()
49return true
50end
51
52function export.upload_pb(file,directory,num)
53local name=".ftmp"..num
54local ds = file
55if directory ~= "" then ds=directory.."/"..file end
56pb="pastebin put "
57print(pb..ds.." > "..name)
58exe(pb..ds.." > "..name)
59d = io.open(name,"r") d:read(98) data=d:read(8) data2=d:read(1) d:close()
60if data2 == [["]] then return data
61else
62print("Pastebin put "..ds.." failed")
63return nil
64end -- END DATA CHECK
65end --END UPLOAD FILE FUNCTION
66
67function export.new(package_name)
68 local OLD=fs.isDirectory(shell.resolve(package_name))
69 if OLD then
70 print("The packagename exists already in this directory.\n Overwrite?... Y or N")
71 local inp=io.read()
72 if inp=="y" or inp=="Y" or inp=="yes" or inp=="YES" or inp=="Yes" then print("Removing old files ") exe("rm -r "..package_name) next_new(package_name)
73 else
74 print("Cancelling...")
75 end
76 else
77 next_new(package_name)
78 end
79end -- END FUNCTION NEW
80
81function next_new(package_name)
82 if input[2] == nil or input[2] =="" or string.len(input[2]) < 3 then decider:case()
83 print("Please use bundle new PACKAGENAME to create a new package")
84 elseif fs.isDirectory(package_name) then print("Package "..package_name.. "already exists...")
85 else
86 print("Creating new package "..package_name.."...")
87 exe("mkdir "..package_name)
88 exe("mkdir "..package_name.."/exe")
89 exe("mkdir "..package_name.."/lib")
90 local info = open(package_name.."/"..package_name..".bundle", 'w')
91 info:write("0.00"); info:close();
92 print("Please move your shell executables into "..package_name.."/exe")
93 print("Please move your custom libs for requiring into "..package_name.."/lib")
94 end
95 end -- END OF NEXT FUNCTiON
96
97function export.uploadPKG(package_name)
98mode=export.get_mode() package_mode=mode
99local nodebin
100if mode ~= "pastebin" then nodebin= require "nodebin" end
101keyz={} progs={} lib_keyz={} lib_progs={}
102if package_name ~= "" or package_name ~= nil then
103 print("Bundling package "..package_name)
104 print("<--- Gathering Executables --->")
105 local x = exe("ls "..package_name.."/exe > .exetmp")
106 local L = exe("ls "..package_name.."/lib > .libtmp")
107 if x==true then
108 for file in open(".exetmp","r"):lines() do
109 local dotx =string.sub(file,-3) print("+File Extension: "..dotx)
110 if dotx == "lua" or dotx == "txt" or dotx == "dat" or dotx == "bin" then
111 if file ~= "bundle.lua" then
112 print("> Uploading "..file)
113 local key = ""
114 if package_mode=="pastebin" then key = export.upload_pb(file,package_name.."/exe",num)
115 else key = nodebin.put(package_name.."/exe/"..file) end
116 keyz[#keyz+1]=key
117 progs[#progs+1]=file
118 num=num+1
119 else print("Ignoring .."..file)
120 end -- END OF IF is bundler.lua check
121 else
122 print("File Extension Not recognized: "..dotx)
123 end -- END OF file extension check
124 end
125 end
126 if L==true then
127 print("<--- Gathering Libraries --->")
128 for file in open(".libtmp","r"):lines() do
129 local dotx =string.sub(file,-3) print("+File Extension: "..dotx)
130 if dotx == "lua" or dotx == "txt" or dotx == "dat" or dotx == "bin" then
131 if file ~= "bundle.lua" then
132 print("> Uploading "..file)
133 local key = ""
134 if package_mode=="pastebin" then key = export.upload_pb(file,package_name.."/lib",num)
135 else key = nodebin.put(package_name.."/lib/"..file) end
136 lib_keyz[#lib_keyz+1]=key
137 lib_progs[#lib_progs+1]=file
138 num=num+1
139 else print("Ignoring .."..file)
140 end -- END OF IF is bundler.lua check
141 else
142 print("File Extension Not recognized: "..dotx)
143 end -- END OF file extension check
144 end
145end
146 else decider:case() print("Please use bundle upload PACKAGENAME")
147 end
148--os.execute("cls")
149print("===========================================================")
150print("Executables : ->")
151for z=1,#keyz do print(keyz[z].." : "..progs[z]) end
152print("===========================================================")
153print("Libraries : ->")
154for z=1,#lib_keyz do print(lib_keyz[z].." : "..lib_progs[z]) end
155cnt_total=#lib_keyz+#keyz
156print("===========================================================")
157print("Total of "..cnt_total.." files packaged and ready to deploy!")
158print("Create the installer with bundle compile MYPACKAGENAME")
159local info = open(package_name.."/"..package_name..".bundle", 'r')
160app_data = info:read(4) desc_scrape=info:read("*all") info:close()
161if app_data==nil or app_data == "" or app_data==" " then
162info = open(package_name.."/"..package_name..".bundle", 'w')
163info:write("0.00\n")
164info:write("lib ")
165for z=1,#lib_keyz do info:write(lib_keyz[z].." "..lib_progs[z].."") end
166info:write("\nexe ")
167for z=1,#keyz do info:write(keyz[z].." "..progs[z].."") end
168descz =export.get_lines(desc_scrape)
169if not descz[3] then
170print("Please enter a short description of your App :")
171print("-----------------"..package_name.."------------------")
172desc = io.read()
173else desc=descz[3]
174end
175info:write("\n"..desc)
176info:write("\n"..package_mode)
177info:close()
178else
179descz =export.get_lines(desc_scrape)
180info = open(package_name.."/"..package_name..".bundle", 'w')
181info:write((app_data+0.01).."\n")
182info:write("lib ")
183for z=1,#lib_keyz do info:write(lib_keyz[z].." "..lib_progs[z].."") end
184info:write("\nexe ")
185for z=1,#keyz do info:write(keyz[z].." "..progs[z].."") end
186if not descz[3] then
187 print(" Please enter a short description of your App ")
188 print("-----------------"..package_name.."------------------")
189 desc = io.read()
190 else desc=descz[3]
191end
192info:write("\n"..desc)
193info:write("\n"..package_mode)
194info:close()
195end
196if not app_data then app_data=0.00 end
197print("--> PREVIOUS VERSION NUMBER: "..app_data)
198print("\nAPPNAME: "..package_name)
199print("DESCRIPTION: "..desc)
200print("VERSION: "..(app_data+0.01))
201print("Bundle Mode: "..package_mode)
202end
203
204function export.get_exe_list(bundle_name)
205local g=open("/lib/bundles/"..bundle_name..".bundle","r") grab=g:read("*all") g:close()
206myline = export.get_lines(grab)
207return export.split_line(myline[3])
208end
209
210function export.get_lib_list(bundle_name)
211local g=open("/lib/bundles/"..bundle_name..".bundle","r") grab=g:read("*all") g:close()
212myline = export.get_lines(grab)
213return export.split_line(myline[2])
214end
215
216function export.get_installer(bundle_name)
217 local g=open("/lib/bundles/"..bundle_name..".bundle","r") grab=g:read("*all") g:close()
218 myline = export.get_lines(grab)
219 return myline[5]
220end
221
222function export.run_bundle(bundle_name,command)
223-- Command can equal 1 or 0, 1 is reinstall bundle, 0 is grab bundle
224if not command then command=1 end
225if fs.exists(shell.resolve("/lib/bundles/"..bundle_name..".bundle")) then
226local installer=export.get_installer(bundle_name)
227local libs=export.get_lib_list(bundle_name)
228local exes=export.get_exe_list(bundle_name)
229if command == 1 then
230local dir=bundle_name
231if installer ~= "pastebin" then
232 nodebin = require "nodebin"
233 for i=2,#libs,2 do nodebin.get(libs[i],"/lib/"..libs[i+1]) end
234 for i=2,#exes,2 do nodebin.get(exes[i],"/bin/"..exes[i+1]) end
235elseif installer ~="none" then
236 for i=2,#libs,2 do exe("pastebin get -f "..libs[i].." ".."/lib/"..libs[i+1]) end
237 for i=2,#exes,2 do exe("pastebin get -f "..exes[i].." ".."/bin/"..exes[i+1]) end
238end
239print("Finished the reinstall of "..bundle_name.." from program directory")
240else
241export.new(bundle_name)
242exe("cp /lib/bundles/"..bundle_name..".bundle "..bundle_name.."/"..bundle_name..".bundle")
243for i=3,#libs,2 do exe("cp /lib/"..libs[i].." "..bundle_name.."/lib/"..libs[i]) end
244for i=3,#exes,2 do exe("cp /bin/"..exes[i].." "..bundle_name.."/exe/"..exes[i]) end
245print("Got Bundle "..bundle_name.." from program directory")
246end
247else print("Bundle /lib/bundles/"..bundle_name..".bundle Does not exist or is corrupt") end
248end
249
250function export.help()
251 print("XooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooX")
252 print("0 Bundle Commands: 0")
253 print("XooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooX")
254 for k,v in pairs(decider) do if k ~="default" and k~="case" then print("<-:->"..tostring(k)) end end
255 end
256
257function export.create_script(package_name)
258local info=open(package_name.."/"..package_name..".bundle",'r')
259local data=info:read("*all") info:close()
260local libs={}
261local exes={}
262local rows={}
263rows =export.get_lines(data)
264local version=rows[1]
265libz =export.split_line(rows[2])
266for i=2,#libz do libs[#libs+1]=libz[i] end
267exez =export.split_line(rows[3])
268for x=2,#exez do exes[#exes+1]=exez[x] end
269if rows[5] then package_mode=rows[5] else package_mode="pastebin" end
270data=open(package_name.."/install.lua","w")
271data:write("-- "..package_name.." --\n")
272data:write("-- BUNDLED APPLICATION INSTALLER REQUIRES INTERNET TO WORK--\n")
273data:write("--00000000000000000000000000000000000000000000000000000000--\n")
274data:write([[local net=require "internet"]].."\n")
275if package_mode == "nodebin" then data:write([[local nodebin=require "nodebin"]].."\n") end
276data:write([[local open=io.open]].."\n")
277data:write([[local c = os.execute("list /lib/bundles/")]].."\n")
278data:write([[if c==true then print("Bundles directory exists...")]].."\n")
279data:write([[else os.execute("mkdir /lib/bundles/") end]].."\n")
280
281for z=1,#libs,2 do
282print(libs[z].." : "..libs[z+1])
283if package_mode == "pastebin" then data:write("\n"..[[os.execute("pastebin get -f ]]..libs[z].." /libs/"..libs[z+1]..[[")]])
284else data:write("\n"..[[nodebin.get("]]..libs[z]..[[","/lib/]]..libs[z+1]..[[")]]) end
285end
286for z=1,#exes,2 do
287print(exes[z].." : "..exes[z+1])
288if package_mode == "pastebin" then data:write("\n"..[[os.execute("pastebin get -f ]]..exes[z].." /bin/"..exes[z+1]..[[")]])
289else data:write("\n"..[[nodebin.get("]]..exes[z]..[[","/bin/]]..exes[z+1]..[[")]]) end
290end
291data:write("\n"..[[data=open("/lib/bundles/]]..package_name..[[.bundle","w")]])
292data:write("\n"..[[data:write("]]..rows[1]..[[\n")]])
293data:write("\n"..[[data:write("]]..rows[2]..[[\n")]])
294data:write("\n"..[[data:write("]]..rows[3]..[[\n")]])
295data:write("\n"..[[data:write("]]..rows[4]..[[\n")]])
296data:write("\n"..[[data:write("]]..rows[5]..[[\n")]])
297data:write("\n"..[[data:close()]])
298data:write("\n"..[[print("Successfully installed -]]..package_name..[[- Ver:]]..rows[1]..[[")]])
299data:close()
300print("Compile finished Successfully...")
301end
302
303-- This function will return a list of apps and their properties
304function export.list_installs(silent)
305local d = os.execute("list /lib/bundles/ > /etc/bundle.progs")
306if d == true then
307local dataT=open("/etc/bundle.progs",'r')
308dat = dataT:read("*all") dataT:close()
309local rows={} rows=export.get_lines(dat)
310
311for i=1,#rows do
312local newdata=open("/lib/bundles/"..rows[i],'r') qdat=newdata:read("*all") newdata:close()
313local qrows=export.get_lines(qdat)
314local qexes=export.split_line(qrows[3])
315local qlibs=export.split_line(qrows[2])
316local qinst="pastebin"
317if qrows[5] then qinst=qrows[5] end
318local qxs="" local exs=""
319for g=3,#qexes,2 do exs=exs.." "..qexes[g] end
320for g=3,#qlibs,2 do qxs=qxs.." "..qlibs[g] end
321apps[i] = {}
322apps[i].desc=qrows[4]
323apps[i].ver=qrows[1]
324apps[i].libs=qxs
325apps[i].exes=exs
326apps[i].name=string.sub(rows[i],1,#rows[i]-7)
327apps[i].installer=qinst
328if not silent then
329print("------------------------------------------")
330print(" =-=-=-=-=-"..apps[i].name.."-=-=-=-=-= ")
331print("------------------------------------------")
332print("VER: "..apps[i].ver)
333print("Exe's:"..apps[i].exes)
334print("Lib's:"..apps[i].libs)
335print("DESC: "..apps[i].desc)
336print("Installer: "..apps[i].installer)
337print("------------------------------------------")
338end
339end
340 return apps
341end
342if not silent then print("No .bundle Programs are installed on your system.") end
343 return nil
344end
345
346function export.make_alias(alias_name, exe_string)
347 if exe_string then
348 local newdata=open("/lib/bundles/"..alias_name..".bundle",'w')
349 newdata:write("1337\n")
350 newdata:write("lib\n")
351 newdata:write("exe xxxxxx "..alias_name..".lua\n")
352 newdata:write("An Alias for '"..exe_string.."'\n")
353 newdata:write("none")
354 newdata:close()
355 local newdata=open("/bin/"..alias_name..".lua",'w')
356 newdata:write([[local args=require("shell").parse(...)]].."\n")
357 newdata:write([[totalargs="" for i=1,#args do totalargs=totalargs.." "..args[i] end]].."\n")
358 newdata:write([[os.execute("]]..exe_string.." "..[["..totalargs)]])
359 newdata:close()
360 print("Alias installed as "..alias_name..".bundle")
361 else print("Unable to make Alias. Incorrect number of Arguments")
362 print("USE: bundle alias %ALIASNAME% %COMMANDNAME%")
363 end
364end
365
366function export.remove(package_name)
367if fs.exists("/lib/bundles/"..package_name..".bundle") then
368local newdata=open("/lib/bundles/"..package_name..".bundle",'r') dat=newdata:read("*all") newdata:close()
369local rows=export.get_lines(dat)
370local exes=export.split_line(rows[3])
371local libs=export.split_line(rows[2])
372for i=3,#exes,2 do print("Deleting /bin/"..exes[i]) os.execute("del /bin/"..exes[i]) end
373for i=3,#libs,2 do print("Deleting /lib/"..libs[i]) os.execute("del /lib/"..libs[i]) end
374os.execute("del /lib/bundles/"..package_name..".bundle")
375print("Uninstalled "..package_name)
376return true
377else print("The packagename /lib/bundles/"..package_name..".bundle does not exist")
378return false
379end
380end -- END of Function REMOVE
381
382function export.table_to_line(table_input)
383--v--turns a table of args[] into a space seperated string
384output=""
385for i=1,#table_input do output=output..table_input[i] end
386return output
387end-- END of Function table to line
388
389function export.get_lines(input_string)
390--v--turns all new lines into a table of args[]
391local str = input_string
392lines = {}
393for s in str:gmatch("[^\r\n]+") do
394table.insert(lines, s)
395end
396return lines
397end -- END of function get lines
398
399function export.split_line(s)
400--v--turns a space seperated string into a table of args[]
401local words = {}
402for word in string.gmatch(s, "%S+") do
403table.insert(words, word)
404end
405return words
406end-- END of function split lines
407
408function export.encode(code)
409--v--Url encodes and makes a safe url string (20- 40% enlargement of size )
410if code then
411code = string.gsub(code, "([^%w ])", function (c)
412return string.format("%%%02X", string.byte(c))
413end)
414code = string.gsub(code, " ", "+")
415end
416return code
417end-- END of function encode
418
419function export.switch(t)
420t.case = function (self,x)
421local f=self[x] or self.default
422if f then
423if type(f)=="function" then f(x,self)
424else
425error("case "..tostring(x).." not a function")
426end
427end
428end
429return t
430end
431
432decider = export.switch {
433 ["new"] = function() if input[2] ~= nil then export.new(input[2]) end end,
434 ["upload"] = function() if input[2] ~= nil then export.uploadPKG(input[2]) end end,
435 ["compile"] = function() if input[2] ~= nil then export.create_script(input[2]) end end,
436 ["install"] = function() if input[2] ~= nil then os.execute(input[2].."/install.lua") end end,
437 ["reinstall"] = function() if input[2] ~= nil then export.run_bundle(input[2],1) end end,
438 ["grab"] = function() if input[2] ~= nil then export.run_bundle(input[2],0) end end,
439 ["remove"] = function() if input[2] ~= nil then export.remove(input[2]) end end,
440 ["alias"] = function() if input[2] ~= nil then export.make_alias(input[2],input[3]) end end,
441 ["config"] = function() if input[2] ~= nil then export.set_mode(input[2]) exe("bundle config") else print("Bundler is using "..export.get_mode()) end end,
442 ["push"] = function() if input[2] ~= nil then export.uploadPKG(input[2]) export.create_script(input[2]) end end,
443 ["list"] = function() print("Listing Installed Packages..") export.list_installs() end,
444 ["help"] = function() export.help() end,
445 ["edit"] = function() if input[2] ~= nil then os.execute("edit "..input[2].."/"..input[2]..".bundle") end end,
446 default = function() print("Invalid Syntax") end,
447}
448
449if input[1] then decider:case(input[1]) end
450
451return export