+++ /dev/null
-include ../../build/config.mk
-include ../../build/module.mk
+++ /dev/null
-module("luci.lpk", package.seeall)
-require("luci.lpk.util")
-require("luci.lpk.core")
-
-__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
- luci.util.perror((error or "Unknown Error") .. "\n")
- luci.lpk.util.splash()
- os.exit(1)
- end
-end
-
-
-
+++ /dev/null
-module("luci.lpk.core", package.seeall)
-require("luci.util")
-
-Task = luci.util.class()
-
-function Task.__init__(self, machine, register, start)
- self.machine = machine
-
- -- The queue that has to be processed
- self.work = {start}
-
- -- The queue that has to be processed in case of rollback
- self.done = {}
-
- -- The Task register
- self.register = register
-end
-
-function Task.rollback(self)
- if #self.done < 1 then
- return false
- end
-
- local state = table.remove(self.done)
- if not state.rollback then
- return true
- end
-
- local ret, err = pcall(state.rollback, state, self.register)
-
- if ret then
- return true
- else
- return false, err
- end
-end
-
-function Task.step(self)
- local state = table.remove(self.work)
- local ret, next = pcall(state.process, self.register)
-
- if ret then
- if next then
- local nstate = self.machine:state(next)
- if nstate then
- table.insert(self.work, state)
- table.insert(self.work, nstate)
- else
- self.register.error = 2
- self.register.errstr = "Unknown state: " .. next
- return false
- end
- else
- table.insert(self.done, state)
- end
-
- return #self.work > 0
- else
- self.register.error = next
- return false
- end
-end
-
-function Task.perform(self)
- while self:step() do
- end
-
- if not self.register.error then
- return true
- else
- local stat, err
- repeat
- stat, err = self:rollback()
- until not stat
-
- if err then
- self.register.errstr = err
- self.register.error = 2
- end
-
- return false
- end
-end
-
-
-Machine = luci.util.class()
-
-function Machine.__init__(self, namespace)
- self.namespace = namespace or _NAME
-end
-
-function Machine.state(self, name)
- local ret, state = pcall(require, self.namespace .. "." .. name)
- return ret and state
-end
-
-function Machine.task(self, name, ...)
- local start = self:state(name)
-
- if type(start) ~= "table" or not start.entry then
- return false, "No such command: " .. name
- end
-
- local register = {}
-
- return start.entry(register, ...) and Task(self, register, start)
-end
+++ /dev/null
-module("luci.lpk.core.download", package.seeall)
+++ /dev/null
-module("luci.lpk.core.install", package.seeall)
-
-function entry(register, ...)
- print("Requested install of " .. table.concat(arg, ", "))
- return true
-end
-
-function process(register)
- register.sometext = "Test"
- if not register.retrieved then
- print("Step down to retrieve")
- return "retrieve"
- else
- print("Coming up again")
- end
-end
\ No newline at end of file
+++ /dev/null
-module("luci.lpk.core.retrieve", package.seeall)
-
-function process(register)
- print "Now in retrieve"
- print (register.sometext)
- register.retrieved = true
-end
\ No newline at end of file
+++ /dev/null
-module("luci.lpk.util", package.seeall)
-
-function getopt( arg, options )
- options = options or ""
- 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 ]
- arg[ k + 1 ] = ""
- end
- else
- tab[ jopt ] = true
- end
- y = y + 1
- end
- elseif #v > 0 then
- table.insert(args, v)
- end
- end
- return tab, args
-end
-
-function splash()
- require("luci.lpk")
- luci.util.perror(string.format("%s v%s\n%s",
- luci.lpk.__appname__, luci.lpk.__version__, luci.lpk.__cpyrght__))
- luci.util.perror([[
-
-Usage:
- lpk [options] <command> [arguments]
- lpk [options] install|remove pkg1 [pkg2] [...] [pkgn]
-
-Commands:
- install - Install packages
- remove - Remove packages
- purge - Remove packages and their configuration files
-
-Options:
- --force-depends - Ignore unresolvable dependencies
-]])
-end
\ No newline at end of file
+++ /dev/null
-backend.model = "ipkg"
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/lua
-require("luci.lpk")
\ No newline at end of file