Skip to content

Commit ab3142b

Browse files
authored
Merge pull request #1736 from afbjorklund/guest-home
Add variable for the guest home directory
2 parents 52558fe + b9e5e65 commit ab3142b

11 files changed

+25
-16
lines changed

docs/internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ The volume label is "cidata", as defined by [cloud-init NoCloud](https://cloudin
151151
- `LIMA_CIDATA_MNT`: the mount point of the disk. `/mnt/lima-cidata`.
152152
- `LIMA_CIDATA_USER`: the user name string
153153
- `LIMA_CIDATA_UID`: the numeric UID
154+
- `LIMA_CIDATA_HOME`: the guest home directory
154155
- `LIMA_CIDATA_HOSTHOME_MOUNTPOINT`: the mount point of the host home directory, or empty if not mounted
155156
- `LIMA_CIDATA_MOUNTS`: the number of the Lima mounts
156157
- `LIMA_CIDATA_MOUNTS_%d_MOUNTPOINT`: the N-th mount point of Lima mounts (N=0, 1, ...)

pkg/cidata/cidata.TEMPLATE.d/boot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [ -d "${LIMA_CIDATA_MNT}"/provision.system ]; then
5252
done
5353
fi
5454

55-
USER_SCRIPT="/home/${LIMA_CIDATA_USER}.linux/.lima-user-script"
55+
USER_SCRIPT="${LIMA_CIDATA_HOME}/.lima-user-script"
5656
if [ -d "${LIMA_CIDATA_MNT}"/provision.user ]; then
5757
if [ ! -f /sbin/openrc-run ]; then
5858
until [ -e "/run/user/${LIMA_CIDATA_UID}/systemd/private" ]; do sleep 3; done

pkg/cidata/cidata.TEMPLATE.d/boot/08-shell-prompt.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ set -eux
33

44
# This script is only intended for the default.yaml image, which is based on Ubuntu LTS
55

6-
if [ "${LIMA_CIDATA_NAME}" = "default" ] && command -v patch >/dev/null 2>&1 && grep -q color_prompt "/home/${LIMA_CIDATA_USER}.linux/.bashrc"; then
6+
if [ "${LIMA_CIDATA_NAME}" = "default" ] && command -v patch >/dev/null 2>&1 && grep -q color_prompt "${LIMA_CIDATA_HOME}/.bashrc"; then
77

8-
! grep -q "^# Lima PS1" "/home/${LIMA_CIDATA_USER}.linux/.bashrc" || exit 0
8+
! grep -q "^# Lima PS1" "${LIMA_CIDATA_HOME}/.bashrc" || exit 0
99

1010
# Change the default shell prompt from "green" to "lime" (#BFFF00)
1111

12-
patch --forward -r - "/home/${LIMA_CIDATA_USER}.linux/.bashrc" <<'EOF'
12+
patch --forward -r - "${LIMA_CIDATA_HOME}/.bashrc" <<'EOF'
1313
@@ -37,7 +37,11 @@
1414
1515
# set a fancy prompt (non-color, unless we know we "want" color)

pkg/cidata/cidata.TEMPLATE.d/boot/20-rootless-base.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ command -v systemctl >/dev/null 2>&1 || exit 0
66

77
# Set up env
88
for f in .profile .bashrc .zshrc; do
9-
if ! grep -q "# Lima BEGIN" "/home/${LIMA_CIDATA_USER}.linux/$f"; then
10-
cat >>"/home/${LIMA_CIDATA_USER}.linux/$f" <<EOF
9+
if ! grep -q "# Lima BEGIN" "${LIMA_CIDATA_HOME}/$f"; then
10+
cat >>"${LIMA_CIDATA_HOME}/$f" <<EOF
1111
# Lima BEGIN
1212
# Make sure iptables and mount.fuse3 are available
1313
PATH="\$PATH:/usr/sbin:/sbin"
1414
export PATH
1515
EOF
1616
if compare_version.sh "$(uname -r)" -lt "5.13"; then
17-
cat >>"/home/${LIMA_CIDATA_USER}.linux/$f" <<EOF
17+
cat >>"${LIMA_CIDATA_HOME}/$f" <<EOF
1818
# fuse-overlayfs is the most stable snapshotter for rootless, on kernel < 5.13
1919
# https://github.com/lima-vm/lima/issues/383
2020
# https://rootlesscontaine.rs/how-it-works/overlayfs/
2121
CONTAINERD_SNAPSHOTTER="fuse-overlayfs"
2222
export CONTAINERD_SNAPSHOTTER
2323
EOF
2424
fi
25-
cat >>"/home/${LIMA_CIDATA_USER}.linux/$f" <<EOF
25+
cat >>"${LIMA_CIDATA_HOME}/$f" <<EOF
2626
# Lima END
2727
EOF
28-
chown "${LIMA_CIDATA_USER}" "/home/${LIMA_CIDATA_USER}.linux/$f"
28+
chown "${LIMA_CIDATA_USER}" "${LIMA_CIDATA_HOME}/$f"
2929
fi
3030
done
3131
# Enable cgroup delegation (only meaningful on cgroup v2)

pkg/cidata/cidata.TEMPLATE.d/boot/25-guestagent-base.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ EOF
3838
rc-service lima-guestagent start
3939
else
4040
# Remove legacy systemd service
41-
rm -f "/home/${LIMA_CIDATA_USER}.linux/.config/systemd/user/lima-guestagent.service"
41+
rm -f "${LIMA_CIDATA_HOME}/.config/systemd/user/lima-guestagent.service"
4242

4343
sudo "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/lima-guestagent install-systemd
4444
fi

pkg/cidata/cidata.TEMPLATE.d/boot/40-install-containerd.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ EOF
5959
fi
6060

6161
if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
62-
if [ ! -e "/home/${LIMA_CIDATA_USER}.linux/.config/containerd/config.toml" ]; then
63-
mkdir -p "/home/${LIMA_CIDATA_USER}.linux/.config/containerd"
64-
cat >"/home/${LIMA_CIDATA_USER}.linux/.config/containerd/config.toml" <<EOF
62+
if [ ! -e "${LIMA_CIDATA_HOME}/.config/containerd/config.toml" ]; then
63+
mkdir -p "${LIMA_CIDATA_HOME}/.config/containerd"
64+
cat >"${LIMA_CIDATA_HOME}/.config/containerd/config.toml" <<EOF
6565
version = 2
6666
[proxy_plugins]
6767
[proxy_plugins."fuse-overlayfs"]
@@ -71,13 +71,13 @@ if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
7171
type = "snapshot"
7272
address = "/run/user/${LIMA_CIDATA_UID}/containerd-stargz-grpc/containerd-stargz-grpc.sock"
7373
EOF
74-
chown -R "${LIMA_CIDATA_USER}" "/home/${LIMA_CIDATA_USER}.linux/.config"
74+
chown -R "${LIMA_CIDATA_USER}" "${LIMA_CIDATA_HOME}/.config"
7575
fi
7676
selinux=
7777
if command -v selinuxenabled >/dev/null 2>&1 && selinuxenabled; then
7878
selinux=1
7979
fi
80-
if [ ! -e "/home/${LIMA_CIDATA_USER}.linux/.config/systemd/user/containerd.service" ]; then
80+
if [ ! -e "${LIMA_CIDATA_HOME}/.config/systemd/user/containerd.service" ]; then
8181
until [ -e "/run/user/${LIMA_CIDATA_UID}/systemd/private" ]; do sleep 3; done
8282
if [ -n "$selinux" ]; then
8383
echo "Temporarily disabling SELinux, during installing containerd units"

pkg/cidata/cidata.TEMPLATE.d/lima.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
LIMA_CIDATA_NAME={{ .Name }}
22
LIMA_CIDATA_USER={{ .User }}
33
LIMA_CIDATA_UID={{ .UID }}
4+
LIMA_CIDATA_HOME={{ .Home}}
45
LIMA_CIDATA_HOSTHOME_MOUNTPOINT={{ .HostHomeMountPoint }}
56
LIMA_CIDATA_MOUNTS={{ len .Mounts }}
67
{{- range $i, $val := .Mounts}}

pkg/cidata/cidata.TEMPLATE.d/user-data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mounts:
1717
users:
1818
- name: "{{.User}}"
1919
uid: "{{.UID}}"
20-
homedir: "/home/{{.User}}.linux"
20+
homedir: "{{.Home}}"
2121
shell: /bin/bash
2222
sudo: ALL=(ALL) NOPASSWD:ALL
2323
lock_passwd: true

pkg/cidata/cidata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
121121
Name: name,
122122
User: u.Username,
123123
UID: uid,
124+
Home: fmt.Sprintf("/home/%s.linux", u.Username),
124125
GuestInstallPrefix: *y.GuestInstallPrefix,
125126
Containerd: Containerd{System: *y.Containerd.System, User: *y.Containerd.User},
126127
SlirpNICName: networks.SlirpNICName,

pkg/cidata/template.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type TemplateArgs struct {
5656
Name string // instance name
5757
IID string // instance id
5858
User string // user name
59+
Home string // home directory
5960
UID int
6061
SSHPubKeys []string
6162
Mounts []Mount
@@ -93,6 +94,9 @@ func ValidateTemplateArgs(args TemplateArgs) error {
9394
if args.UID == 0 {
9495
return errors.New("field UID must not be 0")
9596
}
97+
if args.Home == "" {
98+
return errors.New("field Home must be set")
99+
}
96100
if len(args.SSHPubKeys) == 0 {
97101
return errors.New("field SSHPubKeys must be set")
98102
}

pkg/cidata/template_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func TestTemplate(t *testing.T) {
1313
Name: "default",
1414
User: "foo",
1515
UID: 501,
16+
Home: "/home/foo.linux",
1617
SSHPubKeys: []string{
1718
"ssh-rsa dummy [email protected]",
1819
},
@@ -41,6 +42,7 @@ func TestTemplate9p(t *testing.T) {
4142
Name: "default",
4243
User: "foo",
4344
UID: 501,
45+
Home: "/home/foo.linux",
4446
SSHPubKeys: []string{
4547
"ssh-rsa dummy [email protected]",
4648
},

0 commit comments

Comments
 (0)