diff --git a/AutoInstall/auto_install.py b/AutoInstall/auto_install.py new file mode 100644 index 0000000..87d77a3 --- /dev/null +++ b/AutoInstall/auto_install.py @@ -0,0 +1,64 @@ +import os,sys +from xml.dom import minidom +from xml.dom.ext import PrettyPrint +sys.path.append('../interface/') +sys.path.append('../new_partition/') +sys.path.append('../text/') +import ri_data +import partition_data +import interface_partition +import ri_newt + +list=['partition','raid','mountpoint'] +install_xml = '/var/install/install.xml' + +init_partition_from_os_flag = True +init_mountpoint_flag = True +init_raid_from_os = True +count=0 +while True : + if count == 0: + if init_raid_from_os: + ri_data.Raid.init_from_os() + init_raid_from_os = False + if init_partition_from_os_flag: + partition_data.Partition.init_from_os(unit='s') + init_partition_from_os_flag = False + s = interface_partition.main() + + if init_mountpoint_flag: + ri_data.MountPoint.init_from_internal() + init_mountpoint_flag = False + if len(ri_newt.Raid.init_from_internal()) < 2 and len(ri_data.Raid.dict) == 0: + if list[1] == 'raid': + del list[1] + else: + if list[1] != 'raid': + list.insert(1, 'raid') + else: + if list[count] == 'raid': + ri_newt.Raid() + elif list[count] == 'mountpoint': + ri_newt.MountPoint() + s = ri_newt.Screen.dict[list[count]].set_data() + + if int(s) == 0: + count = count + 1 + else: + count = count - 1 + + if count < 0 or count > len(list) - 1: + ri_newt.Screen.screen.finish() + break + +if s == '0': + xmldoc = minidom.parse(install_xml) + root = xmldoc.firstChild + f = file(install_xml, 'w') + partition_data.Partition.to_xml(xmldoc, root) + ri_data.Raid.to_xml(xmldoc, root) + PrettyPrint(xmldoc, f) + f.close() + os.system("python ../interface/ri_install.py") + + diff --git a/StateGrid/state_grid.py b/StateGrid/state_grid.py new file mode 100755 index 0000000..43089f3 --- /dev/null +++ b/StateGrid/state_grid.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +from snack import * +from xml.dom import minidom +from xml.dom.ext import PrettyPrint +import sys + +sys.path.append('../interface/') +sys.path.append('../text/') + +import ri_newt +import ri_data + +install_xml = '/var/install/install.xml' + +class Username(ri_newt.Screen): + def __init__(self): + ri_newt.Screen.__init__(self, name='username',title='StateGrid custom install') + ri_newt.Screen.screen.pushHelpLine(' moves; selects; activates buttons') + + self.text = 'This username will use as State Grid user. Can not be a system user or reserver user. Please enter username:' + ri_newt.Screen.widget_textboxreflowed(80, self.text) + ri_newt.Screen.widget_buttonbar([('Continue','ok','F12')]) + + def set_data(self): + ri_newt.Screen.widget_entry(75, text='') + s = ri_newt.Screen.yesno('[!!] State Grid custom install', 1, 5, 'TextboxReflowed', 'eLabel', 'Entry', 'eLabel', 'ButtonBar') + if s == 0: + ri_data.StateGrid.username = ri_newt.Screen.entry.value() + return s + +class HomeDirectory(ri_newt.Screen): + def __init__(self): + ri_newt.Screen.__init__(self, name='home_dir',title='StateGrid custom install') + ri_newt.Screen.screen.pushHelpLine(' moves; selects; activates buttons') + + self.text = 'This directory will use as State Grid user home directory. Can not be /home/{sysadmin,netadmin,secadmin,audadmin}.\n\nPlease enter home directory:' + ri_newt.Screen.widget_textboxreflowed(80, self.text) + ri_newt.Screen.widget_buttonbar([('Continue','ok','F12')]) + + def set_data(self): + ri_newt.Screen.widget_entry(75, text='') + s = ri_newt.Screen.yesno('[!!] State Grid custom install', 1, 5, 'TextboxReflowed', 'eLabel', 'Entry', 'eLabel', 'ButtonBar') + if s == 0: + ri_data.StateGrid.home_dir = ri_newt.Screen.entry.value() + return s + +class Shell(ri_newt.Screen): + def __init__(self): + ri_newt.Screen.__init__(self, name='shell',title='StateGrid custom install') + ri_newt.Screen.screen.pushHelpLine(' moves; selects; activates buttons') + + self.text = 'This shell will use as State Grid user shell, Please enter user shell:' + ri_newt.Screen.widget_textboxreflowed(80, self.text) + ri_newt.Screen.widget_buttonbar([('Continue','ok','F12')]) + + def set_data(self): + ri_newt.Screen.widget_entry(75, text='') + s = ri_newt.Screen.yesno('[!!] State Grid custom install', 1, 5, 'TextboxReflowed', 'eLabel', 'Entry', 'eLabel', 'ButtonBar') + if s == 0: + ri_data.StateGrid.shell = ri_newt.Screen.entry.value() + +if __name__ == "__main__": + Username() + ri_newt.Screen.dict['username'].set_data() + HomeDirectory() + ri_newt.Screen.dict['home_dir'].set_data() + Shell() + ri_newt.Screen.dict['shell'].set_data() + + xmldoc = minidom.parse(install_xml) + root = xmldoc.firstChild + f = file(install_xml,'w') + ri_data.StateGrid.to_xml(xmldoc, root) + PrettyPrint(xmldoc, f) + f.close() + + ri_newt.Screen.screen.finish() + + + + + + + + diff --git a/interface/ri_data.py b/interface/ri_data.py index 7bef4f3..0debd5a 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -733,6 +733,8 @@ def init_from_xml(): Group.init_from_xml(n) elif n.nodeName == 'services': Service.init_from_xml(n) + elif n.nodeName == 'stategrid': + StateGrid.init_from_xml(n) def init_from_xml_and_os(): ''' init all classes in this module from file and os ''' @@ -768,3 +770,27 @@ def to_xml(): PrettyPrint(xmldoc, f) f.close() + +class StateGrid(): + ''' state grid custom install data ''' + username = '' + home_dir = '' + shell = '' + + @staticmethod + def init_from_xml(node): + ''' init State Grid data from xml node ''' + for k in node.attributes.keys(): + setattr(StateGrid, k, node.attributes[k].value.encode('ascii')) + + @staticmethod + def to_xml(doc, p_node): + ''' write State Grid data into xml +doc - xml document instance +p_node - xml node (parent node)''' + stgd = doc.createElement('stategrid') + for st in ('username','home_dir','shell'): + to_xml_attr(doc, stgd, StateGrid, st) + + p_node.appendChild(stgd) + diff --git a/operation/exec_finish_install.sh b/operation/exec_finish_install.sh index 5fb67e7..09f2877 100755 --- a/operation/exec_finish_install.sh +++ b/operation/exec_finish_install.sh @@ -32,67 +32,26 @@ source ./functions prep () { - local mp + for mp in /dev /proc /sys + do + mount --bind -n $mp "$TARGET$mp" + done - if [ ! -d $FINISH_INSTALL_DIR ];then - mkdir -p $FINISH_INSTALL_DIR - fi - - for mp in /dev /proc /sys - do - mount --bind -n $mp "$TARGET$mp" - done + # copy the script to $TARGET/opt + cp -r /usr/lib/new_install/operation/finish_install $TARGET/opt } -# copy the script to $TARGET/opt, and chroot execute it -exec_script () -{ - local src - local src_name - - src="$1" - src_name=$(basename $src) - cp $src "$TARGET/opt" - chroot $TARGET "/opt/$src_name" >>$DEV_LOG 2>&1 && rm -f "$TARGET/opt/$src_name" -} - - - main () { - local line - local base - local script - - prep - - while read line ;do - if [ -n "$line" ];then - cp $line $FINISH_INSTALL_DIR/ - else - break - fi - done - - # run all the script in /var/finish_install, - # execute sequence through number of script name - for script in "$FINISH_INSTALL_DIR"/*; do - base=$(basename $script | sed 's/[0-9]*//') - if [ -x "$script" ];then - info "Running $base" - exec_script $script - erv - else - warn "Unable to execute $script" - fi - done - info "Running finish install success" + prep + info "Running finish install" + /usr/bin/python finish_install.py >>$DEV_LOG 2>&1 + info "Running finish install success" [ ! -c "$LOG_FILE" ] && cp $LOG_FILE "$TARGET/var/log" [ ! -c "/var/install/install.xml" ] && cp "/var/install/install.xml" "$TARGET/var/log" [ ! -c "$DEV_LOG" ] && cp $DEV_LOG "$TARGET/var/log" || true } -FINISH_INSTALL_DIR="/var/finish_install" - +#FINISH_INSTALL_DIR="/var/finish_install" main "$@" diff --git a/operation/finish_install.py b/operation/finish_install.py new file mode 100755 index 0000000..e462227 --- /dev/null +++ b/operation/finish_install.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +# run finish_install scripts +# + +import os,sys +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 +instmode = os.system("cat /proc/cmdline | sed 's/.*instmode=\([^ ]*\).*/\1/'") +if instmode == 'StateGrid': + os.system("chroot /mnt /opt/finish_install/StateGrid/setup.sh %s %s %s" %(username, homedir, shell)) + +# run post_add scripts +os.system("chroot /mnt /opt/finish_install/99finish_install.sh") + diff --git a/operation/99finish_install.sh b/operation/finish_install/99finish_install.sh similarity index 100% rename from operation/99finish_install.sh rename to operation/finish_install/99finish_install.sh diff --git a/xml/install.xml b/xml/install.xml new file mode 100644 index 0000000..b15890f --- /dev/null +++ b/xml/install.xml @@ -0,0 +1,449 @@ + + + 0123456789 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +