#!/usr/bin/lua

local config = require "luci.sys.config"
local sys = require "luci.sys"

local ops = arg[1]
local reader = io.popen("getfirm BACKUP_FILE_NAME", "r")
local filename = "/tmp/" .. reader:read("*l")

function usage()
	print("usage: ")
	print("    1- opsconfig backup [backup_file_path]")
	print("    2- opsconfig restore [restore_file_path]")
	print("    3- opsconfig loadisp")
	print("    4- opsconfig saveisp")
end

if ops == "backup" then
	if arg[2] ~= nil then
		filename = arg[2]
	end
	config.backup_config_file(filename)
elseif ops == "restore" then
	if arg[2] ~= nil then
		filename = arg[2]
	end
	config.restore_config_file(filename)
elseif ops == "isp_restore" then
	if arg[2] ~= nil then
		filename = arg[2]
	end
	config.isp_restore_config_file(filename)
elseif ops == "loadisp" then
	config.load_isp_config()
elseif ops == "saveisp" then
	config.save_isp_config()
else
	usage()
end
