|
|
|
#-*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2010 Mir Calculate Ltd. http://www.calculate-linux.org
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
__version__ = "2.2.0"
|
|
|
|
__app__ = "calculate-install"
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from cl_lang import lang
|
|
|
|
from cl_template import template
|
|
|
|
from cl_fill import clLocale
|
|
|
|
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
|
|
|
|
|
|
|
|
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"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
class printNoColor:
|
|
|
|
def colorPrint(self,attr,fg,bg,string):
|
|
|
|
sys.stdout.write(string)
|
|
|
|
|
|
|
|
class DataVarsInstall(DataVars):
|
|
|
|
"""Variable class for installation"""
|
|
|
|
|
|
|
|
def flInstall(self, **args):
|
|
|
|
'''Заполнить конфигурацию переменных, для десктопа'''
|
|
|
|
# Имя секции в calculate.env
|
|
|
|
envSection = "calculate-install"
|
|
|
|
# заполнить переменные окружения алгоритмом по умолнанию
|
|
|
|
self.importData(envSection, ('cl_vars_install','cl_fill_install'))
|
|
|
|
|
|
|
|
class cl_install(color_print):
|
|
|
|
"""Primary class for templates appling and system installation"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.clVars = None
|
|
|
|
self.clTemp = None
|
|
|
|
self.color = True
|
|
|
|
|
|
|
|
def colorPrint(self,*argv,**kwarg):
|
|
|
|
if self.color:
|
|
|
|
color_print.colorPrint(self,*argv,**kwarg)
|
|
|
|
else:
|
|
|
|
sys.stdout.write(argv[-1])
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
def setNoColor(self):
|
|
|
|
self.color = False
|
|
|
|
|
|
|
|
def initVars(self):
|
|
|
|
"""Primary initialization of variables"""
|
|
|
|
self.clVars = DataVarsInstall()
|
|
|
|
self.clVars.flInstall()
|
|
|
|
self.clVars.flIniFile()
|
|
|
|
|
|
|
|
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())
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return dirsFiles
|
|
|
|
|
|
|
|
def printInfo(self,sourceDistr,targetDistr):
|
|
|
|
self.printSUCCESS(_("Installation %s %s")%
|
|
|
|
(self.clVars.Get('os_linux_name'),
|
|
|
|
self.clVars.Get('os_linux_subname')))
|
|
|
|
self.defaultPrint(_("System information\n"))
|
|
|
|
self.printSUCCESS(_("Computer name")+": %s"%
|
|
|
|
self.clVars.Get('os_net_hostname'))
|
|
|
|
self.printSUCCESS(_("Domain name")+": %s"%
|
|
|
|
self.clVars.Get('os_net_domain'))
|
|
|
|
self.printSUCCESS(_("Network devices")+": %s"%
|
|
|
|
self.clVars.Get("os_net_interfaces_info"))
|
|
|
|
self.printSUCCESS(_("Installed system")+": %s %s"%
|
|
|
|
(self.old_os_linux_name, self.old_os_linux_ver))
|
|
|
|
self.defaultPrint(_("Hardware\n"))
|
|
|
|
self.printSUCCESS(_("Machine hardware name")+": %s"%
|
|
|
|
self.clVars.Get('os_arch_machine'))
|
|
|
|
self.printSUCCESS(_("Quantity processors")+": %s(var name)"%
|
|
|
|
self.clVars.Get('hr_cpus'))
|
|
|
|
self.printSUCCESS(_("Videocard")+": %s"%
|
|
|
|
'<needed>')
|
|
|
|
self.printSUCCESS(_("Screen resolution")+": %s"%
|
|
|
|
'<needed>')
|
|
|
|
self.defaultPrint(_("Localization\n"))
|
|
|
|
self.printSUCCESS(_("Language")+": %s"%
|
|
|
|
self.clVars.Get('os_locale_lang'))
|
|
|
|
self.printSUCCESS(_("Keymap")+": %s"%
|
|
|
|
self.clVars.Get('os_locale_xkbname'))
|
|
|
|
self.printSUCCESS(_("Timezone")+": %s"%
|
|
|
|
self.clVars.Get('os_clock_timezone'))
|
|
|
|
|
|
|
|
self.defaultPrint(_("Location\n"))
|
|
|
|
self.printSUCCESS(_("Working volume")+": %s"%
|
|
|
|
self.clVars.Get('os_root_dev'))
|
|
|
|
self.printSUCCESS(_("Installation volume")+": %s"%
|
|
|
|
"<needed>")
|
|
|
|
self.printSUCCESS(_("File system")+": %s"%
|
|
|
|
"<needed>")
|
|
|
|
self.printSUCCESS(_("Swap disk")+": %s"%
|
|
|
|
"<needed>")
|
|
|
|
self.printSUCCESS(_("Mounted disks")+": %s"%
|
|
|
|
"<needed>")
|
|
|
|
|
|
|
|
self.defaultPrint(_("Network services\n"))
|
|
|
|
self.printSUCCESS(_("PROXY")+": %s"%
|
|
|
|
"<needed>")
|
|
|
|
self.printSUCCESS(_("NTP")+": %s"%
|
|
|
|
"<needed>")
|
|
|
|
self.printSUCCESS(_("Authentification")+": %s"%
|
|
|
|
"<needed>")
|
|
|
|
|
|
|
|
self.printSUCCESS("Found update: %s"%self.clVars.Get('os_linux_name'))
|
|
|
|
|
|
|
|
def wait(self,sec=10):
|
|
|
|
self.printSUCCESS(_("Press %s to cancel")%"Ctrl+C"+"... %d"%sec, printBR=False)
|
|
|
|
for i in xrange(sec,0,-1):
|
|
|
|
self.defaultPrint("\a\b\b %d" % i)
|
|
|
|
sleep(1)
|
|
|
|
self.defaultPrint("\b\b \n")
|
|
|
|
|
|
|
|
def prepareBoot(self,targetDistr):
|
|
|
|
targetDistr.installBootloader()
|
|
|
|
|
|
|
|
def getTargetDistributive(self,disk,buildermode):
|
|
|
|
if buildermode:
|
|
|
|
return ScratchDistributive(disk,mdirectory="/mnt/install",
|
|
|
|
check=True)
|
|
|
|
else:
|
|
|
|
return PartitionDistributive(disk,mdirectory="/mnt/install",
|
|
|
|
check=True)
|
|
|
|
|
|
|
|
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
|
|
|
|
else:
|
|
|
|
return dirsFiles
|
|
|
|
|
|
|
|
def installSystem(self,disk="",buildermode=False,osname=None):
|
|
|
|
"""install System by current variable enviroment"""
|
|
|
|
sourceDistr = None
|
|
|
|
targetDistr = None
|
|
|
|
error = None
|
|
|
|
try:
|
|
|
|
targetDistr = self.getTargetDistributive(disk,buildermode)
|
|
|
|
distRep = DistributiveRepository('/usr/calculate/share/linux')
|
|
|
|
self.old_os_linux_name = self.clVars.Get('os_linux_shortname')
|
|
|
|
self.old_os_linux_ver = self.clVars.Get('os_linux_ver')
|
|
|
|
if osname:
|
|
|
|
self.clVars.Set('os_linux_shortname',osname.upper())
|
|
|
|
sourceDistr = distRep.getLastDistributive(
|
|
|
|
march=self.clVars.Get('os_arch_machine'),
|
|
|
|
shortname=self.clVars.Get('os_linux_shortname').lower())
|
|
|
|
if sourceDistr:
|
|
|
|
# print info
|
|
|
|
self.printInfo(sourceDistr,targetDistr)
|
|
|
|
# wait 10 sec
|
|
|
|
waittime = 3
|
|
|
|
self.printSUCCESS(_("Installation will start pass %d seconds.")
|
|
|
|
%waittime)
|
|
|
|
self.wait(waittime)
|
|
|
|
# format partition if needed
|
|
|
|
self.printSUCCESS(_("Formating partition"))
|
|
|
|
targetDistr.formatPartition("reiserfs")
|
|
|
|
# install distributive
|
|
|
|
self.printSUCCESS(_("Unpacking system image into target"))
|
|
|
|
targetDistr.installFrom(sourceDistr)
|
|
|
|
self.printOK("Unpacking complete")
|
|
|
|
# join templates
|
|
|
|
self.printSUCCESS(_("Update config"))
|
|
|
|
self.applyTemplates(targetDistr.getDirectory())
|
|
|
|
# change boot config
|
|
|
|
self.printSUCCESS(_("Prepare system for reboot"))
|
|
|
|
self.prepareBoot(targetDistr)
|
|
|
|
else:
|
|
|
|
self.printWARNING("No update available.")
|
|
|
|
return False
|
|
|
|
|
|
|
|
except (InstallError,DistributiveError),e:
|
|
|
|
error = e
|
|
|
|
except KeyboardInterrupt,e:
|
|
|
|
self.defaultPrint("\n")
|
|
|
|
self.printWARNING("Interrupting the installation")
|
|
|
|
error = _("Installation manually interrupt")
|
|
|
|
try:
|
|
|
|
if sourceDistr:
|
|
|
|
self.printSUCCESS(_("Releasing source distributive"))
|
|
|
|
sourceDistr.close()
|
|
|
|
if targetDistr:
|
|
|
|
self.printSUCCESS(_("Unmount target system volume"))
|
|
|
|
targetDistr.close()
|
|
|
|
except KeyboardInterrupt,e:
|
|
|
|
pass
|
|
|
|
if error:
|
|
|
|
for line in str(error).split('\n'):
|
|
|
|
self.printERROR(line)
|
|
|
|
return False
|
|
|
|
self.printSUCCESS(_("System successfully installed"))
|
|
|
|
return False
|
|
|
|
|
|
|
|
def setAllLocaleByLang(self,lang):
|
|
|
|
"""Set all locale variable by specified lang"""
|
|
|
|
locale = clLocale()
|
|
|
|
if not locale.isLangExists(lang):
|
|
|
|
return False
|
|
|
|
self.clVars.Set('os_locale_lang',lang, True)
|
|
|
|
self.clVars.Set('os_locale_locale',
|
|
|
|
locale.getFieldByLang('locale',lang), True)
|
|
|
|
self.clVars.Set('os_locale_language',
|
|
|
|
locale.getFieldByLang('language',lang), True)
|
|
|
|
self.clVars.Set('os_locale_keymap',
|
|
|
|
locale.getFieldByLang('keymap',lang), True)
|
|
|
|
self.clVars.Set('os_locale_dumpkeys',
|
|
|
|
locale.getFieldByLang('dumpkeys_charset',lang), True)
|
|
|
|
self.clVars.Set('os_locale_xkb',
|
|
|
|
locale.getFieldByLang('xkblayout',lang), True)
|
|
|
|
return True
|