#!/usr/bin/python
#
# Script to add IGPEnabler=Yes for Chameleon boot loaders
#
# Copyright (C) tonymacx86 LLC

import sys
import os

vol = str(sys.argv[1])
boot = "/Extra/org.chameleon.Boot.plist"
plist = vol + boot
infile = open(plist, "r")
# check if IGPEnabler has been written or not
IGPEnablerCheck = False

body = ""

for line in infile:
    # if IGPEnabler is there, advance the next line to
    # read past it, and then add the No string
    if "<key>IGPEnabler</key>" in line:
        line = infile.next()
        line = "        <key>IGPEnabler</key>\n"
        line += "        <string>No</string>\n"
        IGPEnablerCheck = True
        
    # if we finish the tags and haven't written IGPEnabler yet
    if "</dict>" in line and IGPEnablerCheck == False:
        line = "        <key>IGPEnabler</key>\n"
        line += "        <string>No</string>\n"
        line += "</dict>\n"
        IGPEnablerCheck = True
        
    body += line
    
infile.close()

outfile = open(plist, "w")
outfile.write(body)
outfile.close()