import sys
import os
from os.path import join as buildpath
from pentest import __version__
from pentest.parser import JarvisParser
from pentest.manager import JarvisManager


def main(args=None):
	"""
	Main entry point for Jarvis

	Creates a user-level .jarvis directory for managing a couple of configuration
	options
	"""
	if not os.path.isfile("/etc/jarvis.conf"):
		print("[!] File /etc/jarvis.conf does not exist, please create it")
		print("Sample configuration file below, please make sure the pentest_history file will be writable by Jarvis users")
		print()
		print("[jarvis]")
		print("pentests_history = /home/marauder/.pentests_history")
		print("user_directory = user")
		print("output_directory = records")
		print("pentest_tree = [")
		print('	"%(user_directory)s",')
		print('	"%(user_directory)s/img",')
		print('	"%(user_directory)s/scripts",')
		print('	"%(user_directory)s/records"')
		print("	]")
		print("notesfiles = notes.txt")
		print("interface = eth0")
		print("editor = vim")

		sys.exit(0)

	manager = JarvisManager()

	# Execute user-supplied action
	args = manager.parser.parse_args()
	if args.command == "start":
		manager.start(args.directory)

	if manager.current:
		if args.command == "edit":
			manager.edit(args.image)
		elif args.command == "stop":
			manager.stop()
		elif args.command == "init":
			manager.init()
		elif args.command == "screenshot":
			manager.screenshot()
		elif args.command == "notes":
			manager.notes()
		elif args.command == "img":
			manager.img()
		elif args.command == "hooks":
			manager.hooks()
	else:
		print("[!] Create a pentest directory first")


if __name__ == "__main__":
	main()
