module("luci.lpk", package.seeall)
+require("luci.lpk.util")
+require("luci.lpk.core")
-function getopt( arg, options )
- local tab = {}
- local args = {}
- for k, v in ipairs(arg) do
- if v:sub(1, 2) == "--" then
- local x = v:find( "=", 1, true )
- if x then
- tab[ v:sub( 3, x-1 ) ] = v:sub( x+1 )
- else
- tab[ v:sub( 3 ) ] = true
- end
- elseif v:sub( 1, 1 ) == "-" then
- local y = 2
- local l = #v
- local jopt
- while ( y <= l ) do
- jopt = v:sub( y, y )
- if options:find( jopt, 1, true ) then
- if y < l then
- tab[ jopt ] = v:sub( y+1 )
- y = l
- else
- tab[ jopt ] = arg[ k + 1 ]
- end
- else
- tab[ jopt ] = true
- end
- y = y + 1
+__appname__ = "LuCI »lpk« Package Manager"
+__version__ = "0.1"
+__authors__ = "Steven Barth, Jo-Philipp Wich"
+__cpyrght__ = string.format("Copyright (c) 2008 %s", __authors__)
+
+
+options, arguments = luci.lpk.util.getopt(arg)
+config = luci.util.dtable()
+machine = luci.lpk.core.Machine()
+
+local cfgdump = loadfile("/etc/lpk.conf")
+if cfgdump then
+ setfenv(cfgdump, config)
+ pcall(cfgdump)
+end
+
+if #arguments < 1 then
+ luci.lpk.util.splash()
+else
+ local task, error = machine:task(table.remove(arguments, 1),
+ unpack(arguments))
+
+ if task then
+ local stat, error = task:perform()
+ if not stat then
+ luci.util.perror(error or task.register.errstr or "Unknown Error")
+ os.exit(task.register.error or 1)
end
- else
- table.insert(args, v)
- end
- end
- return tab, args
+ else
+ luci.util.perror((error or "Unknown Error") .. "\n")
+ luci.lpk.util.splash()
+ os.exit(1)
+ end
end
+
+