|
|
|
@ -21,24 +21,33 @@ import os
|
|
|
|
|
import re
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
import cl_overriding
|
|
|
|
|
|
|
|
|
|
install_errors = ""
|
|
|
|
|
def installExit(*args,**kwars):
|
|
|
|
|
raise InstallError(globals()["install_errors"])
|
|
|
|
|
|
|
|
|
|
def overprintERROR(s):
|
|
|
|
|
globals()["install_errors"] += s +"\n"
|
|
|
|
|
|
|
|
|
|
cl_overriding.exit = installExit
|
|
|
|
|
cl_overriding.printERROR = overprintERROR
|
|
|
|
|
|
|
|
|
|
from cl_lang import lang
|
|
|
|
|
from cl_template import template
|
|
|
|
|
from cl_fill import clLocale
|
|
|
|
|
from cl_template import template
|
|
|
|
|
from cl_datavars import DataVars
|
|
|
|
|
from cl_print import color_print
|
|
|
|
|
from cl_distr import PartitionDistributive,DistributiveRepository,\
|
|
|
|
|
DistributiveError, ScratchDistributive
|
|
|
|
|
from time import sleep
|
|
|
|
|
import cl_overriding
|
|
|
|
|
from subprocess import Popen,PIPE
|
|
|
|
|
|
|
|
|
|
tr = lang()
|
|
|
|
|
tr.setGlobalDomain('cl_install')
|
|
|
|
|
tr.setLanguage(sys.modules[__name__])
|
|
|
|
|
|
|
|
|
|
def installExit(*args,**kwars):
|
|
|
|
|
raise InstallError("Processing template error")
|
|
|
|
|
|
|
|
|
|
cl_overriding.exit = installExit
|
|
|
|
|
|
|
|
|
|
class InstallError(Exception):
|
|
|
|
|
"""Installation Error"""
|
|
|
|
@ -63,7 +72,7 @@ class cl_install(color_print):
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.clVars = None
|
|
|
|
|
self.clTemp = None
|
|
|
|
|
self.clTempl = None
|
|
|
|
|
self.color = True
|
|
|
|
|
|
|
|
|
|
def colorPrint(self,*argv,**kwarg):
|
|
|
|
@ -85,10 +94,10 @@ class cl_install(color_print):
|
|
|
|
|
def applyTemplatesForSystem(self):
|
|
|
|
|
"""Apply templates for root of system."""
|
|
|
|
|
self.clVars.Set("cl_root_path","/", True)
|
|
|
|
|
self.clTemp = template(self.clVars)
|
|
|
|
|
dirsFiles = self.clTemp.applyTemplates()
|
|
|
|
|
if self.clTemp.getError():
|
|
|
|
|
self.printERROR(self.clTemp.getError())
|
|
|
|
|
self.clTempl = template(self.clVars)
|
|
|
|
|
dirsFiles = self.clTempl.applyTemplates()
|
|
|
|
|
if self.clTempl.getError():
|
|
|
|
|
self.printERROR(self.clTempl.getError())
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
return dirsFiles
|
|
|
|
@ -124,11 +133,8 @@ class cl_install(color_print):
|
|
|
|
|
self.clVars.Get('os_clock_timezone'))
|
|
|
|
|
|
|
|
|
|
self.defaultPrint(_("Location\n"))
|
|
|
|
|
workingVol = filter(lambda x: x[1] == '/',
|
|
|
|
|
zip(self.clVars.Get('os_disk_dev'),
|
|
|
|
|
self.clVars.Get('os_disk_load'))) or [("unknown",)]
|
|
|
|
|
self.printSUCCESS(_("Working volume")+": %s"%
|
|
|
|
|
workingVol[0][0])
|
|
|
|
|
self.getDeviceByField("load",'/') or "unknown" )
|
|
|
|
|
self.printSUCCESS(_("Installation volume")+": %s"%
|
|
|
|
|
self.clVars.Get('os_root_dev'))
|
|
|
|
|
self.printSUCCESS(_("File system")+": %s"%
|
|
|
|
@ -146,7 +152,10 @@ class cl_install(color_print):
|
|
|
|
|
self.printSUCCESS(_("Authentification")+": %s"%
|
|
|
|
|
"<needed>")
|
|
|
|
|
|
|
|
|
|
self.printSUCCESS("Found update: %s"%self.clVars.Get('os_linux_name'))
|
|
|
|
|
self.printSUCCESS("Found update: %s %s %s"%
|
|
|
|
|
(self.clVars.Get('os_linux_name'),
|
|
|
|
|
self.clVars.Get('os_linux_subname'),
|
|
|
|
|
self.clVars.Get('os_linux_ver')))
|
|
|
|
|
|
|
|
|
|
def wait(self,sec=10):
|
|
|
|
|
self.printSUCCESS(_("Press %s to cancel")%"Ctrl+C"+"... %d"%sec, printBR=False)
|
|
|
|
@ -156,7 +165,7 @@ class cl_install(color_print):
|
|
|
|
|
self.defaultPrint("\b\b \n")
|
|
|
|
|
|
|
|
|
|
def prepareBoot(self,targetDistr):
|
|
|
|
|
targetDistr.installBootloader()
|
|
|
|
|
self.installBootloader(targetDistr)
|
|
|
|
|
|
|
|
|
|
def getTargetDistributive(self,disk,buildermode):
|
|
|
|
|
if buildermode:
|
|
|
|
@ -169,14 +178,70 @@ class cl_install(color_print):
|
|
|
|
|
def applyTemplates(self,directory):
|
|
|
|
|
"""Apply templates for root of system."""
|
|
|
|
|
self.clVars.Set("cl_root_path",directory, True)
|
|
|
|
|
self.clTemp = template(self.clVars)
|
|
|
|
|
dirsFiles = self.clTemp.applyTemplates()
|
|
|
|
|
if self.clTemp.getError():
|
|
|
|
|
self.printERROR(self.clTemp.getError())
|
|
|
|
|
return False
|
|
|
|
|
self.clTempl = template(self.clVars)
|
|
|
|
|
dirsFiles = self.clTempl.applyTemplates()
|
|
|
|
|
if self.clTempl.getError():
|
|
|
|
|
raise InstallError(self.clTempl.getError())
|
|
|
|
|
else:
|
|
|
|
|
return dirsFiles
|
|
|
|
|
|
|
|
|
|
def setInstallDisk(self,disk):
|
|
|
|
|
if not disk in self.clVars.Get('os_disk_dev'):
|
|
|
|
|
raise InstallError(_("Wrong target drive name %s"%disk))
|
|
|
|
|
else:
|
|
|
|
|
osdiskload = \
|
|
|
|
|
filter(lambda x: (x[1] or x[2] == "extended") and x[0] == disk,
|
|
|
|
|
zip(self.clVars.Get('os_disk_dev'),
|
|
|
|
|
self.clVars.Get('os_disk_load'),
|
|
|
|
|
self.clVars.Get('os_disk_part')))
|
|
|
|
|
if len(osdiskload) > 0:
|
|
|
|
|
if osdiskload[0][2] == "extended":
|
|
|
|
|
raise InstallError(
|
|
|
|
|
_("Specified drive '%s' is extended"%disk))
|
|
|
|
|
else:
|
|
|
|
|
raise InstallError(
|
|
|
|
|
_("Specified drive '%s' mounted to '%s'")%
|
|
|
|
|
(disk,osdiskload[0][1]))
|
|
|
|
|
else:
|
|
|
|
|
self.clVars.Set('os_root_dev',disk,True)
|
|
|
|
|
|
|
|
|
|
def getDeviceByField(self,field,value):
|
|
|
|
|
"""Get device by fields (install load format uuid grub part name)"""
|
|
|
|
|
return self.getFieldByField('dev',field,value)
|
|
|
|
|
|
|
|
|
|
def getFieldByField(self,resfield,field,value):
|
|
|
|
|
res = filter(lambda x: x[1] == value,
|
|
|
|
|
zip(self.clVars.Get('os_disk_%s'%resfield),
|
|
|
|
|
self.clVars.Get('os_disk_%s'%field))) or [("","")]
|
|
|
|
|
return res[0][0]
|
|
|
|
|
|
|
|
|
|
def getFieldByDevice(self,field,device):
|
|
|
|
|
"""Get value of field by device"""
|
|
|
|
|
device_hash = self.clVars.Get('os_disk_hash')
|
|
|
|
|
if device in device_hash and field in device_hash[device]:
|
|
|
|
|
return device_hash[device][field]
|
|
|
|
|
else:
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
def installBootloader(self,target):
|
|
|
|
|
"""Install boot loader
|
|
|
|
|
|
|
|
|
|
Perform grub installation to disk, which has root partition
|
|
|
|
|
"""
|
|
|
|
|
pipe = Popen(["/sbin/grub",
|
|
|
|
|
"--device-map=%s/boot/grub/device.map"%target.getDirectory(),
|
|
|
|
|
"--batch"], stdin=PIPE, stdout=PIPE,stderr=PIPE)
|
|
|
|
|
pipe.stdin.write("root (hd%s)\n"%
|
|
|
|
|
self.getFieldByField("grub","install","/"))
|
|
|
|
|
# TODO: change hd0 for bootloader install to other disks
|
|
|
|
|
# may be another parameters
|
|
|
|
|
pipe.stdin.write("setup (hd0)\n")
|
|
|
|
|
pipe.stdin.write("quit\n")
|
|
|
|
|
pipe.stdin.close()
|
|
|
|
|
# TODO: break if command is hang (KeyboardInterrupt is supported)
|
|
|
|
|
if pipe.wait() != 0:
|
|
|
|
|
raise DistributiveError("Cann't install bootloader")
|
|
|
|
|
|
|
|
|
|
def installSystem(self,buildermode=False):
|
|
|
|
|
"""install System by current variable enviroment"""
|
|
|
|
|
sourceDistr = None
|
|
|
|
@ -199,7 +264,8 @@ class cl_install(color_print):
|
|
|
|
|
self.wait(waittime)
|
|
|
|
|
# format partition if needed
|
|
|
|
|
self.printSUCCESS(_("Formating partition"))
|
|
|
|
|
targetDistr.formatPartition("reiserfs")
|
|
|
|
|
targetDistr.formatPartition(
|
|
|
|
|
self.getFieldByField("format","install","/") or "reiserfs")
|
|
|
|
|
# install distributive
|
|
|
|
|
self.printSUCCESS(_("Unpacking system image into target"))
|
|
|
|
|
targetDistr.installFrom(sourceDistr)
|
|
|
|
@ -221,16 +287,20 @@ class cl_install(color_print):
|
|
|
|
|
self.printWARNING("Interrupting the installation")
|
|
|
|
|
error = _("Installation manually interrupt")
|
|
|
|
|
try:
|
|
|
|
|
if self.clTempl:
|
|
|
|
|
self.clTempl.closeFiles()
|
|
|
|
|
if sourceDistr:
|
|
|
|
|
self.printSUCCESS(_("Releasing source distributive"))
|
|
|
|
|
sourceDistr.close()
|
|
|
|
|
if targetDistr:
|
|
|
|
|
self.printSUCCESS(_("Unmount target system volume"))
|
|
|
|
|
targetDistr.close()
|
|
|
|
|
except (InstallError,DistributiveError),e:
|
|
|
|
|
error = "%s\n%s" % (str(error),_("Unmouting error"))
|
|
|
|
|
except KeyboardInterrupt,e:
|
|
|
|
|
pass
|
|
|
|
|
if error:
|
|
|
|
|
for line in str(error).split('\n'):
|
|
|
|
|
for line in filter(lambda x: x,str(error).split('\n')):
|
|
|
|
|
self.printERROR(line)
|
|
|
|
|
return False
|
|
|
|
|
self.printSUCCESS(_("System successfully installed"))
|
|
|
|
|