Skip to content

Commit 9fe06aa

Browse files
authored
Merge pull request #2830 from afbjorklund/gecos
Copy the GECOS information for user
2 parents d6838dd + 9164b9e commit 9fe06aa

File tree

8 files changed

+20
-10
lines changed

8 files changed

+20
-10
lines changed

Diff for: pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[ "$LIMA_CIDATA_VMTYPE" = "wsl2" ] || exit 0
55

66
# create user
7-
sudo useradd -u "${LIMA_CIDATA_UID}" "${LIMA_CIDATA_USER}" -d "${LIMA_CIDATA_HOME}"
7+
sudo useradd -u "${LIMA_CIDATA_UID}" "${LIMA_CIDATA_USER}" -c "${LIMA_CIDATA_GECOS}" -d "${LIMA_CIDATA_HOME}"
88
sudo mkdir "${LIMA_CIDATA_HOME}"/.ssh/
99
sudo cp "${LIMA_CIDATA_MNT}"/ssh_authorized_keys "${LIMA_CIDATA_HOME}"/.ssh/authorized_keys
1010
sudo chown "${LIMA_CIDATA_USER}" "${LIMA_CIDATA_HOME}"/.ssh/authorized_keys

Diff for: pkg/cidata/cidata.TEMPLATE.d/lima.env

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ LIMA_CIDATA_DEBUG={{ .Debug }}
22
LIMA_CIDATA_NAME={{ .Name }}
33
LIMA_CIDATA_USER={{ .User }}
44
LIMA_CIDATA_UID={{ .UID }}
5+
LIMA_CIDATA_GECOS={{ .GECOS }}
56
LIMA_CIDATA_HOME={{ .Home}}
67
LIMA_CIDATA_HOSTHOME_MOUNTPOINT={{ .HostHomeMountPoint }}
78
LIMA_CIDATA_MOUNTS={{ len .Mounts }}

Diff for: pkg/cidata/cidata.TEMPLATE.d/user-data

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ timezone: {{.TimeZone}}
3030
users:
3131
- name: "{{.User}}"
3232
uid: "{{.UID}}"
33+
{{- if .GECOS }}
34+
gecos: {{ printf "%q" .GECOS }}
35+
{{- end }}
3336
homedir: "{{.Home}}"
3437
shell: /bin/bash
3538
sudo: ALL=(ALL) NOPASSWD:ALL

Diff for: pkg/cidata/cidata.go

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func templateArgs(bootScripts bool, instDir, name string, instConfig *limayaml.L
132132
Hostname: identifierutil.HostnameFromInstName(name), // TODO: support customization
133133
User: u.Username,
134134
UID: uid,
135+
GECOS: u.Name,
135136
Home: fmt.Sprintf("/home/%s.linux", u.Username),
136137
GuestInstallPrefix: *instConfig.GuestInstallPrefix,
137138
UpgradePackages: *instConfig.UpgradePackages,

Diff for: pkg/cidata/template.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type TemplateArgs struct {
5959
Hostname string // instance hostname
6060
IID string // instance id
6161
User string // user name
62+
GECOS string // user information
6263
Home string // home directory
6364
UID int
6465
SSHPubKeys []string

Diff for: pkg/cidata/template_test.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ var defaultRemoveDefaults = false
1212

1313
func TestConfig(t *testing.T) {
1414
args := &TemplateArgs{
15-
Name: "default",
16-
User: "foo",
17-
UID: 501,
18-
Home: "/home/foo.linux",
15+
Name: "default",
16+
User: "foo",
17+
UID: 501,
18+
GECOS: "Foo",
19+
Home: "/home/foo.linux",
1920
SSHPubKeys: []string{
2021
"ssh-rsa dummy [email protected]",
2122
},
@@ -29,10 +30,11 @@ func TestConfig(t *testing.T) {
2930

3031
func TestConfigCACerts(t *testing.T) {
3132
args := &TemplateArgs{
32-
Name: "default",
33-
User: "foo",
34-
UID: 501,
35-
Home: "/home/foo.linux",
33+
Name: "default",
34+
User: "foo",
35+
UID: 501,
36+
GECOS: "Foo",
37+
Home: "/home/foo.linux",
3638
SSHPubKeys: []string{
3739
"ssh-rsa dummy [email protected]",
3840
},

Diff for: pkg/osutil/user.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type User struct {
1919
Uid uint32
2020
Group string
2121
Gid uint32
22+
Name string // or Comment
2223
Home string
2324
}
2425

@@ -65,7 +66,7 @@ func LookupUser(name string) (User, error) {
6566
if err != nil {
6667
return User{}, err
6768
}
68-
users[name] = User{User: u.Username, Uid: uid, Group: g.Name, Gid: gid, Home: u.HomeDir}
69+
users[name] = User{User: u.Username, Uid: uid, Group: g.Name, Gid: gid, Name: u.Name, Home: u.HomeDir}
6970
}
7071
return users[name], nil
7172
}

Diff for: website/content/en/docs/dev/internals/_index.md

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ The volume label is "cidata", as defined by [cloud-init NoCloud](https://docs.cl
179179
- `LIMA_CIDATA_MNT`: the mount point of the disk. `/mnt/lima-cidata`.
180180
- `LIMA_CIDATA_USER`: the username string
181181
- `LIMA_CIDATA_UID`: the numeric UID
182+
- `LIMA_CIDATA_GECOS`: the name or comment string
182183
- `LIMA_CIDATA_HOME`: the guest home directory
183184
- `LIMA_CIDATA_HOSTHOME_MOUNTPOINT`: the mount point of the host home directory, or empty if not mounted
184185
- `LIMA_CIDATA_MOUNTS`: the number of the Lima mounts

0 commit comments

Comments
 (0)