jails-management/scripts/jail

48 lines
950 B
Ruby
Executable File

#!/usr/bin/env ruby
require_relative "lib/utils.rb"
require_relative "lib/jail.rb"
OPTION_PARSER = OptionParser.new do |opts|
opts.banner = "Usage: jails [options] [subcommand [options]]"
opts.separator ""
opts.separator <<HELP
Available subcommands:
add [options] NAME [ipaddress[,ipaddress,...]]: add jail
regenerate: regenerate configuration
See 'jail COMMAND --help' for more information on a specific command.
HELP
end
def usage
puts(OPTION_PARSER.help)
exit(0)
end
def main(args)
OPTION_PARSER.order!(args)
usage if args.size < 1
registry = JailRegistry.new
case command = args.shift
when "add"
name = args.first or die "name required"
registry.add(name)
when nil
usage
when "regenerate"
else
die "unknown subcommand #{command}"
end
registry.update_pf_vars
registry.update_fstabs
registry.update_jail_config
registry.update_zone
registry.update_rzone
registry.save
end
main(ARGV)