From 3c0236842ada1af474d145098efbc63c373aa09e Mon Sep 17 00:00:00 2001 From: Peng Zhihui Date: Fri, 20 Dec 2013 11:10:32 +0800 Subject: [PATCH] rewrite text isntall interface and partition-tool modified: dialog/di_dialog.py modified: dialog/di_main.py new file: dialog/di_newt.py modified: interface/ri_inst_cli.py modified: interface/ri_oper.py new file: new_partition/finddisk.sh new file: new_partition/list-devices new file: new_partition/new_partition.py new file: new_partition/parted_devices new file: new_partition/parted_devices.py modified: operation/configure_bootloader_cnf.sh modified: operation/copy_kernels.sh modified: operation/install_bootloader.sh modified: xml/config.xml modified: xml/dependency.xml --- dialog/di_dialog.py | 4 - dialog/di_main.py | 61 ++- dialog/di_newt.py | 680 ++++++++++++++++++++++++++ interface/ri_inst_cli.py | 4 +- interface/ri_oper.py | 19 +- new_partition/finddisk.sh | 95 ++++ new_partition/list-devices | 170 +++++++ new_partition/new_partition.py | 558 +++++++++++++++++++++ new_partition/parted_devices | Bin 0 -> 10357 bytes new_partition/parted_devices.py | 38 ++ operation/configure_bootloader_cnf.sh | 9 + operation/copy_kernels.sh | 36 +- operation/install_bootloader.sh | 28 ++ xml/config.xml | 7 +- xml/dependency.xml | 3 +- 15 files changed, 1663 insertions(+), 49 deletions(-) create mode 100644 dialog/di_newt.py create mode 100755 new_partition/finddisk.sh create mode 100755 new_partition/list-devices create mode 100755 new_partition/new_partition.py create mode 100755 new_partition/parted_devices create mode 100755 new_partition/parted_devices.py diff --git a/dialog/di_dialog.py b/dialog/di_dialog.py index 2f0504c..eb2ee62 100644 --- a/dialog/di_dialog.py +++ b/dialog/di_dialog.py @@ -248,10 +248,6 @@ class MountPoint(Dialog): ri_data.MountPoint.get_size(d)+ ri_data.Partition.unit)) - if len(list) == 0: - Dialog.message("Sorry, your hard disk has no partitions,Please partition your disk first!!") - sys.exit(1) - exit_info,string=Dialog.dialog.menu(text="There are five columns in the mount point display frame.\n Device Mountpoint Filesystem Format Size", height=self.height,width=self.width,menu_height=(len(list) > self.height and self.height - 2 or len(list) ), choices=list,title='Mount',ok_label='edit',help_button=1,help_label='Next',clear=1) diff --git a/dialog/di_main.py b/dialog/di_main.py index 560be1c..fa98cc1 100644 --- a/dialog/di_main.py +++ b/dialog/di_main.py @@ -3,34 +3,51 @@ import sys sys.path.append('../interface/') import ri_data import di_dialog +import di_newt -di_dialog.Welcome(30,70) -di_dialog.Raid(30,70) -di_dialog.MountPoint(30,70) -di_dialog.SerialNumber(10,50) -di_dialog.Network(10,50) -di_dialog.Group(30,70) -di_dialog.Service(25,50) -di_dialog.Prepar_installation(40,100) - -list=['welcome','raid','mountpoint','serialnumber','network','group','service','information'] - -ri_data.init() -if len(di_dialog.Raid.raid_raw_init()) < 2: - del list[1] +list=['welcome','partition','raid','mountpoint','serialnumber','network','group','service','information'] count=0 while True : - s = di_dialog.Dialog.dict[list[count]].set_data() - if int(s) == 0: - count = count + 1 - else: - count = count - 1 + if count == 1: + s = os.system("python ../new_partition/new_partition.py") - if count < 0 or count > len(list) - 1: - break + ri_data.init() + if len(di_newt.Raid.raid_raw_init()) < 2: + if list[2] == 'raid': + del list[2] + else: + if list[2] != 'raid': + list.insert(2, 'raid') + else: + if list[count] == 'welcome': + di_newt.Welcome() + elif list[count] == 'raid': + di_newt.Raid() + elif list[count] == 'mountpoint': + di_newt.MountPoint() + elif list[count] == 'serialnumber': + di_newt.SerialNumber() + elif list[count] == 'network': + di_newt.Network() + elif list[count] == 'group': + di_newt.Group() + elif list[count] == 'service': + di_newt.Service() + elif list[count] == 'information': + di_newt.Prepar_installation() + s = di_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: + di_newt.Screen.screen.finish() + break if s == 0: - os.system("python ../interface/ri_install.py") + os.system("python ../interface/ri_install.py") diff --git a/dialog/di_newt.py b/dialog/di_newt.py new file mode 100644 index 0000000..ff3dc84 --- /dev/null +++ b/dialog/di_newt.py @@ -0,0 +1,680 @@ +#!/usr/bin/env python +from snack import * +import sys +import re +import time +sys.path.append('../interface/') + +import ri_data + +config_xml = "../xml/config.xml" + +class Screen: + global screen + #global dict + dict = {} + d_cbl = {} + def __init__(self, name='screen', title='Welcome to Rocky Security OS', helpline='', text=''): + Screen.screen = SnackScreen() + Screen.screen.drawRootText(0, 0, title) + helpline='/ between elments | selects | Next | OK/Edit/Install' + Screen.screen.pushHelpLine(helpline) + Screen.dict[name] = self + Screen.buttonlist1 = [('OK','ok','F12'),('Cancel','cancel')] + Screen.buttonlist2 = [('OK','ok','F12'),('Cancel','cancel'),('Next','next','F5')] + Screen.buttonlist3 = [('Edit','ok','F12'),('Cancel','cancel'),('Next','next','F5')] + Screen.buttonlist4 = [('Install','ok','F12'),('Back','cancel')] + + @staticmethod + def container_gridform(gridtitle, gridx, gridy): + Screen.gridform = GridForm(Screen.screen, gridtitle, gridy, gridx) + + @staticmethod + def container_grid(x, y, *widget): + Screen.grid = Grid(y, x) + row = 0 + for w in widget: + Screen.grid.setField(w, 0, row) + row = row + 1 + + @staticmethod + def container_grid_complex(x, y, *widget): + Screen.grid_complex = Grid(y, x) + row = 0 + col = 0 + for w in widget: + Screen.grid_complex.setField(w, col, row ) + if col < y-1: + col = col + 1 + else: + row = row + 1 + col = 0 + + @staticmethod + def widget_textboxreflowed(width, text): + Screen.textboxreflowed = TextboxReflowed(width, text) + + @staticmethod + def widget_textbox(width, height, text): + Screen.textbox = Textbox(width, height, text, scroll=1, wrap=1) + + @staticmethod + def widget_clistbox(list_col_widths, list_col_labels, list_col_label_align, h=0): + w = 0 + for i in list_col_widths: + w = w + i + 2 + c = len(list_col_widths) + + Screen.clistbox = CListbox(height=h, cols=c, + col_widths = list_col_widths, + scroll=1, returnExit =1, + width=w, col_pad=2, + col_labels = list_col_labels, + col_label_align=list_col_label_align) + + @staticmethod + def widget_buttonbar(*buttonlist): + Screen.bb = ButtonBar(Screen.screen, *buttonlist) + + @staticmethod + def widget_checkboxlist(li_item): + Screen.d_cbl = {} + for item in li_item: + Screen.d_cbl[item] = Checkbox(item) + + @staticmethod + def widget_label(string): + Screen.label = Label(string) + + @staticmethod + def widget_entry(width, text=''): + Screen.entry = Entry(width, text) + + @staticmethod + def widget_listbox(h, *lis): + Screen.listbox = Listbox(height=h, scroll=1) + for i in lis: + Screen.listbox.append(i, i) + + @staticmethod + def initial_static_net(): + Screen.label_hostname = Label(' hostname: ') + Screen.entry_hostname = Entry(20, getattr(ri_data.Network, 'hostname')) + Screen.grid_hostname = Grid(2,1) + Screen.grid_hostname.setField(Screen.label_hostname, 0, 0) + Screen.grid_hostname.setField(Screen.entry_hostname, 1, 0) + + Screen.label_domain = Label(' domain: ') + Screen.entry_domain = Entry(20, getattr(ri_data.Network, 'domain')) + Screen.grid_domain = Grid(2,1) + Screen.grid_domain.setField(Screen.label_domain, 0, 0) + Screen.grid_domain.setField(Screen.entry_domain, 1, 0) + + Screen.label_ip = Label(' ip: ') + Screen.entry_ip = Entry(20, getattr(ri_data.Network, 'ip')) + Screen.grid_ip = Grid(2,1) + Screen.grid_ip.setField(Screen.label_ip, 0, 0) + Screen.grid_ip.setField(Screen.entry_ip, 1, 0) + + Screen.label_netmask = Label(' netmask: ') + Screen.entry_netmask = Entry(20, getattr(ri_data.Network, 'mask')) + Screen.grid_netmask = Grid(2,1) + Screen.grid_netmask.setField(Screen.label_netmask, 0, 0) + Screen.grid_netmask.setField(Screen.entry_netmask, 1, 0) + + Screen.label_gateway = Label(' gateway: ') + Screen.entry_gateway = Entry(20, getattr(ri_data.Network, 'gateway')) + Screen.grid_gateway = Grid(2,1) + Screen.grid_gateway.setField(Screen.label_gateway, 0, 0) + Screen.grid_gateway.setField(Screen.entry_gateway, 1, 0) + + Screen.label_primary_dns = Label('primary_dns: ') + Screen.entry_primary_dns = Entry(20, getattr(ri_data.Network, 'primary_dns')) + Screen.grid_primary_dns = Grid(2,1) + Screen.grid_primary_dns.setField(Screen.label_primary_dns, 0, 0) + Screen.grid_primary_dns.setField(Screen.entry_primary_dns, 1, 0) + + @staticmethod + def yesno(gridtitle, gridx, gridy, *widget): + Screen.form = Form() + Screen.container_gridform(gridtitle, gridy, gridx) + count = 0 + for i in widget: + if i == 'TextboxReflowed': + Screen.gridform.add(Screen.textboxreflowed, 0, count) + count = count + 1 + elif i == 'Textbox': + Screen.gridform.add(Screen.textbox, 0, count) + count = count + 1 + elif i == 'Entry': + Screen.gridform.add(Screen.entry, 0, count) + count = count + 1 + elif i == 'eLabel': + Screen.gridform.add(Label(""), 0, count) + count = count + 1 + elif i == "ButtonBar": + Screen.gridform.add(Screen.bb, 0, count) + count = count + 1 + elif i == "Label": + Screen.gridform.add(Screen.label, 0, count) + count = count + 1 + elif i == 'Listbox': + Screen.gridform.add(Screen.listbox, 0, count) + count = count + 1 + elif i == 'CListbox': + Screen.gridform.add(Screen.clistbox, 0, count) + count = count + 1 + elif i == 'CheckboxList': + for i in Screen.d_cbl: + Screen.gridform.add(Screen.d_cbl[i], 0, count, padding=(13,0,0,0), anchorLeft=1) + count = count + 1 + elif i == 'Grid': + Screen.gridform.add(Screen.grid, 0, count) + count = count + 1 + elif i == 'Grid_Complex': + Screen.gridform.add(Screen.grid_complex, 0, count) + count = count + 1 + + Screen.form.add(Screen.gridform) + Screen.screen.gridWrappedWindow(Screen.gridform, gridtitle) + Screen.form.addHotKey("F12") + res = Screen.form.run() + Screen.screen.popWindow() + #res = Screen.gridform.runOnce() + if Screen.bb.buttonPressed(res) == "ok": + s = 0 + elif Screen.bb.buttonPressed(res) == "cancel": + s = -1 + elif Screen.bb.buttonPressed(res) == "next": + s = 'help' + if locals().has_key('s'): + return s + + @staticmethod + def pop_window(title, text): + Screen.p_window = GridForm(Screen.screen, title, 1, 2) + Screen.p_window.add(TextboxReflowed(30, text),0,0) + Screen.p_window.add(Button('OK'),0,1) + Screen.p_window.runOnce() + + + +class Welcome(Screen): + #def __init__(self, helpline='/ between elments | selects | Next | OK'): + def __init__(self): + Screen.__init__(self, name='welcome') + #Screen.screen.pushHelpLine(Screen.helpline) + + self.text = 'Welcome!\n\nThis script will guide you through the installation of RSS packages.\n\nIf you want to install the system, then please continue, else abort the installation and come back later.\n\nAre you really sure you want to continue?' + Screen.widget_textboxreflowed(50, self.text) + Screen.widget_buttonbar(Screen.buttonlist1) + + def set_data(self): + s = Screen.yesno('welcome', 1, 3, 'TextboxReflowed', 'eLabel', 'ButtonBar') + return s + +class SerialNumber(Screen): + def __init__(self): + Screen.__init__(self, name='serialnumber') + + self.text = 'please input a serial number' + Screen.widget_textboxreflowed(50, self.text) + Screen.widget_buttonbar(Screen.buttonlist1) + + def set_data(self): + Screen.widget_entry(20, text=getattr(ri_data.SerialNumber,'value')) + s = Screen.yesno('serialnumber', 1, 4, 'TextboxReflowed', 'Entry', 'eLabel', 'ButtonBar') + if s == 0: + ri_data.SerialNumber.value = Screen.entry.value() + return s + +class Raid(Screen): + def __init__(self): + Screen.__init__(self, name='raid') + self.title = 'Making Raid devices' + + @staticmethod + def raid_raw_init(): + ''' initialize raid raw devices (parttion with id 'fd' ''' + # get all component devices already in raid + dev_in_raid = ri_data.Raid.dev_in_raid() + + raw_devs = [ d for d in ri_data.Partition.dict.keys() + if re.search('raid', ri_data.Partition.dict[d].flags) and d not in dev_in_raid ] + raw_devs.sort() + return raw_devs + + def raid_raw_map(self): + list=[] + fd=Raid.raid_raw_init() + for d in fd: + list.append((d,'','off')) + return list + + def raid_raw_to_active(self,level,dname): + list=self.raid_raw_map() + actives = [] + + if not list: + return 0 + + list_cb = [] + for i in list: + list_cb.append(i[0]) + + Screen.widget_checkboxlist(list_cb) + + num_widget = len(list) + 4 + + Screen.widget_buttonbar(Screen.buttonlist1) + Screen.widget_textboxreflowed(47, 'Please select the active fd') + while True: + s = Screen.yesno(self.title, 1, num_widget, 'TextboxReflowed', 'eLabel', 'CheckboxList', 'eLabel', 'ButtonBar') + + if s == 0: + actives = [] + for i in list: + if Screen.d_cbl[i[0]].value() == 1: + actives.append(i[0]) + if int(level) < 2 and len(actives) < 2 : + #ButtonChoiceWindow(Screen.screen, 'Warning', 'Making a raid0 or raid1 needs two or more partitions.') + Screen.pop_window('Tips', 'Making a raid0 or raid1 needs two or more partitions.') + elif int(level) == 5 and len(actives) < 3: + ButtonChoiceWindow(Screen.screen, 'Warning', 'Making a raid5 needs three or more partitions.') + else: + #(dev, from_os, level, a_devs, s_devs=[]): + if dname not in ri_data.Raid.dict.keys(): + ri_data.Raid(dname,'no',level,actives,[]) + else: + #print 'get_next_name error in active?' + #print dname + ri_data.Raid.dict[dname].active_components=actives + break + else: + return s + return s + + def raid_raw_to_spare(self,level,dname): + if dname not in ri_data.Raid.dict.keys(): + return + + list=self.raid_raw_map() + if not list: + return 0 + + Screen.d_cbl = {} + for i in list: + Screen.d_cbl[i[0]] = Checkbox(i[0]) + + num_widget = len(list) + 4 + + Screen.widget_textboxreflowed(47, 'Please select the spare fd') + Screen.widget_buttonbar(Screen.buttonlist1) + + s = Screen.yesno(self.title, 1, num_widget, 'TextboxReflowed', 'eLabel', 'CheckboxList', 'eLabel', 'ButtonBar') + + if s == 0: + spares = [] + for i in list: + if Screen.d_cbl[i[0]].value() == 1: + spares.append(i[0]) + #(dev, from_os, level, a_devs, s_devs=[]): + if dname not in ri_data.Raid.dict.keys(): + ri_data.Raid(dname,'no',level,[],spares) + else: + ri_data.Raid.dict[dname].spare_components=spares + return s + + def make_raid(self): + fd_devices=Raid.raid_raw_init() + + # from os + raid_text='' + for R in ri_data.Raid.dict.values(): + raid_text+='%s (%s):\n active %s; spare %s\n'%(R.device,R.from_os,R.active_components,R.spare_components) + + #fd + fd_devices_text='fd: '+','.join(fd_devices) + + raidx = ['raid0','raid1','raid5'] + Screen.widget_listbox(3, *raidx) + Screen.widget_buttonbar(Screen.buttonlist2) + Screen.widget_textboxreflowed(50, 'Please select make raidX\n%s\n%s' %(raid_text, fd_devices_text)) + + s = Screen.yesno(self.title, 1, 6, 'TextboxReflowed', 'eLabel', 'Listbox', 'eLabel', 'ButtonBar') + + + if s == 0: + raid = Screen.listbox.current() + dname = ri_data.Raid.get_next_device() + self.raid_raw_to_active(raid[-1],dname) + self.raid_raw_to_spare(raid[-1],dname) + else: + return s + + def del_raid(self): + # from os + raid_text='' + raid_choices=[] + + for R in [ d for d in ri_data.Raid.dict.values() if d.from_os == 'no' ]: + raid_text+='%s (%s):\n active %s; spare %s\n'%(R.device,R.from_os,R.active_components,R.spare_components) + raid_choices.append((R.device,'')) + + len_raid_choices = len(raid_choices) + #Screen.widget_listbox(len_raid_choices, *raid_choices) + + if len(raid_choices) > 5: + h = 5 + else: + h = len(raid_choices) + + Screen.listbox = Listbox(height=h, scroll=1) + for i in raid_choices: + Screen.listbox.append(i[0],i[0]) + Screen.widget_textboxreflowed(50, 'Please select make raidX\n%s' %(raid_text)) + + s = Screen.yesno(self.title, 1, 5, 'TextboxReflowed', 'eLabel', 'Listbox', 'eLabel', 'ButtonBar') + + if s == 0: + device = Screen.listbox.current() + del ri_data.Raid.dict[device] + return s + + def set_data(self): + while True: + list = ['Making the raid device','Delect raid device'] + fd_devices=Raid.raid_raw_init() + fd_devices_text='' + raid_text='' + + from_os_list= [ R.from_os for R in ri_data.Raid.dict.values() if R.from_os == 'no' ] + + if len(fd_devices) < 2 and not from_os_list : + return 0 + + if not fd_devices : + del list[list.index('Making the raid device')] + else: + fd_devices_text='fd: '+','.join(fd_devices) + + if not from_os_list: + del list[list.index('Delect raid device')] + else: + for R in ri_data.Raid.dict.values(): + raid_text+='%s (%s):\n active %s; spare %s\n'%(R.device,R.from_os,R.active_components,R.spare_components) + + len_list = len(list) + Screen.widget_listbox(len_list, *list) + Screen.widget_buttonbar(Screen.buttonlist2) + Screen.widget_textboxreflowed(50, 'Please select make raidX\n%s\n%s' %(raid_text, fd_devices_text)) + + s = Screen.yesno(self.title, 1, 6, 'TextboxReflowed', 'eLabel', 'Listbox', 'eLabel', 'ButtonBar') + + if s == 0: + string = Screen.listbox.current() + + if s == 0 and string == "Making the raid device": + self.make_raid() + elif s == 0 and string == "Delect raid device" : + self.del_raid() + else: + return ( s == 'help' and '0' or s) + +class MountPoint(Screen): + #fs = '' + #dict = {} + def __init__(self): + Screen.__init__(self, name='mountpoint') + self.title = 'MountPoint Configure' + + def set_mountpoint(self, device): + Screen.widget_buttonbar(Screen.buttonlist1) + Screen.widget_textboxreflowed(30, 'Please input the mountpoint and select the file system type.') + Screen.label_mp = Label('mountpoint : ') + Screen.label_fs = Label('File System Type : ') + Screen.widget_label('') + + fs_list = ['ext2','ext3', 'ext4', 'swap', 'reiserfs', 'xfs', 'jfs'] + Screen.widget_listbox(3, *fs_list) + Screen.listbox.setCurrent('ext3') + Screen.widget_entry(15, text='') + Screen.container_grid_complex(3, 2, Screen.label_mp, Screen.entry, Screen.label, Screen.label, Screen.label_fs, Screen.listbox) + s = Screen.yesno(self.title, 1, 6, 'TextboxReflowed', 'eLabel', 'Grid_Complex', 'eLabel', 'ButtonBar') + if s == 0: + ri_data.MountPoint.dict[device].filesystem= Screen.listbox.current() + ri_data.MountPoint.dict[device].directory= Screen.entry.value() + ri_data.MountPoint.dict[device].format='yes' + + return s + + def set_data(self): + ri_data.MountPoint.init_from_internal() + while True: + keys=ri_data.MountPoint.dict.keys() + keys.sort() + + len_keys = len(keys) + list_col_widths = [6, 12, 10, 5, 10] + list_col_labels = [] + list_col_label_align = [CENTER, CENTER, CENTER, CENTER, CENTER] + + Screen.widget_clistbox(list_col_widths, list_col_labels, list_col_label_align, h=len_keys) + + for d in keys: + Screen.clistbox.append(["%s" %(ri_data.MountPoint.dict[d].device), + "%s" %(ri_data.MountPoint.dict[d].directory.ljust(10)), + "%s" %(ri_data.MountPoint.dict[d].filesystem.ljust(10)), + "%s" %(ri_data.MountPoint.dict[d].format.ljust(5)), + "%s%s" %(ri_data.MountPoint.get_size(d),ri_data.Partition.unit)], + "%s" %(ri_data.MountPoint.dict[d].device), + [LEFT, LEFT, LEFT, LEFT, RIGHT]) + + Screen.widget_buttonbar(Screen.buttonlist3) + Screen.widget_textboxreflowed(50, 'There are five colums in the mount point display frame.\nDevice Mountpoint Filesystem Format Size') + s = Screen.yesno(self.title, 1, 6, 'TextboxReflowed', 'CListbox', 'eLabel', 'ButtonBar') + + if s == 0: + self.set_mountpoint(Screen.clistbox.current()) + # edit mountpoint + elif s == None: + pass + else: + break + return (s == 'help' and '0' or s) + +class Network(Screen): + def __init__(self): + Screen.__init__(self, name='network') + self.title = 'Network Configure' + + self.rb_static = SingleRadioButton("Static IP Address", None, 1) + self.rb_dynamic = SingleRadioButton("Dynamic IP Address", self.rb_static) + Screen.widget_buttonbar(Screen.buttonlist1) + + def check_network(self, n): + try: + if (re.match("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$",n) and \ + len([i for i in n.split('.') if (0 <= int(i) <= 255)]) == 4): + return True + else: + return False + except(ValueError): + return False + + def set_network(self, t): + if t == 'dynamic': + Screen.widget_textboxreflowed(50, 'Please enter the hostname:') + Screen.widget_entry(20, text=getattr(ri_data.Network, 'hostname')) + #Screen.widget_entry(30, text='linx') + s = Screen.yesno(self.title, 1, 6, 'TextboxReflowed', 'eLabel', 'Entry', 'eLabel', 'ButtonBar') + if s == 0: + setattr(ri_data.Network, 'hostname', Screen.entry.value()) + + elif t == 'static': + Screen.widget_buttonbar(Screen.buttonlist2) + Screen.widget_textboxreflowed(50, 'Please configure the static net:') + Screen.initial_static_net() + Screen.container_grid(6, 1, Screen.grid_hostname, Screen.grid_domain, Screen.grid_ip,\ + Screen.grid_netmask, Screen.grid_gateway, Screen.grid_primary_dns) + + while True: + s = Screen.yesno(self.title, 1, 6, 'TextboxReflowed', 'eLabel', 'Grid', 'eLabel', 'ButtonBar') + if s == 0: + if self.check_network(Screen.entry_ip.value()) and \ + self.check_network(Screen.entry_netmask.value()) and \ + self.check_network(Screen.entry_gateway.value()) and \ + self.check_network(Screen.entry_primary_dns.value()): + + setattr(ri_data.Network, 'hostname', Screen.entry_hostname.value()) + setattr(ri_data.Network, 'domain', Screen.entry_domain.value()) + setattr(ri_data.Network, 'ip', Screen.entry_ip.value()) + setattr(ri_data.Network, 'mask', Screen.entry_netmask.value()) + setattr(ri_data.Network, 'gateway', Screen.entry_gateway.value()) + setattr(ri_data.Network, 'primary_dns', Screen.entry_primary_dns.value()) + break + else: + #ButtonChoiceWindow(Screen.screen, 'Warning', 'There is something wrong with your input network address.') + Screen.pop_window('Tips', 'There is something wrong with your input network address.') + elif s == -1: + break + else: + return (s == 'help' and '0' or s) + return s + + + def set_data(self): + Screen.container_grid(2,1,self.rb_static, self.rb_dynamic) + Screen.widget_textboxreflowed(50, 'Please select the network type') + + s = Screen.yesno(self.title, 1, 5, 'TextboxReflowed', 'eLabel', 'Grid', 'eLabel', 'ButtonBar') + + if s == 0 and self.rb_static.selected(): + ri_data.Network.configuration == 'static' + s = self.set_network('static') + + elif s == 0 and self.rb_dynamic.selected(): + ri_data.Network.configuration == 'dynamic' + s = self.set_network('dynamic') + + return s + +class Group(Screen): + def __init__(self): + Screen.__init__(self, name='group') + self.title = 'Package Group Selcect' + + def set_data(self): + g_list = [] + for g in ri_data.Group.dict.keys(): + g_list.append(g.encode('ascii')) + + Screen.widget_buttonbar(Screen.buttonlist1) + Screen.widget_textboxreflowed(50, 'Please select the software package groups') + Screen.widget_checkboxlist(g_list) + + for g in g_list: + if ri_data.Group.dict[g].install == 'yes': + Screen.d_cbl[g].setValue('*') + + num_widget = len(g_list) + 4 + + s = Screen.yesno(self.title, 1, num_widget, 'TextboxReflowed', 'eLabel', 'CheckboxList', 'eLabel', 'ButtonBar') + + if s == 0: + for g in g_list: + if Screen.d_cbl[g].value() == 1: + ri_data.Group.dict[g].install='yes' + ri_data.Group.dict[g].selection='all' + else: + ri_data.Group.dict[g].install='no' + + return s + + +class Service(Screen): + def __init__(self): + Screen.__init__(self, name='service') + self.title = 'Start Service' + + def set_data(self): + ri_data.Service.change_state() + + s_list = ['check all'] + for s in ri_data.Service.list: + if s.start != 'disable': + s_list.append(s.name) + + Screen.widget_buttonbar(Screen.buttonlist1) + Screen.widget_textboxreflowed(50, 'Please select the start services') + Screen.widget_checkboxlist(s_list) + + for service in ri_data.Service.list: + if service.start == 'yes': + Screen.d_cbl[service.name].setValue('*') + + num_widget = len(s_list) + 4 + + s = Screen.yesno(self.title, 1, num_widget, 'TextboxReflowed', 'eLabel', 'CheckboxList', 'eLabel', 'ButtonBar') + + if s == 0: + if Screen.d_cbl[s_list[0]].value() == 1: + for service in ri_data.Service.list: + if service.start != 'disable': + service.start='yes' + else: + for service in ri_data.Service.list: + if service.start != 'disable': + if Screen.d_cbl[service.name].value() == 1: + service.start = 'yes' + else: + service.start = 'no' + ri_data.to_xml() + + return s + + + + +class Prepar_installation(Screen): + def __init__(self): + Screen.__init__(self, name='information') + self.title = 'Installation Information' + + def set_data(self): + string = open('/var/install/install.xml').read() + Screen.widget_textbox(100,30,string) + Screen.widget_buttonbar(Screen.buttonlist4) + s = Screen.yesno(self.title, 1, 3, 'Textbox', 'eLabel', 'ButtonBar') + + return s + + + + +#SerialNumber() +#s = Screen.dict['serialnumber'].set_data() + +#Welcome() +#s = Screen.dict['welcome'].set_data() + +#Raid() +#s = Screen.dict['raid'].make_raid() +#s = Screen.dict['raid'].raid_raw_to_active() +#s = Screen.dict['raid'].set_data() + +#Network() +#s = Screen.dict['network'].set_data() + +#Screen.screen.finish() + +#print s +#print s +#print Screen.dict + + + + + + + diff --git a/interface/ri_inst_cli.py b/interface/ri_inst_cli.py index b47a71d..ab5b5cc 100644 --- a/interface/ri_inst_cli.py +++ b/interface/ri_inst_cli.py @@ -27,8 +27,8 @@ def set_task_scale(): print "%.2f" %float(Rate.value) def set_task_over(): - string = raw_input("Rocky system installation successfully, are your restart?[Y]") - if string.lower() == "y": + string = raw_input("Rocky system installation successfully, do you want to reboot?[Y]") + if string.lower() == "y" or string == "": return True return False diff --git a/interface/ri_oper.py b/interface/ri_oper.py index a7d1d34..0e26bf0 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -321,7 +321,7 @@ class BootLoader(Operation): Operation.__init__(self,"Install bootloader",u"安装引导程序","install_bootloader.sh",scr) self.return_value[2]=("Bootloader type hasn't been specified",u"没有指定引导程序的类型") self.return_value[3]=("Bootloader hasn't been implemented",u"没有实现bootloader") - self.return_value[127]=("No tool to bootloader. E.g grub",u"没有安装引导程序的工具。如grub等") + self.return_value[127]=("No tool to bootloader. E.g grub",u"没有安装引导程序的工具。如grub2等") def get_arguments(self): if self.getarch() == "ppc64": @@ -329,7 +329,7 @@ class BootLoader(Operation): elif self.getarch() == "ia64": return ["-t elilo"] else: - return ["-t grub"] + return ["-t grub2"] class ConfigureBootloader(Operation): """class for configure bootloader file""" @@ -347,7 +347,7 @@ class ConfigureBootloader(Operation): elif self.getarch() == "ia64": tp = "elilo" else: - tp = "grub" + tp = "grub2" # FIXME if tag file format is error? if os.path.isfile("/tag"): fd = open("/tag","r") @@ -355,12 +355,13 @@ class ConfigureBootloader(Operation): list = string.split('-') fd.close() - bootloader=['-t',tp,'-o',list[0][5:].split('.')[0]+'.'+list[0][5:].split('.')[1],'-k','"linx_serial=%s vga=791 quiet"' %ri_data.SerialNumber.value.strip()] + #bootloader=['-t',tp,'-o',list[0][5:].split('.')[0]+'.'+list[0][5:].split('.')[1],'-k','"linx_serial=%s vga=791 quiet"' %ri_data.SerialNumber.value.strip()] + bootloader=['-t',tp,'-k','"linx_serial=%s vga=791"' %ri_data.SerialNumber.value.strip()] - for k in Mount.dict.keys(): - if '/' == Mount.dict[k]: - bootloader += ['-r',k] - if '/boot' == Mount.dict[k]: - bootloader += ['-b',k] + #for k in Mount.dict.keys(): + # if '/' == Mount.dict[k]: + # bootloader += ['-r',k] + # if '/boot' == Mount.dict[k]: + # bootloader += ['-b',k] return bootloader diff --git a/new_partition/finddisk.sh b/new_partition/finddisk.sh new file mode 100755 index 0000000..fed7337 --- /dev/null +++ b/new_partition/finddisk.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +finddisks() { + workdir="$PWD" + cd /sys/block + # ide devices + for dev in $(ls | egrep '^hd'); do + if [ "$(cat $dev/device/media)" = "disk" ]; then + echo -e "/dev/$dev$3" + fi + done + #scsi/sata devices, and virtio blockdevices (/dev/vd*) + for dev in $(ls | egrep '^[sv]d'); do + # TODO: what is the significance of 5? ASKDEV + if ! [ "$(cat $dev/device/type)" = "5" ]; then + echo -e "/dev/$dev$3" + fi + done + # cciss controllers + if [ -d /dev/cciss ] ; then + cd /dev/cciss + for dev in $(ls | egrep -v 'p'); do + echo -e "/dev/cciss/$dev$3" + done + fi + # Smart 2 controllers + if [ -d /dev/ida ] ; then + cd /dev/ida + for dev in $(ls | egrep -v 'p'); do + echo -e "/dev/ida/$dev$3" + done + fi + cd "$workdir" +} + +findblockdevices() { + workdir="$PWD" + for devpath in $(finddisks) + do + disk=$(echo $devpath | sed 's|.*/||') + echo -e "/dev/$disk$3" + cd /sys/block/$disk + for part in $disk* + do + # check if not already assembled to a raid device. TODO: what is the significance of the 5? ASKDEV + if ! [ "$(grep $part /proc/mdstat 2>/dev/null)" -o "$(fstype 2>/dev/null /dev/null | grep "5")" ] + then + if [ -d $part ] + then + echo -e "/dev/$part$3" + fi + fi + done + done + # include any mapped devices + for devpath in $(ls /dev/mapper 2>/dev/null | grep -v control) + do + echo -e "/dev/mapper/$devpath$3" + done + # include any raid md devices + for devpath in $(ls -d /dev/md* 2>/dev/null| grep '[0-9]' 2>/dev/null) + do + if grep -qw $(echo $devpath /proc/mdstat | sed -e 's|/dev/||g') + then + echo -e "$devpath$3" + fi + done + # inlcude cciss controllers + if [ -d /dev/cciss ] + then + cd /dev/cciss + for dev in $(ls | egrep 'p') + do + echo -e "/dev/cciss/$dev$3" + done + fi + # inlcude Smart 2 controllers + if [ -d /dev/ida ] + then + cd /dev/ida + for dev in $(ls | egrep 'p') + do + echo -e "/dev/ida/$dev$3" + done + fi + + cd "$workdir" +} + +#findblockdevices |grep -v [0-9]|while read f;\ +#do fdisk -l ${f} 2>/dev/null; done|\ +#grep "Disk /dev" |awk -F "," '{print $1}'|\ +#awk -F ":" '{print $1,$2}' + +findblockdevices |grep -v [0-9] diff --git a/new_partition/list-devices b/new_partition/list-devices new file mode 100755 index 0000000..3005e66 --- /dev/null +++ b/new_partition/list-devices @@ -0,0 +1,170 @@ +#! /bin/sh -e +# get from debian-installer-utils list-devices-linux + +TYPE="$1" + +case $TYPE in + maybe-floppy) + #logger -t list-devices "deprecated parameter maybe-floppy" + TYPE=floppy + ;; + cd|disk|partition|floppy|maybe-usb-floppy|usb-partition) ;; + *) + echo "Usage: $0 cd|disk|partition|floppy|maybe-usb-floppy|usb-partition" >&2 + exit 2 + ;; +esac + +if [ ! -d /sys/block ]; then + exit 0 +fi +if type udevadm >/dev/null 2>&1; then + device_info () { + udevadm info -q "$1" -p "$2" 2>/dev/null + } +elif type udevinfo >/dev/null 2>&1; then + device_info () { + udevinfo -q "$1" -p "$2" 2>/dev/null + } +else + exit 0 +fi + +device_name () { + local name + if ! name="$(device_info name "$1")"; then + name="$(printf %s "${1##*/}" | \ + sed 's,!,/,g')" + fi + echo "/dev/$name" +} + +is_sataraid () { + grep -qs ^DMRAID- "$1/dm/uuid" +} + +is_sataraid_partition () { + # dmraid partitions are always slaved to another dm device + for slave in "$1"/slaves/dm-*; do + if [ -e "$slave" ]; then + return 0 + fi + done + return 1 +} + +if type dmraid >/dev/null 2>&1; then + raiddevs="$(dmraid -r -c || true)" +else + raiddevs= +fi + +# cloned-and-hacked from partman-base/init.d/parted +part_of_sataraid () { + local raiddev + for raiddev in $raiddevs; do + if [ "$(readlink -f "$raiddev")" = "$1" ]; then + return 0 + fi + done + return 1 +} + +syspaths= +scan_partition=false +case $TYPE in + partition) + for x in /sys/block/*/*[0-9]; do + [ -d "$x" ] || continue + syspaths="${syspaths:+$syspaths }$x" + done + for x in /sys/block/dm-*; do + [ -d "$x" ] || continue + (is_sataraid "$x" && is_sataraid_partition "$x") || continue + syspaths="${syspaths:+$syspaths }$x" + done + TYPE=disk + # Also allow misdetected USB devices + scan_partition=: + ;; + usb-partition) + for x in /sys/block/*/*; do + [ -d "$x" ] || continue + syspaths="${syspaths:+$syspaths }$x" + done + ;; + *) + for x in /sys/block/*; do + [ -d "$x" ] || continue + case $x in + /sys/block/dm-*) + if is_sataraid "$x" && is_sataraid_partition "$x"; then + continue + fi + ;; + *) + name="$(device_name "$x")" + if part_of_sataraid "$name"; then + continue + fi + ;; + esac + syspaths="${syspaths:+$syspaths }$x" + done + ;; +esac +for x in $syspaths; do + devpath="${x#/sys}" + match=false + case $TYPE in + floppy) + # TODO ugly special case for non-IDE floppies + case $devpath in + /block/fd[0-9]*) + match=: + ;; + esac + ;; + esac + if ! $match && [ "$TYPE" = cd ]; then + if device_info env "$devpath" | grep -q '^ID_CDROM='; then + match=: + fi + fi + if ! $match; then + if device_info env "$devpath" | grep -q "^ID_TYPE=$TYPE"; then + match=: + fi + fi + if ! $match && [ "$TYPE" = disk ]; then + case $devpath in + /block/cciss\!*|/block/ida\!*|/block/rd\!*|/block/mmcblk*|/block/vd[a-z]*|/block/xvd[a-z]*) + match=: + ;; + /block/dm-*) + # for now, we only understand dmraid + if is_sataraid "/sys$devpath"; then + match=: + fi + ;; + esac + fi + # Some USB sticks and CD drives are misdetected as floppy + # This allows to scan for those + if ! $match && ( $scan_partition || [ "$TYPE" = maybe-usb-floppy ] ); then + if device_info env "$devpath" | grep -q '^ID_BUS=usb' && \ + device_info env "$devpath" | grep -q '^ID_TYPE=floppy'; then + match=: + fi + fi + # Disk partitions, but only on USB drives + if ! $match && [ "$TYPE" = usb-partition ]; then + if device_info env "$devpath" | grep -q '^ID_BUS=usb' && \ + device_info env "$devpath" | grep -q '^ID_TYPE=disk'; then + match=: + fi + fi + if $match; then + device_name "/sys$devpath" + fi +done diff --git a/new_partition/new_partition.py b/new_partition/new_partition.py new file mode 100755 index 0000000..423b012 --- /dev/null +++ b/new_partition/new_partition.py @@ -0,0 +1,558 @@ +#!/usr/bin/env python + +from snack import * +import gettext +_ = lambda x: gettext.ldgettext("linx", x) + +import sys +import os +import re +import string + +data_dir = '/tmp/new_partitions' +os.mkdir(data_dir) + +screen = SnackScreen() + +screen.drawRootText(0, 0, "Welcome to Rocky Security OS") + +screen.pushHelpLine( _(" F1-New F2-Delete F3-Boot F4-Raid F12-OK ")) + +global p_num +p_num = dict() + +def invalidnumber(str, maxsize): + ints = string.digits + "." + if str == "": + return ("Must specify a value") + for n in str: + if n not in ints: + return ("Requested value is not an number") + if float(str) > float(maxsize): + return ("Requested value is too large") + +def showInvalidNumberWindow(tips): + g21 = GridForm(screen, "Invalid Entry for Partition Size", 1, 2) + g21.add(Label("%s." %(tips)), 0, 0) + g21.add(Button("OK"), 0, 1) + g21.runOnce() + +def findstrinfile(filename, lookup): + return lookup in open(filename, 'rt').read() + +def get_extended_end(filename): + f_extended = open(filename, 'r') + for end in f_extended.readlines(): + if re.search('extended',end): + extended_end = end.split('\n')[0].split()[2] + f_extended.close() + return extended_end + else: + continue + f_extended.close() + +def get_extended_start(filename): + f_extended = open(filename, 'r') + for start in f_extended.readlines(): + if re.search('extended',start): + extended_start = start.split('\n')[0].split()[1] + f_extended.close() + return extended_start + else: + continue + f_extended.close() + +def conform_start_end(free_space_start, size_set, flag_align=""): + free_space_start_unit = filter(str.isalpha, free_space_start) + size_set_unit = filter(str.isalpha, size_set) + free_space_start_num = get_size_num(free_space_start) + size_set_num = get_size_num(size_set) + size_set_num_orig = size_set_num + + if size_set_unit == free_space_start_unit: + pass + else: + if free_space_start_unit == "kB" and size_set_unit == "MB": + #size_set_num = float(size_set_num) * 1000 + free_space_start_num = float(free_space_start_num) / 1000 + elif free_space_start_unit == "kB" and size_set_unit == "GB": + #size_set_num = float(size_set_num) * 1000 * 1000 + free_space_start_num = float(free_space_start_num) / 1000 / 1000 + elif free_space_start_unit == "MB" and size_set_unit == "kB": + size_set_num = float(size_set_num) / 1000 + size_set_unit = free_space_start_unit + elif free_space_start_unit == "MB" and size_set_unit == "GB": + #size_set_num = float(size_set_num) * 1000 + free_space_start_num = float(free_space_start_num) / 1000 + elif free_space_start_unit == "GB" and size_set_unit == "kB": + size_set_num = float(size_set_num) / 1000 / 1000 + size_set_unit = free_space_start_unit + elif free_space_start_unit == "GB" and size_set_unit == "MB": + size_set_num = float(size_set_num) / 1000 + size_set_unit = free_space_start_unit + + if flag_align == "0%": + if size_set_unit == "kB": + size_set_num_tmp = float(size_set_num_orig) + if size_set_unit == "MB": + size_set_num_tmp = float(size_set_num_orig) * 1000 + elif size_set_unit == "GB": + size_set_num_tmp = float(size_set_num_orig) * 1000 * 1000 + + if size_set_num_tmp < 2000: + free_space_end = "2MB" + else: + free_space_end = size_set + else: + free_space_end_num = float(free_space_start_num) + float(size_set_num) + free_space_end = str(free_space_end_num) + size_set_unit + + return free_space_end + +def conform_and_compare(var1, var2, sign): + + var1_unit = filter(str.isalpha, var1) + var2_unit = filter(str.isalpha, var2) + var1_num = get_size_num(var1) + var2_num = get_size_num(var2) + + if var1_unit == var2_unit: + pass + if var1_unit == "kB" and var2_unit == "MB": + var2_num = float(var2_num) * 1000 + elif var1_unit == "kB" and var2_unit == "GB": + var2_num = float(var2_num) * 1000 * 1000 + elif var1_unit == "MB" and var2_unit == "kB": + var2_num = float(var2_num) / 1000 + elif var1_unit == "MB" and var2_unit == "GB": + var2_num = float(var2_num) * 1000 + elif var1_unit == "GB" and var2_unit == "kB": + var2_num = float(var2_num) / 1000 / 1000 + elif var1_unit == "GB" and var2_unit == "MB": + var2_num = float(var2_num) / 1000 + + var2_num = float(var2_num) + var1_num = float(var1_num) + + if sign == ">=": + if var2_num >= var1_num: + return True + else: + return False + elif sign == "<=": + if var2_num <= var1_num: + return True + else: + return False + + +def get_disk_label(disk_name): + os.system("parted /dev/%s print |grep 'Partition Table:'|awk -F':' \ + '{print $2}' >%s/label-%s" %(disk_name, data_dir, disk_name)) + f_disk_label = open("%s/label-%s" %(data_dir, disk_name)) + label = f_disk_label.readline().split('\n')[0].strip() + f_disk_label.close() + + return label + +def get_size_num(size): + if re.search('kB', size): + size_num = size.split('kB')[0] + elif re.search('MB', size): + size_num = size.split('MB')[0] + elif re.search('GB', size): + size_num = size.split('GB')[0] + return size_num + +def get_new_partition_num(dev, dev_name, ptype): + p_num_new = dict() + p_num_new['logical_num_'+dev_name] = [] + p_num_new['primary_num_'+dev_name] = [] + + os.system('parted %s print free |sed -n "/^Number/,//p" |sed \ + "/^Number/d" |sed "/^$/d">%s/%s-partitions 2>/dev/null' %(dev,data_dir,dev_name)) + f_partitions = open("%s/%s-partitions" %(data_dir,dev_name), 'r') + + label = get_disk_label(dev_name) + + if label == "gpt": + for p in f_partitions.readlines(): + p = p.split('\n')[0] + if re.search('Free Space', p): + pass + else: + p_num_new['primary_num_'+dev_name].append(int(p.split()[0])) + elif label == "msdos": + for p in f_partitions.readlines(): + p = p.split('\n')[0] + ptype = p.split()[4] + if re.search('Free Space', p): + pass + else: + if ptype == "logical": + p_num_new['logical_num_'+dev_name].append(int(p.split()[0])) + else: + if ptype != "extended": + p_num_new['primary_num_'+dev_name].append(int(p.split()[0])) + + f_partitions.close() + return p_num_new + +def set_partition_flag(ptype, dev, dev_name, flag): + p_num_new = get_new_partition_num(dev,dev_name,ptype) + for i in p_num_new[ptype+'_num_'+dev_name]: + if i not in p_num[ptype+'_num_'+dev_name]: + if flag == 'boot': + os.system("parted -s %s set %d boot >/dev/null 2>&1" %(dev, i)) + elif flag == 'raid': + os.system("parted -s %s set %d raid >/dev/null 2>&1" %(dev, i)) + +def new_partition(ptype='', extended='', label=''): + dev = clb.current().split(":")[2] + dev_name = dev.split("/")[2] + size = clb.current().split(":")[3] + free_space_start = clb.current().split(":")[4] + end = clb.current().split(":")[5] + + if re.search('kB', free_space_start) and \ + float(get_size_num(free_space_start)) < 2048: + free_space_start_real = free_space_start + free_space_start = '0%' + + size_num = get_size_num(size) + unit = filter(str.isalpha, size) + + bb2 = ButtonBar(screen, (("OK", "ok"), ("Cancel", "cancel"))) + + sg21 = Grid(2,1) + typeLbl = Label("File System type: ") + lb_fstype = Listbox(height=3, scroll=1) + list_fs = ['ext2', 'ext3', 'ext4', 'linux-swap', 'raid', 'reiserfs', 'xfs', 'jfs'] + for fs in list_fs: + lb_fstype.append(fs, fs) + lb_fstype.setCurrent('ext3') + sg21.setField(typeLbl, 0, 0, anchorLeft=0) + sg21.setField(lb_fstype, 1, 0) + + sg22 = Grid(2,1) + sizeLbl = Label("Size(%s): " %(unit)) + size_entry = Entry(10, size_num) + sg22.setField(sizeLbl, 0, 0) + sg22.setField(size_entry, 1, 0) + + sg23 = Grid(2,1) + rb_primary = SingleRadioButton("primary", None, 1) + rb_extended = SingleRadioButton("extended", rb_primary) + sg23.setField(rb_primary, 0, 0) + sg23.setField(rb_extended, 1, 0) + + cb_boot = Checkbox("Force to be a bootable partition") + + g2 = GridForm(screen, "New Partition(%s)" %(dev), 1, 9) + g2.add(sg21,0,0) + g2.add(Label(""),0,1) + g2.add(sg22,0,2) + g2.add(Label(""),0,3) + g2.add(cb_boot,0,4) + g2.add(Label(""),0,5) + + if extended == "extended" or label == 'gpt': + g2.add(bb2, 0, 6) + res2 = g2.runOnce() + if label == 'gpt': + ptype = 'primary' + else: + g2.add(sg23,0,6) + g2.add(Label(""),0,7) + g2.add(bb2, 0, 8) + res2 = g2.runOnce() + if rb_primary.selected(): + ptype = 'primary' + else: + ptype = 'extended' + + if bb2.buttonPressed(res2) == "ok": + fs_set = lb_fstype.current() + + tips = invalidnumber(size_entry.value(), size_num) + if tips: + showInvalidNumberWindow(tips) + else: + size_set = size_entry.value() + unit + if free_space_start == "0%": + free_space_end = conform_start_end(free_space_start_real,size_set,"0%") + else: + free_space_end = conform_start_end(free_space_start, size_set) + + if ptype == 'primary' or ptype == 'logical': + if fs_set == 'raid': + os.system("parted -s %s mkpart %s %s %s >/dev/null 2>&1" %(dev, ptype,\ + free_space_start, free_space_end)) + set_partition_flag(ptype, dev, dev_name, 'raid') + elif fs_set == 'linux-swap': + os.system("parted -s %s mkpartfs %s %s %s %s >/dev/null 2>&1" %(dev, ptype,\ + fs_set,free_space_start, free_space_end)) + else: + os.system("parted -s %s mkpart %s %s %s %s >/dev/null 2>&1" %(dev, ptype,\ + fs_set,free_space_start, free_space_end)) + if cb_boot.value() == 1: + set_partition_flag(ptype, dev, dev_name, 'boot') + elif ptype == 'extended': + os.system("parted -s %s mkpart %s %s %s >/dev/null 2>&1" %(dev, ptype,\ + free_space_start, free_space_end)) + + +def del_partition(): + dev = clb.current().split(":")[1] + bb3 = ButtonBar(screen, (("Cancel", "cancel"), ("Delete", "delete"))) + g3 = GridForm(screen, "Del Partition", 1, 3) + g3.add(TextboxReflowed(45, 'You are about to delete the partition "%s".' \ + %(dev,)), 0, 0) + g3.add(Label(""),0,1) + g3.add(bb3, 0, 2) + res3 = g3.runOnce() + if bb3.buttonPressed(res3) == "delete": + disk = "/dev/" + filter(str.isalpha, dev) + num = filter(str.isdigit, dev) + ptype = clb.current().split(":")[2] + os.system("parted -s %s rm %s >/dev/null 2>&1" %(disk, num)) + +def showPartitionWindow(): + p_num.clear() + global clb + clb = CListbox(height=10, cols=6, + col_widths=[13,11,11,11,10,12], + scroll=1, returnExit = 1, + width=79, col_pad=2, + col_labels=[_('Device'), _('Start'), _('End'), _('Size'), _('Type'), _('Flags')], + col_label_align=[CENTER,CENTER,CENTER,CENTER,CENTER,CENTER]) + + os.system("../new_partition/parted_devices |awk -F' ' '{print $1}' >%s/disks 2>/dev/null" %(data_dir)) + f_disk = open("%s/disks" %(data_dir), 'r') + + for d in f_disk.readlines(): + disk = d.split('\n')[0] + disk_name = disk.split('/')[2] + + p_num['logical_num_'+disk_name] = [] + p_num['primary_num_'+disk_name] = [] + + clb.append(["%s" %(disk),"","","","",""], \ + "disk:%s" %(disk), \ + [LEFT, RIGHT, RIGHT, RIGHT, LEFT, LEFT]) + + os.system('parted %s print free |sed -n "/^Number/,//p" |sed \ + "/^Number/d" |sed "/^$/d" >%s/%s-partitions 2>/dev/null' %(disk,data_dir,disk_name)) + + f_partitions = open("%s/%s-partitions" %(data_dir,disk_name), 'r') + + for p in f_partitions.readlines(): + p = p.split('\n')[0] + if re.search('Free Space', p): + size = p.split()[2] + if re.search('512B', size) or (float(get_size_num(size)) < 2048 \ + and filter(str.isalpha, size) == 'kB'): + continue + partition = "Free Space" + start = p.split()[0] + end = p.split()[1] + ptype = p.split()[3] + " " + p.split()[4] + fs = "" + flags = "" + + label = get_disk_label(disk_name) + + clb.append([" %s" %(partition), + "%s" %(start), + "%s" %(end), + "%s" %(size), + "%s" %(ptype), + "%s" %(flags)], "partition:%s:%s:%s:%s:%s:%s" %(partition,disk, size, start, end,label), + [LEFT, RIGHT, RIGHT, RIGHT, LEFT, LEFT]) + + else: + partition = disk_name + p.split()[0] + + start = p.split()[1] + end = p.split()[2] + size = p.split()[3] + ptype = p.split()[4] + + if ptype == "logical": + p_num['logical_num_'+disk_name].append(int(p.split()[0])) + else: + if ptype != "extended": + p_num['primary_num_'+disk_name].append(int(p.split()[0])) + + os.system("blkid /dev/%s |awk -F' TYPE=' '{print $2}' |awk \ + -F'\"' '{print $2}' >%s/fsType-%s 2>/dev/null" %(partition,data_dir,partition)) + + f_partitions_fs = open("%s/fsType-%s" %(data_dir,partition)) + fs = f_partitions_fs.readline().split('\n')[0] + flags = "" + + try: + if fs != "": + try: + flags = p.split()[6] + p.split()[7] + except: + flags = p.split()[6] + else: + try: + #flags = p.split()[5] + ", " + p.split()[6] + flags = p.split()[5] + " " + p.split()[6] + except: + flags = p.split()[5] + except: + pass + + if fs == "swap": + if flags == "": + flags = fs + else: + flags = flags + ", swap" + + #if fs == "linux_raid_member": + # if flags == "": + # flags = 'raid' + # else: + # flags = flags + ", raid" + + clb.append([" %s" %(partition), + "%s" %(start), + "%s" %(end), + "%s" %(size), + "%s" %(ptype), + "%s" %(flags)], "partition:%s:%s:%s:%s" %(partition, ptype, disk, flags), + [LEFT, RIGHT, RIGHT, RIGHT, LEFT, LEFT]) + + f_partitions_fs.close() + + + f_partitions.close() + + f_disk.close() + + global bb + bb = ButtonBar (screen, ((_("New"), "new", "F1"), + (_("Delete"), "delete", "F2"), + (_("Boot"), "boot", "F3"), + (_("Raid"), "raid", "F4"), + (_("OK"), "ok", "F12"), + (_("Cancel"), "cancel"), + )) + + sg = Grid(2, 3) + sg.setField(bb, 0, 1, anchorLeft = 1) + + g = Grid(1, 3) + g.setField(clb, 0, 0) + g.setField(sg, 0, 2) + #g.setField(bb, 0, 1) + g.place(1, 1) + screen.gridWrappedWindow(g, "Partitioning") + + f = Form("This is some help") + f.add(bb) + f.add(clb) + + f.addHotKey("F1") + f.addHotKey("F2") + f.addHotKey("F3") + f.addHotKey("F4") + f.addHotKey("F12") + + global res + res = f.run() + + #screen.popWindow() + screen.refresh() + +while(1): + global ret + showPartitionWindow() + + if bb.buttonPressed(res) == "cancel": + ret = 1 + break + + if bb.buttonPressed(res) == "ok": + ret = 0 + break + + if bb.buttonPressed(res) == "boot": + if re.search("partition:", clb.current()) and \ + re.search("swap", clb.current()) == None and \ + re.search("raid", clb.current()) == None and \ + re.search("lba", clb.current()) == None: + dev = clb.current().split(":")[3] + partition_num = filter(str.isdigit, clb.current().split(":")[1]) + os.system("parted -s %s set %s boot >/dev/null 2>&1" %(dev, partition_num)) + + if bb.buttonPressed(res) == "raid": + if re.search("partition:", clb.current()) and \ + re.search("lba", clb.current()) == None: + dev = clb.current().split(":")[3] + partition_num = filter(str.isdigit, clb.current().split(":")[1]) + os.system("parted -s %s set %s raid >/dev/null 2>&1" %(dev, partition_num)) + + # assign partition table label + if re.search("disk:", clb.current()): + dev = clb.current().split(":")[1] + rb = RadioBar(screen, (("gpt", "gpt", 0),("msdos", "msdos", 1))) + bb1 = ButtonBar(screen, (("Cancel", "cancel"), ("OK", "ok"))) + g = GridForm(screen, "Partition table", 1, 4) + g.add(TextboxReflowed(25, 'Warning! A new partition table will be created on "%s" and the data on it will be cleared.' \ + %(dev,)), 0, 0) + g.add(Label(""),0,1) + g.add(rb,0,2,(0,0,0,1)) + g.add(bb1, 0, 3) + res1 = g.runOnce() + if bb1.buttonPressed(res1) == "ok": + label = rb.getSelection() + os.system("parted -s %s mklabel %s >/dev/null 2>&1" %(dev, label)) + + # new partition when partition table label is msdos + elif re.search("partition:Free", clb.current()) and \ + clb.current().split(':')[6] == 'msdos'and \ + bb.buttonPressed(res) == "new": + dev = clb.current().split(":")[2] + dev_name = dev.split("/")[2] + free_space_start = clb.current().split(":")[4] + end = clb.current().split(":")[5] + # new logical partition when partition table is msdos and there is + # an extended partition + if findstrinfile("%s/%s-partitions" %(data_dir,dev_name), "extended"): + + extended_start = get_extended_start("%s/%s-partitions" %(data_dir,dev_name)) + extended_end = get_extended_end("%s/%s-partitions" %(data_dir,dev_name)) + + if conform_and_compare(extended_start, free_space_start, '>=') and \ + conform_and_compare(extended_end, end, '<='): + ptype = 'logical' + # new primary partition when partition table label is msdos and + # there is an extended partition + else: + ptype = 'primary' + + new_partition(ptype,'extended','msdos') + + # new partition when partition table label is msdos and there is no + # extended partition + else: + new_partition(ptype='', extended='', label='msdos') + + # new partition when partition table label is gpt + elif re.search("partition:Free", clb.current()) and \ + clb.current().split(':')[6] == 'gpt' and \ + bb.buttonPressed(res) == "new": + new_partition(ptype='primary', extended='', label='gpt') + elif re.search("partition:Free", clb.current()) == None and \ + re.search("disk:", clb.current()) == None and \ + bb.buttonPressed(res) == "delete": + del_partition() + + +screen.finish() +os.system('rm -rf %s' %(data_dir)) +sys.exit(ret) diff --git a/new_partition/parted_devices b/new_partition/parted_devices new file mode 100755 index 0000000000000000000000000000000000000000..65992592f542e9e0947ac58597018f1f8ff175cf GIT binary patch literal 10357 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 literal 0 HcmV?d00001 diff --git a/new_partition/parted_devices.py b/new_partition/parted_devices.py new file mode 100755 index 0000000..e16fa25 --- /dev/null +++ b/new_partition/parted_devices.py @@ -0,0 +1,38 @@ +#!/usr/bin/python + +import parted +import _ped + + +# class from pyparted-3.4/tests/_ped/baseclass.py +# Base class for any test case that requires a list being built via successive +# calls of some function. The function must raise IndexError when there's no +# more output to add to the return list. This class is most useful for all +# those _get_next methods. +class BuildList: + def getDeviceList(self, func): + lst = [] + prev = None + + while True: + try: + if not prev: + prev = func() + else: + prev = func(prev) + + lst.append(prev) + except IndexError: + break + + return lst + + +_ped.device_probe_all() +List = BuildList() +disk_list = List.getDeviceList(_ped.device_get_next) + +for i in range(len(disk_list)): + print disk_list[i].path + +#print _ped.device_get_next() diff --git a/operation/configure_bootloader_cnf.sh b/operation/configure_bootloader_cnf.sh index 40b1371..b180d9e 100755 --- a/operation/configure_bootloader_cnf.sh +++ b/operation/configure_bootloader_cnf.sh @@ -164,6 +164,10 @@ EOF chown 96.96 $GRUBMENU } +configure_def_grub (){ + sed -i "s/GRUB_CMDLINE_LINUX=\"/&$KPARAMETER/" "$DEFGRUB" +} + main () { if [ $# -eq 0 ];then @@ -225,6 +229,10 @@ main () configure_elilo_cnf erv ;; + grub2) + configure_def_grub + erv + ;; *) err "$TYPE bootloader no implement yet !" exit 3 @@ -245,6 +253,7 @@ KPARAMETER="" OSVERSION="" GRUB_DIR="$TARGET/boot/grub" GRUBMENU="$GRUB_DIR/menu.lst" +DEFGRUB="$TARGET/etc/default/grub" DEVICEMAP="$GRUB_DIR/device.map" ELILO_CNF="/tmp/tmppoint/efi/boot/elilo.conf" diff --git a/operation/copy_kernels.sh b/operation/copy_kernels.sh index aaed391..7ef5cd9 100755 --- a/operation/copy_kernels.sh +++ b/operation/copy_kernels.sh @@ -27,6 +27,8 @@ source ./functions +set -x + main () { @@ -43,20 +45,36 @@ main () info "copy $KERNELS/* to $TARGET/boot/" if [ -d "$KERNELS" ];then - cp -r "$KERNELS"/* "$TARGET/boot/" 2>>$DEV_LOG + #cp -r "$KERNELS"/* "$TARGET/boot/" 2>>$DEV_LOG + cp -r "$KERNELS"/System* "$TARGET/boot/" 2>>$DEV_LOG + cp $KERNELS/vmlinuz-root $TARGET/boot/vmlinuz-2.6.32.41-Rocky4.2-x86_64-root + cp $KERNELS/vmlinuz-root-n $TARGET/boot/vmlinuz-2.6.32.41-Rocky4.2-x86_64-nroot + cp $KERNELS/vmlinuz-root-n-nocgroup $TARGET/boot/vmlinuz-2.6.32.41-Rocky4.2-x86_64-nocgroup-root + cp $KERNELS/vmlinuz-root-nocgroup $TARGET/boot/vmlinuz-2.6.32.41-Rocky4.2-x86_64-nocgroup-nroot else err "$KERNELS directory doesn't exist " exit 1 fi - info "copy $INITRD/initrd-full-cgroup.gz to $TARGET/boot/initrd-full-cgroup.gz and copy $INITRD/initrd-full-nocgroup.gz to $TARGET/boot/initrd-full-nocgroup.gz" - if [ -e "$INITRD/initrd-full-cgroup.gz" -a -e "$INITRD/initrd-full-nocgroup.gz" ];then - cp "$INITRD/initrd-full-cgroup.gz" "$TARGET/boot/initrd-full-cgroup.gz" 2>>$DEV_LOG - cp "$INITRD/initrd-full-nocgroup.gz" "$TARGET/boot/initrd-full-nocgroup.gz" 2>>$DEV_LOG - else - err "$INITRD/initrd-full-cgroup.gz or $INITRD/initrd-full-nocgroup.gz doesn't exist " - exit 1 - fi + #info "copy $INITRD/initrd-full-cgroup.gz to $TARGET/boot/initrd-full-cgroup.gz and copy $INITRD/initrd-full-nocgroup.gz to $TARGET/boot/initrd-full-nocgroup.gz" + #if [ -e "$INITRD/initrd-full-cgroup.gz" -a -e "$INITRD/initrd-full-nocgroup.gz" ];then + # cp "$INITRD/initrd-full-cgroup.gz" "$TARGET/boot/initrd-full-cgroup.gz" 2>>$DEV_LOG + # cp "$INITRD/initrd-full-nocgroup.gz" "$TARGET/boot/initrd-full-nocgroup.gz" 2>>$DEV_LOG + #else + # err "$INITRD/initrd-full-cgroup.gz or $INITRD/initrd-full-nocgroup.gz doesn't exist " + # exit 1 + #fi + + info "copy $INITRD/initrd-full.gz to $TARGET/boot/initrd.gz" + if [ -e "$INITRD/initrd-full-cgroup.gz" -a -e "$INITRD/initrd-full-cgroup.gz" ];then + cp "$INITRD/initrd-full-cgroup.gz" "$TARGET/boot/initrd.img-2.6.32.41-Rocky4.2-x86_64-root" 2>>$DEV_LOG + cp "$INITRD/initrd-full-cgroup.gz" "$TARGET/boot/initrd.img-2.6.32.41-Rocky4.2-x86_64-nroot" 2>>$DEV_LOG + cp "$INITRD/initrd-full-nocgroup.gz" "$TARGET/boot/initrd.img-2.6.32.41-Rocky4.2-x86_64-nocgroup-root" 2>>$DEV_LOG + cp "$INITRD/initrd-full-nocgroup.gz" "$TARGET/boot/initrd.img-2.6.32.41-Rocky4.2-x86_64-nocgroup-nroot" 2>>$DEV_LOG + else + err "$INITRD/initrd-full-cgroup.gz doesn't exist " + exit 1 + fi info "copy $FIRMWARE to $TARGET/lib/" if [ -d $FIRMWARE ];then diff --git a/operation/install_bootloader.sh b/operation/install_bootloader.sh index 7422784..c97b66f 100755 --- a/operation/install_bootloader.sh +++ b/operation/install_bootloader.sh @@ -69,6 +69,30 @@ EOF grub-install --no-floppy --root-directory=$TARGET $f_hd 1>>$DEV_LOG 2>&1 } +# This should probably be rewritten using udevadm or similar. +# from di grub-install +device_to_disk () +{ + echo "$1" | \ + sed 's:\(/dev/\(cciss\|ida\|rs\)/c[0-9]d[0-9][0-9]*\|/dev/mmcblk[0-9]\|/dev/\(ad\|da\)[0-9]\+\|/dev/[hs]d[0-9]\+\|/dev/[a-z]\+\).*:\1:' +} + +install_grub2() +{ + mount -obind /dev $TARGET/dev + mount -obind /proc $TARGET/proc + mount -obind /sys $TARGET/sys + + boot_dev=$(chroot $TARGET grub-probe -t device /boot) + disk=$(device_to_disk $boot_dev) + + chroot $TARGET update-grub > /dev/null 2>&1 + chroot $TARGET grub-install $disk --force > /dev/null 2>&1 + chroot $TARGET update-grub > /dev/null 2>&1 +} + + + main () { if [ $# -eq 0 ];then @@ -102,6 +126,10 @@ main () install_grub erv ;; + grub2) + install_grub2 + erv + ;; elilo) echo "install elilo"; sed -i '/tmppoint/d' $TARGET/etc/fstab diff --git a/xml/config.xml b/xml/config.xml index 20f70eb..773416d 100644 --- a/xml/config.xml +++ b/xml/config.xml @@ -168,6 +168,8 @@ + + @@ -244,7 +246,7 @@ - + @@ -833,6 +835,7 @@ + @@ -842,7 +845,7 @@ - + diff --git a/xml/dependency.xml b/xml/dependency.xml index 0a9a27d..b3235e3 100644 --- a/xml/dependency.xml +++ b/xml/dependency.xml @@ -787,7 +787,8 @@ - + +