Add kernel and initrd variables

netsetup
Mike Hiretsky 14 years ago
parent 89899877f4
commit 8e975365e3

@ -20,9 +20,12 @@ import cl_overriding
from cl_datavars import glob_attr
from os.path import join as pathjoin, exists as pathexists
from os import readlink,listdir,access,R_OK
from cl_utils import isMount
from cl_utils import isMount,typeFile,getTupleVersion
from cl_distr import DistributiveRepository
from cl_fill import clLocale
from operator import itemgetter
from cl_template import _terms
from subprocess import PIPE, Popen
class fillVars(object, glob_attr):
nonTransferedDirs = ["/","/bin", "/dev", "/etc",
@ -732,6 +735,12 @@ class fillVars(object, glob_attr):
else:
return self.Get('os_root_type')
def get_os_install_dev_from(self):
if self.Get('os_root_type') == "hdd":
return self.Get('os_root_dev')
else:
return ""
def get_os_install_makeopts(self):
"""Get makeopts for make.conf file"""
cpunum = self.Get('hr_cpu_num')
@ -739,3 +748,78 @@ class fillVars(object, glob_attr):
return "-j1"
else:
return "-j%d"%(cpunum+1)
reFindVer = re.compile(
"(?<=version )(\d+\.?\d*\.?\d*\.?\d*)([^\d* ])*(\d*)")
def getFilesByType(self,path,descr):
"""Get files from "path" has "descr" in descriptions"""
filelist = map(lambda x:pathjoin(path,x),os.listdir(path))
ftype = typeFile(magic=0x4).getMType
filesWithType = map(lambda x:(x,ftype(x)), filelist)
return filter(lambda x:descr in x[1],filesWithType)
def get_os_install_kernel(self):
bootdir = pathjoin(self.Get('cl_chroot_path'),'boot')
modulesdir = pathjoin(self.Get('cl_chroot_path'),'lib/modules')
validKernel = os.listdir(modulesdir)
kernelFiles = self.getFilesByType(bootdir,"Linux kernel")
kernelsWithVer = \
map(lambda x:(x[0],getTupleVersion("".join(x[1].groups()[0:3:2]))),
filter(lambda x:x[1] and x[1].group() in validKernel,
map(lambda x:(x[0],self.reFindVer.search(x[1])),
kernelFiles)))
if kernelsWithVer:
return os.path.split(max(kernelsWithVer,key=itemgetter(1))[0])[-1]
else:
return "vmlinuz"
def getInitrd(self,suffix=""):
"""Get initrd for kernel"""
#def initrd_version_by_content(filename):
# p1 = Popen(["/bin/gzip","-dc",filename],stdout=PIPE,stderr=PIPE)
# p2 = Popen(["/bin/cpio","-tf"],stdin=p1.stdout,stdout=PIPE,
# stderr=PIPE)
# result = filter(lambda x: "lib/modules/" in x,
# p2.communicate()[0].split('\n'))
# if result:
# splitresult = result[0].split('/')
# if len(splitresult)>2:
# return splitresult[2]
# return ""
reInitrdVer = re.compile("(initrd|initramfs)-(.+?)(-install)?$",re.S)
def initrd_version_by_name(filename):
resInitrdVer = reInitrdVer.search(filename)
if resInitrdVer:
return resInitrdVer.groups()[1]
return ""
ftype = typeFile(magic=0x4).getMType
kernelfile = pathjoin(self.Get('cl_chroot_path'),'/boot',
self.Get('os_install_kernel'))
resKernelVer = self.reFindVer.search(ftype(kernelfile))
if resKernelVer:
kernelVersion = resKernelVer.group()
bootdir = pathjoin(self.Get('cl_chroot_path'),'boot')
initramfsFiles = self.getFilesByType(bootdir,"ASCII cpio archive")
initramfsWithVer = \
filter(lambda x: x[1] == kernelVersion and \
x[0].endswith(suffix),
map(lambda x:(x[0],initrd_version_by_name(x[0])),
initramfsFiles))
if initramfsWithVer:
return os.path.split(min(initramfsWithVer,
key=itemgetter(0))[0])[-1]
if suffix:
return "initrd-%s"%suffix
else:
return "initrd"
def get_os_install_initrd(self):
return self.getInitrd(suffix="")
#return self.Get('os_install_initrd_install').strip('-install')
def get_os_install_initrd_install(self):
return self.getInitrd(suffix="install")

@ -71,7 +71,7 @@ class DataVarsInstall(DataVars):
def importInstall(self, **args):
'''Заполнить конфигурацию переменных, для десктопа'''
# Имя секции в calculate.env
envSection = "calculate-install"
envSection = "install"
# заполнить переменные окружения алгоритмом по умолнанию
self.importData(envSection, ('cl_vars_install','cl_fill_install'))
@ -598,7 +598,7 @@ class cl_install(color_print):
"""Apply templates for root of system."""
#self.clVars.Set("cl_root_path","/", True)
self.clVars.Set("cl_chroot_path","/", True)
self.clVars.Write("cl_pass_action", "template", True)
self.clVars.Set("cl_pass_action", "template", True)
self.clTempl = template(self.clVars)
dirsFiles = self.clTempl.applyTemplates()
if self.clTempl.getError():
@ -689,7 +689,7 @@ class cl_install(color_print):
"""Apply templates for root of system."""
#self.clVars.Set("cl_root_path",directory, True)
self.clVars.Set("cl_chroot_path",directory, True)
self.clVars.Write("cl_pass_action", "install", True)
self.clVars.Set("cl_pass_action", "install", True)
self.clTempl = template(self.clVars)
dirsFiles = self.clTempl.applyTemplates()
if self.clTempl.getError():
@ -1158,6 +1158,12 @@ class cl_install(color_print):
return False
return True
def writeInstallVars(self):
self.clVars.Write('cl_pass_action','template', True,
header="install")
if not self.clVars.WriteVars(header="install"):
raise InstallError(self.getError())
def installSystem(self, force=False, bootDisk=None, users=[]):
"""install System by current variable enviroment"""
if not users:
@ -1285,6 +1291,9 @@ the system") + " (yes/no)"
self.applyTemplates(targetDistr.getDirectory())
# mount bind mount points
targetDistr.postinstallMountBind()
self.writeInstallVars()
# migrate users
self.printSUCCESS(_("Migrate users"))
addUsers = self.generateHashUsers(users)

@ -46,13 +46,12 @@ class share_cmd(color_print, _error):
def writeVars(self, optObj):
"""Запись переменных"""
if optObj.set:
if not self.clVars.WriteVars(header="calculate-install"):
errMsg = self.getError()
if errMsg:
self.printERROR(errMsg.strip())
self.printERROR(_('Can not write template variables'))
return False
if not self.clVars.WriteVars(header="install"):
errMsg = self.getError()
if errMsg:
self.printERROR(errMsg.strip())
self.printERROR(_('Can not write template variables'))
return False
return True
def setPrintNoColor(self, optObj):

@ -6,8 +6,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# http://www.apache.org/licenses/LICENSE-2.0 #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -153,6 +152,9 @@ class Data:
# root device of installed os
os_install_root_dev = {}
# root device of previous installed os
os_install_dev_from = {}
# list mount options of installed os
os_install_disk_options = {}
@ -186,8 +188,7 @@ class Data:
# vertical resolution
os_install_x11_height = {'mode':'w'}
# horizontal resolution
os_install_x11_width = {'mode':'w'}
# horizontal resolution os_install_x11_width = {'mode':'w'}
# xorg resolution
os_install_x11_resolution = {}
@ -250,3 +251,12 @@ class Data:
# nt server for system
os_install_ntp = {'mode':'w',
'value':'ntp0.zenon.net'}
# kernel filename
os_install_kernel = {}
# optimized initramfs filename
os_install_initrd = {}
# install initramfs filename
os_install_initrd_install = {}

@ -15,15 +15,36 @@ title #-os_install_linux_name-# #-os_install_arch_machine-# #-os_install_linux_v
#os_install_linux_system#
root (hd#-disk(/boot,grub)-#)
#?os_install_linux_system==desktop#
kernel /boot/vmlinuz root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3,splash=silent,theme:tty1 CONSOLE=/dev/tty1 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
kernel /boot/#-os_install_kernel-# root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3,splash=silent,theme:tty1 CONSOLE=/dev/tty1 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
#os_install_linux_system#
#?os_install_linux_system==server&&os_install_linux_shortname!=CSS#
kernel /boot/vmlinuz root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3,splash=silent,theme:tty1 CONSOLE=/dev/tty1 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
kernel /boot/#-os_install_kernel-# root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3,splash=silent,theme:tty1 CONSOLE=/dev/tty1 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
#os_install_linux_system#
#?os_install_linux_shortname==CSS#
kernel /boot/vmlinuz root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
kernel /boot/#-os_install_kernel-# root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
#os_install_linux_shortname#
initrd /boot/initrd
initrd /boot/#-os_install_initrd-#
#?os_install_linux_system==desktop&&os_install_linux_subname!=#
title #-os_install_linux_name-# #-os_install_arch_machine-# #-os_install_linux_ver-# #-os_install_linux_subname-# Safemode
#os_install_linux_system#
#?os_install_linux_system==desktop&&os_install_linux_subname==#
title #-os_install_linux_name-# #-os_install_arch_machine-# #-os_install_linux_ver-# Safemode
#os_install_linux_system#
#?os_install_linux_system==server#
title #-os_install_linux_name-# #-os_install_arch_machine-# #-os_install_linux_ver-# Safemode
#os_install_linux_system#
root (hd#-disk(/boot,grub)-#)
#?os_install_linux_system==desktop#
kernel /boot/#-os_install_kernel-# root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3,splash=silent,theme:tty1 CONSOLE=/dev/tty1 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
#os_install_linux_system#
#?os_install_linux_system==server&&os_install_linux_shortname!=CSS#
kernel /boot/#-os_install_kernel-# root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3,splash=silent,theme:tty1 CONSOLE=/dev/tty1 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
#os_install_linux_system#
#?os_install_linux_shortname==CSS#
kernel /boot/#-os_install_kernel-# root=#-os_install_root_dev-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3 udev quiet #-os_install_kernel_resume-# elevator=#-os_install_kernel_scheduler-# doscsi#-os_install_kernel_attr-#
#os_install_linux_shortname#
initrd /boot/#-os_install_initrd_install-#
#-grub()-#

Loading…
Cancel
Save