Merge pull request #360 from sil2100/console-conf-core-version
console-conf identity: do not hard-code the core version
This commit is contained in:
commit
0d95adb89e
|
@ -16,6 +16,7 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from subiquitycore.controller import BaseController
|
from subiquitycore.controller import BaseController
|
||||||
|
@ -26,6 +27,28 @@ from console_conf.ui.views import IdentityView, LoginView
|
||||||
log = logging.getLogger('console_conf.controllers.identity')
|
log = logging.getLogger('console_conf.controllers.identity')
|
||||||
|
|
||||||
|
|
||||||
|
def get_core_version():
|
||||||
|
""" For a ubuntu-core system, return its version or None """
|
||||||
|
|
||||||
|
path = "/usr/lib/os-release"
|
||||||
|
try:
|
||||||
|
with open(path, "r") as fp:
|
||||||
|
content = fp.read()
|
||||||
|
except FileNotFoundError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
version = None
|
||||||
|
for line in shlex.split(content):
|
||||||
|
key, _, value = line.partition("=")
|
||||||
|
if key == "ID" and value != "ubuntu-core":
|
||||||
|
return None
|
||||||
|
if key == "VERSION_ID":
|
||||||
|
version = value
|
||||||
|
break
|
||||||
|
|
||||||
|
return version
|
||||||
|
|
||||||
|
|
||||||
def get_device_owner():
|
def get_device_owner():
|
||||||
""" Check if device is owned """
|
""" Check if device is owned """
|
||||||
|
|
||||||
|
@ -106,7 +129,7 @@ def host_key_info():
|
||||||
|
|
||||||
|
|
||||||
login_details_tmpl = """\
|
login_details_tmpl = """\
|
||||||
Ubuntu Core 16 on {first_ip} ({tty_name})
|
Ubuntu Core {version} on {first_ip} ({tty_name})
|
||||||
{host_key_info}
|
{host_key_info}
|
||||||
To login:
|
To login:
|
||||||
{sshcommands}
|
{sshcommands}
|
||||||
|
@ -115,7 +138,7 @@ Personalize your account at https://login.ubuntu.com.
|
||||||
|
|
||||||
|
|
||||||
login_details_tmpl_no_ip = """\
|
login_details_tmpl_no_ip = """\
|
||||||
Ubuntu Core 16 on <no ip address> ({tty_name})
|
Ubuntu Core {version} on <no ip address> ({tty_name})
|
||||||
|
|
||||||
You cannot log in until the system has an IP address. (Is there
|
You cannot log in until the system has an IP address. (Is there
|
||||||
supposed to be a DHCP server running on your network?)
|
supposed to be a DHCP server running on your network?)
|
||||||
|
@ -129,15 +152,17 @@ def write_login_details(fp, username, ips):
|
||||||
for ip in ips:
|
for ip in ips:
|
||||||
sshcommands += " ssh %s@%s\n" % (username, ip)
|
sshcommands += " ssh %s@%s\n" % (username, ip)
|
||||||
tty_name = os.ttyname(0)[5:] # strip off the /dev/
|
tty_name = os.ttyname(0)[5:] # strip off the /dev/
|
||||||
|
version = get_core_version() or "16"
|
||||||
if len(ips) == 0:
|
if len(ips) == 0:
|
||||||
fp.write(login_details_tmpl_no_ip.format(
|
fp.write(login_details_tmpl_no_ip.format(
|
||||||
sshcommands=sshcommands, tty_name=tty_name))
|
sshcommands=sshcommands, tty_name=tty_name, version=version))
|
||||||
else:
|
else:
|
||||||
first_ip = ips[0]
|
first_ip = ips[0]
|
||||||
fp.write(login_details_tmpl.format(sshcommands=sshcommands,
|
fp.write(login_details_tmpl.format(sshcommands=sshcommands,
|
||||||
host_key_info=host_key_info(),
|
host_key_info=host_key_info(),
|
||||||
tty_name=tty_name,
|
tty_name=tty_name,
|
||||||
first_ip=first_ip))
|
first_ip=first_ip,
|
||||||
|
version=version))
|
||||||
|
|
||||||
|
|
||||||
def write_login_details_standalone():
|
def write_login_details_standalone():
|
||||||
|
@ -162,11 +187,9 @@ def write_login_details_standalone():
|
||||||
ips.append(addr.ip)
|
ips.append(addr.ip)
|
||||||
if len(ips) == 0:
|
if len(ips) == 0:
|
||||||
tty_name = os.ttyname(0)[5:]
|
tty_name = os.ttyname(0)[5:]
|
||||||
print("Ubuntu Core 16 on <no ip address> ({})".format(tty_name))
|
version = get_core_version() or "16"
|
||||||
print()
|
print(login_details_tmpl_no_ip.format(tty_name=tty_name,
|
||||||
print("You cannot log in until the system has an IP address.")
|
version=version))
|
||||||
print("(Is there supposed to be a DHCP server running on "
|
|
||||||
"your network?)")
|
|
||||||
return 2
|
return 2
|
||||||
write_login_details(sys.stdout, owner['username'], ips)
|
write_login_details(sys.stdout, owner['username'], ips)
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in New Issue