#!/usr/bin/env python

# run finish_install scripts
#

import os,sys,re
sys.path.append('../interface')
import ri_data

# get data from install.xml
ri_data.init_from_xml()
username = ri_data.StateGrid.username
homedir = ri_data.StateGrid.home_dir
shell = ri_data.StateGrid.shell

# run state grid custom scripts
#f = open('/proc/cmdline', 'r')
#cmdline = f.readline().strip()
#f.close()
#for i in cmdline.split(' '):
#    if re.match('instmode=',i):
#        instmode = i.split('=')[1]
#        break
try:
    instmode = os.environ["instmode"]
except:
	instmode = 'Text'
if instmode == 'StateGrid':
	os.system("cp -r /usr/lib/StateGrid /mnt/opt/")
	os.system("chroot /mnt /opt/StateGrid/setup.sh  %s %s %s" %(username, homedir, shell))
	os.system("rm -rf /mnt/opt/StateGrid")

