Added cmd options '-P' (input users passwords) to cl-install

master3.3
Самоукин Алексей 14 years ago
parent 6a8b151cfc
commit 1281431f20

@ -917,7 +917,9 @@ class fillVars(object, glob_attr):
userData = filter(lambda x:\
reNumb.match(x[2]) and minId<=int(x[2])<=maxId,
userData)
retList = ["root"] +map(lambda x: x[0], userData)
sortUsers = map(lambda x: x[0], userData)
sortUsers.sort()
retList = ["root"] + sortUsers
return retList
def get_cl_migrate_user_pwd(self):

@ -756,12 +756,11 @@ class cl_install(color_print):
def setInstallOptions(self, listDisks, listBinds, listSwaps, listUsers):
"""Set data for installation partitions"""
if listUsers:
migrateUsers = self.clVars.Get('cl_migrate_user')
migrateUsers = list(set(listUsers)|\
set(filter(lambda x: x=="root", migrateUsers)))
migrateUsers = list(set(listUsers))
migrateUsers.sort()
migrateUsers = ["root"] + filter(lambda x: x!="root", migrateUsers)
self.clVars.Set('cl_migrate_user', migrateUsers, force=True)
convObj = convertDictOpt(self.clVars)
try:
listDisks = map(convObj, listDisks)
@ -1128,22 +1127,32 @@ class cl_install(color_print):
return title, headerList, zip(self.clVars.Get('os_install_bind_dir'),
self.clVars.Get('os_install_bind_mountpoint'))
def getPwdHashUser(self, userName):
cl_overriding.printSUCCESS(_("Enter password for user %s") %userName)
try:
userPwd = getUserPassword()
while userPwd is False:
if get_install_errors():
for line in filter(lambda x:x,
pop_install_errors().split('\n')):
self.printERROR(line)
def getPwdHashUser(self, userName, stdinRead=False):
if stdinRead:
try:
userPwd = sys.stdin.readline().rstrip()
except EOFError:
raise KeyboardInterrupt()
else:
cl_overriding.printSUCCESS(_("Enter password for user %s")%userName)
try:
userPwd = getUserPassword()
except EOFError:
raise KeyboardInterrupt()
while userPwd is False:
if get_install_errors():
for line in filter(lambda x:x,
pop_install_errors().split('\n')):
self.printERROR(line)
userPwd = getUserPassword()
except EOFError:
raise KeyboardInterrupt()
encryptObj = encrypt()
if not userPwd:
raise InstallError(_("Unable to find the password for user %s")\
%userName)
return False
pwdHash = encryptObj.getHashPasswd(userPwd, "shadow_ssha256")
if pwdHash is False:
return False
raise InstallError()
return pwdHash
def getNamesAddUsers(self):
@ -1160,21 +1169,21 @@ class cl_install(color_print):
zip(self.clVars.Get("cl_migrate_user"),
self.clVars.Get("cl_migrate_user_pwd"))))
def generateHashUsers(self):
def generateHashUsers(self, stdinRead=False):
"""Generate pwd hash from users"""
addUsers = self.getNamesAddUsers()
users = filter(lambda x: x!="root", addUsers)
listAddUsers = []
for user in users:
hashPwd = self.getPwdHashUser(user)
hashPwd = self.getPwdHashUser(user, stdinRead)
listAddUsers.append((user, hashPwd))
return listAddUsers
def generateHashRoot(self):
def generateHashRoot(self, stdinRead=False):
"""Generate pwd hash from root"""
addUsers = self.getNamesAddUsers()
if filter(lambda x: x=="root", addUsers):
hashPwd = self.getPwdHashUser("root")
hashPwd = self.getPwdHashUser("root", stdinRead)
return [("root", hashPwd,"","")]
else:
return []
@ -1310,13 +1319,22 @@ class cl_install(color_print):
#if not self.clVars.WriteVars(header="install"):
# raise InstallError(self.getError())
def installSystem(self, force=False, bootDisk=None):
def installSystem(self, force=False, bootDisk=None, stdinReadPwd=False):
"""install System by current variable enviroment"""
sourceDistr = None
targetDistr = None
error = None
distrCopy = False
try:
# error in stdin
#if not stdinReadPwd:
#import StringIO
#sys.stdin = StringIO.StringIO()
#sys.stdin.write("no")
#print sys.stdin.read()
#sys.stdin.close()
#if textStdin:
#raise InstallError("incorrect stdin '%s'"%textStdin)
rootPartdev = self.clVars.Get('os_install_root_dev')
rootPartCmdList = filter(lambda x: x['dev']==rootPartdev,
self.listDisksOptions)
@ -1360,15 +1378,10 @@ the system") + " (yes/no)"
elif dialogRes is False:
return True
# set Users passwords
changePwdUsers = self.generateHashRoot()
addUsers = self.generateHashUsers()
changePwdUsers = self.generateHashRoot(stdinRead=stdinReadPwd)
addUsers = self.generateHashUsers(stdinRead=stdinReadPwd)
migrateUsers = self.getNamesMigrateUsers()
#self.wait(waittime)
# cmd options
#self.listDisksOptions
#self.listBindsOptions
#self.listSwapsOptions
noRootPartDisksOptions = filter(lambda x: x['mountPoint']!="/",
self.listDisksOptions)
flagMultipartition = False
@ -1464,6 +1477,8 @@ the system") + " (yes/no)"
self.printByResult(True)
else:
return False
except (EOFError), e:
error = e
except (InstallError,DistributiveError),e:
error = e

@ -81,6 +81,10 @@ CMD_OPTIONS = [{'shortOption':"d",
'optVal':"NTP",
'help':_("set ntp server for system")
},
{'shortOption':"P",
'help':_("use passwords for the users accounts \
(from standard input)")
},
{'longOption':"install",
'help':_("configure the system to install this package")
},
@ -335,9 +339,10 @@ class install_cmd(share_cmd):
else:
return False
def installSystem(self, force=False, bootDisk=None):
def installSystem(self, force=False, bootDisk=None, stdinReadPwd=False):
"""Run install system"""
if self.logicObj.installSystem(force=force, bootDisk=bootDisk):
if self.logicObj.installSystem(force=force, bootDisk=bootDisk,
stdinReadPwd=stdinReadPwd):
return True
else:
return False

@ -69,7 +69,9 @@ if __name__ == "__main__":
if not install.uninstallPackage():
sys.exit(1)
else:
if not install.installSystem(force=options.f, bootDisk=options.mbr):
forceOpions = options.f or options.P
if not install.installSystem(force=forceOpions, bootDisk=options.mbr,
stdinReadPwd=options.P):
sys.exit(1)
#if not install.writeVars(options):
# sys.exit(1)

Loading…
Cancel
Save