@@ -18,6 +18,75 @@ users:
18
18
{{- end}}
19
19
20
20
write_files :
21
+ - content : |
22
+ #!/sbin/openrc-run
23
+ supervisor=supervise-daemon
24
+
25
+ name="lima-guestagent"
26
+ description="Forward ports to the lima-hostagent"
27
+
28
+ export XDG_RUNTIME_DIR="/run/user/{{.UID}}"
29
+ command=/usr/local/bin/lima-guestagent
30
+ command_args="daemon"
31
+ command_background=true
32
+ command_user="{{.User}}:{{.User}}"
33
+ pidfile="${XDG_RUNTIME_DIR}/lima-guestagent.pid"
34
+ owner: root:root
35
+ path: /var/lib/lima-guestagent/lima-guestagent.openrc
36
+ permissions: '0755'
37
+ - content : |
38
+ #!/bin/sh
39
+ # This script prepares Alpine for lima; there is nothing in here for other distros
40
+ test -f /etc/alpine-release || exit
41
+
42
+ # Since we are on Alpine, we can now assume /bin/sh is /bin/ash
43
+ set -eux -o pipefail
44
+
45
+ # Redirect bash to ash (built with CONFIG_ASH_BASH_COMPAT) and hope for the best :)
46
+ # (it does support `set -o pipefail`, but not `[[`)
47
+ # /bin/bash can't be a symlink because /bin/ash is a symlink to /bin/busybox
48
+ cat >/bin/bash <<'EOF'
49
+ #!/bin/sh
50
+ exec /bin/ash "$@"
51
+ EOF
52
+ chmod +x /bin/bash
53
+
54
+ # Configure apk repos
55
+ branch=edge
56
+ VERSION_ID=$(awk -F= '$1=="VERSION_ID" {print $2}' /etc/os-release)
57
+ case $VERSION_ID in
58
+ *_alpha*|*_beta*) branch=edge;;
59
+ *.*.*) branch=v${VERSION_ID%.*};;
60
+ esac
61
+
62
+ for repo in main community; do
63
+ url="https://dl-cdn.alpinelinux.org/alpine/${branch}/${repo}"
64
+ if ! grep -q "^${url}$" /etc/apk/repositories; then
65
+ echo "${url}" >> /etc/apk/repositories
66
+ fi
67
+ done
68
+
69
+ # Alpine doesn't use PAM so we need to explicitly allow public key auth
70
+ usermod -p '*' ""{{.User}}""
71
+
72
+ # Alpine disables TCP forwarding, which is needed by the lima-guestagent
73
+ sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
74
+ rc-service sshd reload
75
+
76
+ # Create directory for the lima-guestagent socket (normally done by systemd)
77
+ mkdir -p /run/user/{{.UID}}
78
+ chown "{{.User}}" /run/user/{{.UID}}
79
+ chmod 700 /run/user/{{.UID}}
80
+
81
+ # Install the openrc lima-guestagent service script
82
+ mv /var/lib/lima-guestagent/lima-guestagent.openrc /etc/init.d/lima-guestagent
83
+
84
+ # `limactl stop` tells acpid to powerdown
85
+ rc-update add acpid
86
+ rc-service acpid start
87
+ owner: root:root
88
+ path: /var/lib/cloud/scripts/per-boot/00-alpine-prep.boot.sh
89
+ permissions: '0755'
21
90
- content : |
22
91
#!/bin/bash
23
92
set -eux -o pipefail
@@ -81,11 +150,16 @@ write_files:
81
150
umount /mnt/lima-cidata
82
151
83
152
# Launch the guestagent service
84
- until [ -e "/run/user/{{.UID}}/systemd/private" ]; do sleep 3; done
85
- sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" lima-guestagent install-systemd
153
+ if [ -f /etc/alpine-release ]; then
154
+ rc-update add lima-guestagent default
155
+ rc-service lima-guestagent start
156
+ else
157
+ until [ -e "/run/user/{{.UID}}/systemd/private" ]; do sleep 3; done
158
+ sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" lima-guestagent install-systemd
159
+ fi
86
160
owner: root:root
87
161
# We do not use per-once.
88
- path: /var/lib/cloud/scripts/per-boot/00 -base.boot.sh
162
+ path: /var/lib/cloud/scripts/per-boot/10 -base.boot.sh
89
163
permissions: '0755'
90
164
{{- if or .Mounts .Containerd.System .Containerd.User }}
91
165
- content : |
@@ -119,6 +193,15 @@ write_files:
119
193
ln -s fusermount3 /usr/bin/fusermount
120
194
fi
121
195
{{- end}}
196
+ elif command -v apk 2>&1 >/dev/null; then
197
+ : {{/* make sure the "elif" block is never empty */}}
198
+ {{- if .Mounts}}
199
+ if ! command -v sshfs 2>&1 >/dev/null; then
200
+ apk update
201
+ apk add sshfs
202
+ fi
203
+ modprobe fuse
204
+ {{- end}}
122
205
fi
123
206
# Modify /etc/fuse.conf to allow "-o allow_root"
124
207
{{- if .Mounts }}
@@ -127,7 +210,7 @@ write_files:
127
210
fi
128
211
{{- end}}
129
212
owner: root:root
130
- path: /var/lib/cloud/scripts/per-boot/10 -install-packages.boot.sh
213
+ path: /var/lib/cloud/scripts/per-boot/20 -install-packages.boot.sh
131
214
permissions: '0755'
132
215
{{- end}}
133
216
{{- if or .Containerd.System .Containerd.User}}
@@ -191,7 +274,7 @@ write_files:
191
274
fi
192
275
{{- end}}
193
276
owner: root:root
194
- path: /var/lib/cloud/scripts/per-boot/20 -install-containerd.boot.sh
277
+ path: /var/lib/cloud/scripts/per-boot/30 -install-containerd.boot.sh
195
278
permissions: '0755'
196
279
{{- end}}
197
280
{{- if .Provision}}
@@ -208,7 +291,7 @@ write_files:
208
291
{{- end}}
209
292
{{- end}}
210
293
owner: root:root
211
- path: /var/lib/cloud/scripts/per-boot/30 -execute-provision-scripts.boot.sh
294
+ path: /var/lib/cloud/scripts/per-boot/40 -execute-provision-scripts.boot.sh
212
295
permissions: '0755'
213
296
{{- end}}
214
297
{{- range $i, $val := .Provision}}
0 commit comments