Skip to content

Commit

Permalink
Malboxes.py: works on windows natively now. Might have problem with t…
Browse files Browse the repository at this point in the history
…he WinPcap package.
  • Loading branch information
Svieg committed May 23, 2016
1 parent 58f0dff commit 13b2e4f
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions malboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import sys

from jinja2 import Environment, FileSystemLoader
# from sh import packer_io

CONFIG_CACHE = 'config_cache/'
CONFIG_CACHE = 'config_cache'


def initialize():
Expand Down Expand Up @@ -123,6 +122,7 @@ def prepare_autounattend(config):
# os type is extracted from profile json
os_type = config['builders'][0]['guest_os_type'].lower()

# Jinja2 splits on '/' so dont change for os.path.join
env = Environment(loader=FileSystemLoader('installconfig/'))
template = env.get_template("{}/Autounattend.xml".format(os_type))
f = create_configfd('Autounattend.xml')
Expand All @@ -134,7 +134,7 @@ def load_config(profile):
"""
Config is in JSON since we can re-use the same in both malboxes and packer
"""
profile_file = 'profiles/{}.json'.format(profile)
profile_file = os.path.join('profiles','{}.json'.format(profile))
# validate if profile is present
if not os.path.isfile(profile_file):
print("Profile doesn't exist")
Expand Down Expand Up @@ -192,7 +192,7 @@ def run_packer(packer_config):
print("Starting packer to generate the VM")
print("----------------------------------")

cmd = ['packer-io', 'build', '-var-file=config.json', packer_config]
cmd = ['packer', 'build', '-var-file=config.json', packer_config]
ret = run_foreground(cmd)

print("----------------------------------")
Expand Down Expand Up @@ -224,8 +224,8 @@ def default(parser, args):

def list_profiles(parser, args):
print("supported profiles:\n")
for f in sorted(glob.glob('profiles/*.json')):
m = re.search(r'^profiles\/(.*).json$', f)
for f in sorted(glob.glob(os.path.join('profiles','*.json'))):
m = re.search(r'^profiles[\/\\](.*).json$', f)
print(m.group(1))
print()

Expand All @@ -236,7 +236,7 @@ def build(parser, args):
print("Generating configuration files...")
prepare_autounattend(config)
print("Configuration files are ready")
ret = run_packer('profiles/{}.json'.format(args.profile))
ret = run_packer(os.path.join('profiles','{}.json'.format(args.profile)))
if ret != 0:
print("Packer failed. Build failed. Exiting...")
sys.exit(3)
Expand All @@ -259,7 +259,7 @@ def spin(parser, args):
config = load_config(args.profile)

print("Creating a Vagrantfile")
env = Environment(loader=FileSystemLoader('vagrantfiles/'))
env = Environment(loader=FileSystemLoader('vagrantfiles'))
template = env.get_template("analyst_single.rb")

if os.path.isfile('Vagrantfile'):
Expand Down Expand Up @@ -298,7 +298,7 @@ def reg(parser, args):
print("Registry modification type invalid.")
print("Valid ones are: add, delete and modify.")

filename = "scripts/windows/{}.ps1".format(args.profile)
filename = os.path.join("scripts","windows", "{}.ps1".format(args.profile))
f = open(filename, "a")
f.write(line)
f.close()
Expand All @@ -309,7 +309,7 @@ def reg(parser, args):
""" If the script is not already in the profile."""
if filename not in provisioners_list:
provisioners_list.append(fiString)
f = open("profiles/{}.json".format(args.profile), "w")
f = open(os.path.join("profiles","{}.json".format(args.profile)), "w")
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
f.close()

Expand All @@ -329,7 +329,7 @@ def directory(parser, args):
print("Directory modification type invalid.")
print("Valid ones are: add, delete.")

filename = "scripts/windows/{}.ps1".format(args.profile)
filename = os.path.join("scripts","windows","{}.ps1".format(args.profile))
f = open(filename, "a")
f.write(line)
f.close()
Expand All @@ -340,15 +340,15 @@ def directory(parser, args):
""" If the script is not already in the profile."""
if filename not in provisioners_list:
provisioners_list.append(filename)
f = open("profiles/{}.json".format(args.profile), "w")
f = open(os.path.join("profiles","{}.json".format(args.profile)), "w")
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
f.close()

def package(parser, args):
""" Adds a package to install with Chocolatey."""
line = "cinst {} -y\r\n".format(args.package)
print("Adding Chocolatey package: {}".format(args.package))
filename = "scripts/windows/{}.ps1".format(args.profile)
filename = os.path.join("scripts","windows","{}.ps1".format(args.profile))
f = open(filename, "a")
f.write(line)
f.close()
Expand All @@ -359,7 +359,7 @@ def package(parser, args):
""" If the script is not already in the profile."""
if filename not in provisioners_list:
provisioners_list.append(filename)
f = open("profiles/{}.json".format(args.profile), "w")
f = open(os.path.join("profiles","{}.json".format(args.profile)), "w")
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
f.close()

Expand All @@ -378,7 +378,7 @@ def document(parser, args):
print("Directory modification type invalid.")
print("Valid ones are: add, delete.")

filename = "scripts/windows/{}.ps1".format(args.profile)
filename = os.path.join("scripts","windows","{}.ps1".format(args.profile))
f = open(filename, "a")
f.write(line)
f.close()
Expand All @@ -389,7 +389,7 @@ def document(parser, args):
""" If the script is not already in the profile."""
if filename not in provisioners_list:
provisioners_list.append(filename)
f = open("profiles/{}.json".format(args.profile), "w")
f = open(os.path.join("profiles","{}.json".format(args.profile)), "w")
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
f.close()

Expand Down

0 comments on commit 13b2e4f

Please sign in to comment.