|
|
|
@ -22,10 +22,13 @@ from cl_install import cl_install, InstallError, __app__, __version__,\
|
|
|
|
|
from cl_vars_share import varsShare
|
|
|
|
|
from cl_opt import opt
|
|
|
|
|
from cl_share_cmd import share_cmd
|
|
|
|
|
from utils import ip as iputils
|
|
|
|
|
from cl_utils import isPkgInstalled
|
|
|
|
|
|
|
|
|
|
from cl_lang import lang
|
|
|
|
|
lang().setLanguage(sys.modules[__name__])
|
|
|
|
|
OSSYSTEM_LIST=sorted(varsShare.dictNameSystem.keys())
|
|
|
|
|
NM_LIST=sorted(varsShare.dictNetworkManagers.keys())
|
|
|
|
|
|
|
|
|
|
DESCRIPTION = _("The Calculate Linux installation and configuration utility")
|
|
|
|
|
CMD_OPTIONS = [{'shortOption':"d",
|
|
|
|
@ -90,6 +93,27 @@ CMD_OPTIONS = [{'shortOption':"d",
|
|
|
|
|
'optVal':"HOSTNAME",
|
|
|
|
|
'help':_("set short hostname of full hostname")
|
|
|
|
|
},
|
|
|
|
|
{'longOption':"netsetup",
|
|
|
|
|
'optVal':"NETMANAGER",
|
|
|
|
|
'type':'choice',
|
|
|
|
|
'choices_regignore': NM_LIST,
|
|
|
|
|
'help':_("network manager (%s)"%
|
|
|
|
|
"%s or %s" % (",".join(NM_LIST[0:-1]),NM_LIST[-1]))},
|
|
|
|
|
{'longOption':"dhcp",
|
|
|
|
|
'help':_("get ip address by %s")%"DHCP"
|
|
|
|
|
},
|
|
|
|
|
{'longOption':"ip",
|
|
|
|
|
'optVal':"IP",
|
|
|
|
|
'help':_("ip address with net (example:%s)")%"192.168.1.1/24"
|
|
|
|
|
},
|
|
|
|
|
{'longOption':"dns",
|
|
|
|
|
'optVal':"DNS",
|
|
|
|
|
'help':_("domain name servers (comma delimeter)")
|
|
|
|
|
},
|
|
|
|
|
{'longOption':"gateway",
|
|
|
|
|
'optVal':"GATEWAY",
|
|
|
|
|
'help':_("default gateway")
|
|
|
|
|
},
|
|
|
|
|
{'longOption':"proxy",
|
|
|
|
|
'optVal':"PROXY",
|
|
|
|
|
'help':_("set proxy server for system")
|
|
|
|
@ -126,6 +150,9 @@ CMD_OPTIONS = [{'shortOption':"d",
|
|
|
|
|
(from standard input)")
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
class OptException(Exception):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
class install_cmd(share_cmd):
|
|
|
|
|
"""Class for work with cl_install by console"""
|
|
|
|
|
def __init__(self):
|
|
|
|
@ -143,6 +170,7 @@ class install_cmd(share_cmd):
|
|
|
|
|
# names incompatible options with --live
|
|
|
|
|
self.optionsLiveIncompatible = ["type","d", "b", "mbr",
|
|
|
|
|
"w", "f","U", "s","install","uninstall","build","u"]
|
|
|
|
|
self.optionsDhcpIncompatible = ["ip","gateway","dns"]
|
|
|
|
|
|
|
|
|
|
def _getNamesAllSetOptions(self):
|
|
|
|
|
"""Get list set options"""
|
|
|
|
@ -165,6 +193,14 @@ class install_cmd(share_cmd):
|
|
|
|
|
self.optobj.error(_("incompatible options")+":"+" %s"\
|
|
|
|
|
%self.getStringIncompatibleOptions(incompatible+["live"]))
|
|
|
|
|
|
|
|
|
|
def checkIncompatibleDhcp(self):
|
|
|
|
|
"""Check incompatible options for option --dchp"""
|
|
|
|
|
incompatible = list(set(self._getNamesAllSetOptions()) &
|
|
|
|
|
set(self.optionsDhcpIncompatible))
|
|
|
|
|
if incompatible:
|
|
|
|
|
self.optobj.error(_("incompatible options")+":"+" %s"\
|
|
|
|
|
%self.getStringIncompatibleOptions(incompatible+["dhcp"]))
|
|
|
|
|
|
|
|
|
|
def checkIncompatibleInstallUninstall(self):
|
|
|
|
|
"""Check incompatible options for options --install and --uninstall"""
|
|
|
|
|
opts = self._getNamesAllSetOptions()
|
|
|
|
@ -180,17 +216,32 @@ class install_cmd(share_cmd):
|
|
|
|
|
self.checkIncompatibleInstallUninstall()
|
|
|
|
|
if values.live:
|
|
|
|
|
self.checkIncompatibleLive()
|
|
|
|
|
if values.dhcp:
|
|
|
|
|
self.checkIncompatibleDhcp()
|
|
|
|
|
if not values.v:
|
|
|
|
|
if values.filter:
|
|
|
|
|
errMsg = _("incorrect option") + ":" + " %s" %"--filter" +\
|
|
|
|
|
": " + _("use with option '-v'")
|
|
|
|
|
self.optobj.error(errMsg)
|
|
|
|
|
return False
|
|
|
|
|
if values.xml:
|
|
|
|
|
errMsg = _("incorrect option") + ":" + " %s" %"--xml" +\
|
|
|
|
|
": " + _("use with option '-v'")
|
|
|
|
|
self.optobj.error(errMsg)
|
|
|
|
|
return False
|
|
|
|
|
if values.ip:
|
|
|
|
|
if not re.match("^%s$"%iputils.IP_ADDR_NET,values.ip):
|
|
|
|
|
self.optobj.error(_("option %s:") %"--ip" +\
|
|
|
|
|
" " + _("ip specifing error: '%s'") %\
|
|
|
|
|
values.ip)
|
|
|
|
|
if values.dns:
|
|
|
|
|
if not re.match("^{0}(,{0})*$".format(iputils.IP_ADDR),values.dns):
|
|
|
|
|
self.optobj.error(_("option %s:") %"--dns" +\
|
|
|
|
|
" " + _("dns specifing error: '%s'") %\
|
|
|
|
|
values.dns)
|
|
|
|
|
if values.gateway:
|
|
|
|
|
if not iputils.checkIp(values.gateway):
|
|
|
|
|
self.optobj.error(_("option %s:") %"--gateway" +\
|
|
|
|
|
" " + _("gateway specifing error: '%s'") %\
|
|
|
|
|
values.gateway)
|
|
|
|
|
if not (values.install or values.uninstall or values.live):
|
|
|
|
|
if values.v is False and \
|
|
|
|
|
values.d is None and \
|
|
|
|
@ -221,7 +272,6 @@ class install_cmd(share_cmd):
|
|
|
|
|
self.optobj.error(_("option %s:") %"w" +\
|
|
|
|
|
" " + _("mount bind specifing error: '%s'")\
|
|
|
|
|
%", ".join(wrongValue))
|
|
|
|
|
|
|
|
|
|
#check boot device
|
|
|
|
|
if values.mbr:
|
|
|
|
|
bootDisk = values.mbr
|
|
|
|
@ -229,7 +279,6 @@ class install_cmd(share_cmd):
|
|
|
|
|
if not reBootDisk.match(bootDisk):
|
|
|
|
|
self.optobj.error(_("option %s:") %"mbr" + " " +\
|
|
|
|
|
_("disk specifing error: '%s'")%bootDisk)
|
|
|
|
|
|
|
|
|
|
# check syntax --set
|
|
|
|
|
self.optobj.checkVarSyntax(values)
|
|
|
|
|
return (values, args)
|
|
|
|
@ -244,24 +293,58 @@ class install_cmd(share_cmd):
|
|
|
|
|
|
|
|
|
|
def setProxyNtpHostname(self,proxy,ntp,hostname):
|
|
|
|
|
"""Process set locales by lang"""
|
|
|
|
|
getVar = self.logicObj.clVars.Get
|
|
|
|
|
setVar = self.logicObj.clVars.Set
|
|
|
|
|
setWriteVar = self.logicObj.clVars.SetWriteVar
|
|
|
|
|
if proxy:
|
|
|
|
|
if not self.logicObj.clVars.SetWriteVar('os_install_proxy',proxy):
|
|
|
|
|
if not setWriteVar('os_install_proxy',proxy):
|
|
|
|
|
self.printERROR(get_install_errors(),printBR=False)
|
|
|
|
|
return False
|
|
|
|
|
if ntp:
|
|
|
|
|
if not self.logicObj.clVars.SetWriteVar('os_install_ntp',ntp):
|
|
|
|
|
if not setWriteVar('os_install_ntp',ntp):
|
|
|
|
|
self.printERROR(get_install_errors(),printBR=False)
|
|
|
|
|
return False
|
|
|
|
|
if hostname:
|
|
|
|
|
if "." in hostname:
|
|
|
|
|
hostname, op, domain = hostname.partition('.')
|
|
|
|
|
self.logicObj.clVars.Set('os_install_net_hostname',
|
|
|
|
|
hostname,True)
|
|
|
|
|
self.logicObj.clVars.Set('os_install_net_domain',
|
|
|
|
|
domain,True)
|
|
|
|
|
setVar('os_install_net_hostname', hostname,True)
|
|
|
|
|
setVar('os_install_net_domain', domain,True)
|
|
|
|
|
dns_search = getVar("os_install_net_dns_search")
|
|
|
|
|
if not domain in dns_search:
|
|
|
|
|
setVar("os_install_net_dns_search",domain,True)
|
|
|
|
|
else:
|
|
|
|
|
self.logicObj.clVars.Set('os_install_net_hostname',
|
|
|
|
|
hostname,True)
|
|
|
|
|
setVar('os_install_net_hostname', hostname,True)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def setNetworkParams(self,ipaddr,gateway,dns,setup,dhcp):
|
|
|
|
|
"""Set nework params"""
|
|
|
|
|
#if dhcp:
|
|
|
|
|
# self.logicObj.clVars.Set("os_install_net_dhcp_set","on",True)
|
|
|
|
|
# return True
|
|
|
|
|
#if ipaddr:
|
|
|
|
|
# self.logicObj.clVars.Set("os_install_net_dhcp_set","off",True)
|
|
|
|
|
# ip,op,net = ipaddr.partition('/')
|
|
|
|
|
# mask = iputils.netToMask(int(net))
|
|
|
|
|
# self.logicObj.clVars.Set("os_install_net_ip",ip,True)
|
|
|
|
|
# self.logicObj.clVars.Set("os_install_net_mask", mask,True)
|
|
|
|
|
#else:
|
|
|
|
|
# ip = self.logicObj.clVars.Get("os_install_net_ip")
|
|
|
|
|
# mask = self.logicObj.clVars.Get("os_install_net_mask")
|
|
|
|
|
# ipaddr = "{ip}/{net}".format(ip=ip, net=iputils.maskToNet(mask))
|
|
|
|
|
#if gateway:
|
|
|
|
|
# if not iputils.isIpInNet(gateway,ipaddr):
|
|
|
|
|
# self.printERROR(
|
|
|
|
|
# _("Specified gateway is unreachable for net %s")%
|
|
|
|
|
# iputils.getIpNet(ip,mask))
|
|
|
|
|
# return False
|
|
|
|
|
# self.logicObj.clVars.Set("os_install_net_ip",gateway,True)
|
|
|
|
|
#if dns:
|
|
|
|
|
# self.logicObj.clVars.Set("os_install_net_dns",dns,True)
|
|
|
|
|
#if setup:
|
|
|
|
|
# if not isPkgInstalled(setup):
|
|
|
|
|
# self.printERROR(_("Network manager %s is not installed")%setup)
|
|
|
|
|
# return False
|
|
|
|
|
# self.logicObj.clVars.Set("os_install_net_setup",setup,True)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def setVars(self,options):
|
|
|
|
@ -301,6 +384,7 @@ class install_cmd(share_cmd):
|
|
|
|
|
if self.optobj.values.type:
|
|
|
|
|
self.logicObj.clVars.Set('os_install_root_type',
|
|
|
|
|
self.optobj.values.type, True)
|
|
|
|
|
|
|
|
|
|
listDiskOptions = []
|
|
|
|
|
listBindOptions = []
|
|
|
|
|
listSwapOptions = []
|
|
|
|
|