Skip to content

Commit

Permalink
Merge pull request #2830 from afbjorklund/gecos
Browse files Browse the repository at this point in the history
Copy the GECOS information for user
  • Loading branch information
jandubois authored Nov 1, 2024
2 parents d6838dd + 9164b9e commit 9fe06aa
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[ "$LIMA_CIDATA_VMTYPE" = "wsl2" ] || exit 0

# create user
sudo useradd -u "${LIMA_CIDATA_UID}" "${LIMA_CIDATA_USER}" -d "${LIMA_CIDATA_HOME}"
sudo useradd -u "${LIMA_CIDATA_UID}" "${LIMA_CIDATA_USER}" -c "${LIMA_CIDATA_GECOS}" -d "${LIMA_CIDATA_HOME}"
sudo mkdir "${LIMA_CIDATA_HOME}"/.ssh/
sudo cp "${LIMA_CIDATA_MNT}"/ssh_authorized_keys "${LIMA_CIDATA_HOME}"/.ssh/authorized_keys
sudo chown "${LIMA_CIDATA_USER}" "${LIMA_CIDATA_HOME}"/.ssh/authorized_keys
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/cidata.TEMPLATE.d/lima.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ LIMA_CIDATA_DEBUG={{ .Debug }}
LIMA_CIDATA_NAME={{ .Name }}
LIMA_CIDATA_USER={{ .User }}
LIMA_CIDATA_UID={{ .UID }}
LIMA_CIDATA_GECOS={{ .GECOS }}
LIMA_CIDATA_HOME={{ .Home}}
LIMA_CIDATA_HOSTHOME_MOUNTPOINT={{ .HostHomeMountPoint }}
LIMA_CIDATA_MOUNTS={{ len .Mounts }}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cidata/cidata.TEMPLATE.d/user-data
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ timezone: {{.TimeZone}}
users:
- name: "{{.User}}"
uid: "{{.UID}}"
{{- if .GECOS }}
gecos: {{ printf "%q" .GECOS }}
{{- end }}
homedir: "{{.Home}}"
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func templateArgs(bootScripts bool, instDir, name string, instConfig *limayaml.L
Hostname: identifierutil.HostnameFromInstName(name), // TODO: support customization
User: u.Username,
UID: uid,
GECOS: u.Name,
Home: fmt.Sprintf("/home/%s.linux", u.Username),
GuestInstallPrefix: *instConfig.GuestInstallPrefix,
UpgradePackages: *instConfig.UpgradePackages,
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type TemplateArgs struct {
Hostname string // instance hostname
IID string // instance id
User string // user name
GECOS string // user information
Home string // home directory
UID int
SSHPubKeys []string
Expand Down
18 changes: 10 additions & 8 deletions pkg/cidata/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ var defaultRemoveDefaults = false

func TestConfig(t *testing.T) {
args := &TemplateArgs{
Name: "default",
User: "foo",
UID: 501,
Home: "/home/foo.linux",
Name: "default",
User: "foo",
UID: 501,
GECOS: "Foo",
Home: "/home/foo.linux",
SSHPubKeys: []string{
"ssh-rsa dummy [email protected]",
},
Expand All @@ -29,10 +30,11 @@ func TestConfig(t *testing.T) {

func TestConfigCACerts(t *testing.T) {
args := &TemplateArgs{
Name: "default",
User: "foo",
UID: 501,
Home: "/home/foo.linux",
Name: "default",
User: "foo",
UID: 501,
GECOS: "Foo",
Home: "/home/foo.linux",
SSHPubKeys: []string{
"ssh-rsa dummy [email protected]",
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/osutil/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type User struct {
Uid uint32
Group string
Gid uint32
Name string // or Comment
Home string
}

Expand Down Expand Up @@ -65,7 +66,7 @@ func LookupUser(name string) (User, error) {
if err != nil {
return User{}, err
}
users[name] = User{User: u.Username, Uid: uid, Group: g.Name, Gid: gid, Home: u.HomeDir}
users[name] = User{User: u.Username, Uid: uid, Group: g.Name, Gid: gid, Name: u.Name, Home: u.HomeDir}
}
return users[name], nil
}
Expand Down
1 change: 1 addition & 0 deletions website/content/en/docs/dev/internals/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ The volume label is "cidata", as defined by [cloud-init NoCloud](https://docs.cl
- `LIMA_CIDATA_MNT`: the mount point of the disk. `/mnt/lima-cidata`.
- `LIMA_CIDATA_USER`: the username string
- `LIMA_CIDATA_UID`: the numeric UID
- `LIMA_CIDATA_GECOS`: the name or comment string
- `LIMA_CIDATA_HOME`: the guest home directory
- `LIMA_CIDATA_HOSTHOME_MOUNTPOINT`: the mount point of the host home directory, or empty if not mounted
- `LIMA_CIDATA_MOUNTS`: the number of the Lima mounts
Expand Down

0 comments on commit 9fe06aa

Please sign in to comment.