Commit 25f1c465 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

control input and output directories from command line

parent 42909321
......@@ -6,19 +6,33 @@ Copyright (C) 2012 Kaarle Ritvanen
Licensed under the terms of GPL2
]]--
require 'alt_getopt'
require 'lfs'
require 'stringy'
testmode = stringy.endswith(arg[0], '/awall-cli')
short_opts = 'o:'
long_opts = {['output-dir']='o'}
if testmode then
path = string.sub(arg[0], 1, -11)
lfs.chdir(path)
if stringy.endswith(arg[0], '/awall-cli') then
basedir = string.sub(arg[0], 1, -11)
input = {basedir..'/json'}
short_opts = short_opts..'i:'
long_opts['input-dir'] = 'i'
end
for switch, value in pairs(alt_getopt.get_opts(arg, short_opts, long_opts)) do
if switch == 'i' then table.insert(input, value)
elseif switch == 'o' then
iptdir = value
ipsfile = value..'/ipset'
else assert(false) end
end
require 'awall'
awall.loadmodules(testmode and '.')
awall.loadmodules(basedir)
config = awall.Config.new(testmode and {'json', 'input'})
config = awall.Config.new(input)
config:test()
config:dump(testmode and 'output', testmode and 'output/ipset')
config:dump(iptdir, ipsfile)
......@@ -20,6 +20,9 @@ require 'awall.util'
local modules = {package.loaded['awall.model']}
function loadmodules(path)
local cdir = lfs.currentdir()
if path then lfs.chdir(path) end
for modfile in lfs.dir((path or '/usr/share/lua/5.1')..'/awall/modules') do
if stringy.endswith(modfile, '.lua') then
local name = 'awall.modules.'..string.sub(modfile, 1, -5)
......@@ -27,6 +30,8 @@ function loadmodules(path)
table.insert(modules, package.loaded[name])
end
end
lfs.chdir(cdir)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment