Do not try to set the username if it's None.

This commit is contained in:
Teo Mrnjavac 2015-02-25 17:54:38 +01:00
parent b319cc1da0
commit 67ed53caeb

View File

@ -79,6 +79,11 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
:param default_desktop_environment: :param default_desktop_environment:
:param root_mount_point: :param root_mount_point:
""" """
do_autologin = True
if username is None:
do_autologin = False
if "mdm" in displaymanagers: if "mdm" in displaymanagers:
# Systems with MDM as Desktop Manager # Systems with MDM as Desktop Manager
mdm_conf_path = os.path.join(root_mount_point, "etc/mdm/custom.conf") mdm_conf_path = os.path.join(root_mount_point, "etc/mdm/custom.conf")
@ -91,15 +96,15 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
if do_autologin: if do_autologin:
line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username) line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username)
else: else:
line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=False\n".format(username) line = "[daemon]\nAutomaticLoginEnable=False\n"
mdm_conf.write(line) mdm_conf.write(line)
else: else:
with open(mdm_conf_path, 'w') as mdm_conf: with open(mdm_conf_path, 'w') as mdm_conf:
mdm_conf.write( mdm_conf.write(
'# Calamares - Configure automatic login for user\n') '# Calamares - Configure automatic login for user\n')
mdm_conf.write('[daemon]\n') mdm_conf.write('[daemon]\n')
mdm_conf.write("AutomaticLogin={!s}\n".format(username))
if do_autologin: if do_autologin:
mdm_conf.write("AutomaticLogin={!s}\n".format(username))
mdm_conf.write('AutomaticLoginEnable=True\n') mdm_conf.write('AutomaticLoginEnable=True\n')
else: else:
mdm_conf.write('AutomaticLoginEnable=False\n') mdm_conf.write('AutomaticLoginEnable=False\n')
@ -116,19 +121,19 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
if do_autologin: if do_autologin:
line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username) line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username)
else: else:
line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=False\n".format(username) line = "[daemon]\nAutomaticLoginEnable=False\n"
gdm_conf.write(line) gdm_conf.write(line)
else: else:
with open(gdm_conf_path, 'w') as gdm_conf: with open(gdm_conf_path, 'w') as gdm_conf:
gdm_conf.write( gdm_conf.write(
'# Calamares - Enable automatic login for user\n') '# Calamares - Enable automatic login for user\n')
gdm_conf.write('[daemon]\n') gdm_conf.write('[daemon]\n')
gdm_conf.write("AutomaticLogin={!s}\n".format(username))
if do_autologin: if do_autologin:
gdm_conf.write("AutomaticLogin={!s}\n".format(username))
mdm_conf.write('AutomaticLoginEnable=True\n') mdm_conf.write('AutomaticLoginEnable=True\n')
else: else:
mdm_conf.write('AutomaticLoginEnable=False\n') mdm_conf.write('AutomaticLoginEnable=False\n')
if os.path.exists("{!s}/var/lib/AccountsService/users".format(root_mount_point)): if do_autologin and os.path.exists("{!s}/var/lib/AccountsService/users".format(root_mount_point)):
os.system( os.system(
"echo \"[User]\" > {!s}/var/lib/AccountsService/users/{!s}".format( "echo \"[User]\" > {!s}/var/lib/AccountsService/users/{!s}".format(
root_mount_point, username)) root_mount_point, username))
@ -155,7 +160,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
line = 'AutoLoginEnable=true\n' line = 'AutoLoginEnable=true\n'
else: else:
line = 'AutoLoginEnable=false\n' line = 'AutoLoginEnable=false\n'
if 'AutoLoginUser=' in line: if do_autologin and 'AutoLoginUser=' in line:
line = "AutoLoginUser={!s}\n".format(username) line = "AutoLoginUser={!s}\n".format(username)
kdm_conf.write(line) kdm_conf.write(line)
else: else:
@ -174,7 +179,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
if do_autologin: if do_autologin:
line = "autologin={!s}\n".format(username) line = "autologin={!s}\n".format(username)
else: else:
line = "# autologin={!s}\n".format(username) line = "# autologin=\n"
lxdm_conf.write(line) lxdm_conf.write(line)
else: else:
return "Cannot write LXDM configuration file", "LXDM config file {!s} does not exist".format(lxdm_conf_path) return "Cannot write LXDM configuration file", "LXDM config file {!s} does not exist".format(lxdm_conf_path)
@ -196,7 +201,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
if do_autologin: if do_autologin:
line = "autologin-user={!s}\n".format(username) line = "autologin-user={!s}\n".format(username)
else: else:
line = "#autologin-user={!s}\n".format(username) line = "#autologin-user=\n"
lightdm_conf.write(line) lightdm_conf.write(line)
else: else:
return "Cannot write LightDM configuration file", "LightDM config file {!s} does not exist".format(lightdm_conf_path) return "Cannot write LightDM configuration file", "LightDM config file {!s} does not exist".format(lightdm_conf_path)
@ -215,7 +220,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
line = 'auto_login yes\n' line = 'auto_login yes\n'
else: else:
line = 'auto_login no\n' line = 'auto_login no\n'
if 'default_user' in line: if do_autologin and 'default_user' in line:
line = "default_user {!s}\n".format(username) line = "default_user {!s}\n".format(username)
slim_conf.write(line) slim_conf.write(line)
else: else:
@ -238,7 +243,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
if do_autologin: if do_autologin:
line = 'User={}\n'.format(username) line = 'User={}\n'.format(username)
else: else:
line = '#User={}\n'.format(username) line = '#User=\n'
# Session= line, commented out or with empty value # Session= line, commented out or with empty value
if re.match('\\s*#\\s*Session=|\\s*Session=$', line): if re.match('\\s*#\\s*Session=|\\s*Session=$', line):
if default_desktop_environment is not None: if default_desktop_environment is not None:
@ -402,11 +407,7 @@ def run():
if username is not None: if username is not None:
libcalamares.utils.debug( libcalamares.utils.debug(
"Setting up autologin for user {!s}.".format(username)) "Setting up autologin for user {!s}.".format(username))
return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point, True)
else: else:
libcalamares.utils.debug( libcalamares.utils.debug("Unsetting autologin.")
"Unsetting autologin for user {!s}.".format(username))
return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point, False)
return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point)
return None