only add the user to groups that exist in the target system
for https://bugs.launchpad.net/subiquity/+bug/1775228 ("user is in debian-tor group on fresh install")
This commit is contained in:
parent
2f184ce9a6
commit
ad17c530b0
|
@ -20,6 +20,7 @@ import yaml
|
||||||
|
|
||||||
from subiquitycore.models.identity import IdentityModel
|
from subiquitycore.models.identity import IdentityModel
|
||||||
from subiquitycore.models.network import NetworkModel
|
from subiquitycore.models.network import NetworkModel
|
||||||
|
from subiquitycore.utils import run_command
|
||||||
|
|
||||||
from .filesystem import FilesystemModel
|
from .filesystem import FilesystemModel
|
||||||
from .installpath import InstallpathModel
|
from .installpath import InstallpathModel
|
||||||
|
@ -41,12 +42,24 @@ def setup_yaml():
|
||||||
setup_yaml()
|
setup_yaml()
|
||||||
|
|
||||||
|
|
||||||
|
def get_all_groups(dry_run):
|
||||||
|
command = ['chroot', '/target', 'getent', 'group']
|
||||||
|
if dry_run:
|
||||||
|
del command[:2]
|
||||||
|
cp = run_command(command, check=True)
|
||||||
|
groups = set()
|
||||||
|
for line in cp.stdout.splitlines():
|
||||||
|
groups.add(line.split(':')[0])
|
||||||
|
return groups
|
||||||
|
|
||||||
|
|
||||||
class SubiquityModel:
|
class SubiquityModel:
|
||||||
"""The overall model for subiquity."""
|
"""The overall model for subiquity."""
|
||||||
|
|
||||||
def __init__(self, common):
|
def __init__(self, common):
|
||||||
root = '/'
|
root = '/'
|
||||||
if common['opts'].dry_run:
|
self.opts = common['opts']
|
||||||
|
if self.opts.dry_run:
|
||||||
root = os.path.abspath(".subiquity")
|
root = os.path.abspath(".subiquity")
|
||||||
self.locale = LocaleModel(common['signal'])
|
self.locale = LocaleModel(common['signal'])
|
||||||
self.keyboard = KeyboardModel(root)
|
self.keyboard = KeyboardModel(root)
|
||||||
|
@ -61,13 +74,15 @@ class SubiquityModel:
|
||||||
def _cloud_init_config(self):
|
def _cloud_init_config(self):
|
||||||
user = self.identity.user
|
user = self.identity.user
|
||||||
users_and_groups_path = (
|
users_and_groups_path = (
|
||||||
os.path.join(os.environ.get("SNAP", "/does-not-exist"),
|
os.path.join(os.environ.get("SNAP", "."),
|
||||||
"users-and-groups"))
|
"users-and-groups"))
|
||||||
if os.path.exists(users_and_groups_path):
|
if os.path.exists(users_and_groups_path):
|
||||||
groups = open(users_and_groups_path).read().split()
|
groups = open(users_and_groups_path).read().split()
|
||||||
else:
|
else:
|
||||||
groups = ['admin']
|
groups = ['admin']
|
||||||
groups.append('sudo')
|
groups.append('sudo')
|
||||||
|
all_groups = get_all_groups(self.opts.dry_run)
|
||||||
|
groups = [group for group in groups if group in all_groups]
|
||||||
user_info = {
|
user_info = {
|
||||||
'name': user.username,
|
'name': user.username,
|
||||||
'gecos': user.realname,
|
'gecos': user.realname,
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
adm cdrom dip lpadmin plugdev sambashare debian-tor libvirtd lxd
|
Loading…
Reference in New Issue