Shinmaru
エロルアー Scripter!
A Discussion on thoughts about a Package System for TFS(all in Lua).
I have always thought of making something simple for TFS and that is an easy way to install scripts to a server.
This is an example code, on how it should look, btw this was inspired by an user here that made his system self install into the server and by Arch Linux's AUR.
Warning: This is a Unix-only script it will not work on Windows.(I don't plan to make it for Windows.)
INSTALL script:
Repository Table
INSTALL Library (Still not complete)
I need someone that knows better Lua than me to look at this and tell me if I'm doing it right, because I'm not testing it.
All instructions goes into "INSTALL" function.
Added Repo and change the main Install libraries.(using Luarocks and LuaFileSystem)
Tell me what you guys think? it will have libraries to handle most actions with ease.
I have always thought of making something simple for TFS and that is an easy way to install scripts to a server.
This is an example code, on how it should look, btw this was inspired by an user here that made his system self install into the server and by Arch Linux's AUR.
Warning: This is a Unix-only script it will not work on Windows.(I don't plan to make it for Windows.)
INSTALL script:
Code:
local PKG = {
USER = "Shinmaru",
NAME = "Install Library",
VERSION = "1.0",
EMAIL = "",
LICENSE = "",
DISCLAIMER = "",
URL = 'http://myhost.com',
FILE = '/install_libs.tar.gz',
INSTALLFILE = "/TFS_Package_System.install",
GET = function()
require "luasocket"
c = assert(socket.connect(PKG.URL, 80))
c:send("GET " ..PKG.FILE.. " HTTP/1.0\r\n\r\n")
c:close()
end,
INSTALL = function()
-- Install instructions go here.
end,
REMOVE = function()
-- Remove instructions go here.
end
}
dofile("repo.lua")
if REPO[PKG.NAME][1] ~= "standby-installed" and REPO[PKG.NAME][1] == "install" then
PKG.GET()
PKG.INSTALL()
elseif REPO[PKG.NAME][1] == "remove" then
PKG.REMOVE()
end
Repository Table
Code:
--[[
REPO Information.
States:
install, remove, standby and standby-installed
Descriptions:
install = Will automatically install on next server startup.
remove = Will automatically remove on next server startup.
standby = Awaits command to install or remove.
standby-installed = Installed package state.
State Changes:
install > standby-installed
remove > standby
standby remains standby untill issued the install command, which will turn to standby-installed.
standby-installed > standby
]]--
REPO = {
["Package Name"] = {"install", "http://HOSTNAME.net/PACKAGE_NAME/PACKAGE.INSTALL"}
}
INSTALL Library (Still not complete)
Code:
if os.execute("[ -z \"/usr/bin/luarocks\" ]") ~= 0 then
os.execute("wget \"http://luarocks.org/releases/luarocks-2.0.11.tar.gz\" && tar -xzf luarocks-2.0.11.tar.gz && cd luarocks-2.0.11/ && sh configure && make && su -c \"make install\" && echo \"LuaRocks installed.\"")
if os.execute("[ -z \"/usr/lib/lua/5.1/lfs.so\" ]") ~= 0 then
os.execute("[ `su -c \"luarocks install luafilesystem && ln -s /usr/local/lua/5.1/lfs.so /usr/lib/lua/5.1/lfs.so\" ] || printf \">> Error installing or linking .so file.\"")
end
end
lfs = require "lfs"
fs = {
Exist = function(path)
return (os.execute("[ -d " .. path .. " ] || [ -f " .. path .. " ]") == 0 and true or false)
end,
Dir = function(path)
path = (path ~= nil and lfs.dir(path) or lfs.dir(lfs.currentdir()))
for file in path do
if file ~= "." and ".." then
local mode = (lfs.attributes(path..'/'..file, "mode")
print(file.." >> "..mode)
end
end
end,
DirSearch = function(search, path)
path = (path ~= nil and lfs.dir(path) or lfs.dir(lfs.currentdir()))
for file in path do
if search == file then
print("Found ".. lfs.attributes(path..'/'..file, "mode").. " \""..file.."\".")
return true
end
end
end,
Write = {
Tag = function(file, tag, comment, tagClose) -- Credits to Wake's Libraries.
local f = io.open(file, "r")
local content = f:read("*all")
local content, _ = content:gsub(tagClose, tag .. "<!-- " .. comment .. " -->\n" .. tagClose)
f:close()
local fi = io.open(file, "w+")
fi:write(content)
fi:close()
return true
end,
Content = function(file, content)
-- TODO
end
},
Remove = function(path)
if os.execute(" [ -d \""..path.."\" ]") == 0 then
lfs.rmdir(path)
return true
elseif os.execute(" [ -f \""..path.."\" ]") == 0 then
os.execute("rm \""..path.."\"")
return true
end
return false
end,
Create = function(file, content, overwrite)
if fs.Exist(file) then
if content ~= nil then
if overwrite == true then
os.execute("echo -e " .. content .. " > " .. file)
end
end
elseif content ~= nil then
os.execute("echo -e " .. content .. " > " .. file)
else
os.execute("echo > "..file)
end
end,
Move = function(Ifile, Ofile)
return os.execute("mv "..Ifile.." "..Ofile)
end,
Copy = function(Ifile, Ofile, recursive)
return os.execute("cp "..(recursive == true and "-R " or "") and Ifile.." "..Ofile)
end,
Wget = function(url)
os.execute("wget \""..url.."\"")
end,
Tar = function(file, parameters)
os.execute("tar "..parameters.." "..file)
end
}
function repo(arg, package) -- TODO
if isInArray({"install", "-i"}, arg) then
fs.Wget(REPO[package][2])
dofile(package..".install")
end
end
if fs.DirSearch("repo.lua") == true then
dofile("repo.lua")
for i = 1, #REPO do
if REPO[1] == "install" then
fs.Wget(REPO[2])
dofile(REPO..".install")
elseif REPO[1] == "remove" then
fs.Wget(REPO[2])
dofile(REPO..".install")
end
end
end
All instructions goes into "INSTALL" function.
Added Repo and change the main Install libraries.(using Luarocks and LuaFileSystem)
Tell me what you guys think? it will have libraries to handle most actions with ease.
Last edited: