跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

05-rosetta-volume.sh

111 行 · 4.1 KB历史下载
1#!/bin/bash
2
3# SPDX-FileCopyrightText: Copyright The Lima Authors
4# SPDX-License-Identifier: Apache-2.0
5
6set -eux -o pipefail
7
8if [ "$LIMA_CIDATA_ROSETTA_ENABLED" != "true" ]; then
9 exit 0
10fi
11
12if [ -f /etc/alpine-release ]; then
13 rc-service procfs start --ifnotstarted
14 rc-service qemu-binfmt stop --ifexists --ifstarted
15fi
16
17binfmt_entry=/proc/sys/fs/binfmt_misc/rosetta
18binfmtd_conf=/usr/lib/binfmt.d/rosetta.conf
19if [ "$LIMA_CIDATA_ROSETTA_BINFMT" = "true" ]; then
20 rosetta_binfmt=":rosetta:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00:\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/mnt/lima-rosetta/rosetta:OCF"
21
22 # If rosetta is not registered in binfmt_misc, register it.
23 [ -f "$binfmt_entry" ] || echo "$rosetta_binfmt" >/proc/sys/fs/binfmt_misc/register
24
25 # Create binfmt.d(5) configuration to prioritize rosetta even if qemu-user-static is installed on systemd based systems.
26 # If the binfmt.d directory exists, consider systemd-binfmt.service(8) to be enabled and create the configuration file.
27 [ ! -d "$(dirname "$binfmtd_conf")" ] || [ -f "$binfmtd_conf" ] || echo "$rosetta_binfmt" >"$binfmtd_conf"
28else
29 # unregister rosetta from binfmt_misc if it exists
30 [ ! -f "$binfmt_entry" ] || echo -1 >"$binfmt_entry"
31 # remove binfmt.d(5) configuration if it exists
32 [ ! -f "$binfmtd_conf" ] || rm "$binfmtd_conf"
33fi
34
35if [ -x /mnt/lima-rosetta/rosettad ]; then
36 CACHE_DIRECTORY=/var/cache/rosettad
37 DEFAULT_SOCKET=${CACHE_DIRECTORY}/uds/rosetta.sock
38 EXPECTED_SOCKET=/run/rosettad/rosetta.sock
39
40 # Create rosettad service
41 if [ -f /sbin/openrc-run ]; then
42 cat >/etc/init.d/rosettad <<EOF
43#!/sbin/openrc-run
44name="rosettad"
45description="Rosetta AOT Caching Daemon"
46required_dirs=/mnt/lima-rosetta
47required_files=/mnt/lima-rosetta/rosettad
48command=/mnt/lima-rosetta/rosettad
49command_args="daemon ${CACHE_DIRECTORY}"
50command_background=true
51pidfile="/run/rosettad.pid"
52start_pre() {
53 # To detect creation of the socket by rosettad, remove the old socket before starting
54 test ! -e "${DEFAULT_SOCKET}" || rm -f "${DEFAULT_SOCKET}"
55}
56start_post() {
57 # Set the socket permission to world-writable
58 while ! chmod -f go+w "${DEFAULT_SOCKET}"; do sleep 1; done
59 # Create the symlink as expected by the configuration to enable Rosetta AOT caching
60 mkdir -p "$(dirname "${EXPECTED_SOCKET}")"
61 ln -sf "${DEFAULT_SOCKET}" "${EXPECTED_SOCKET}"
62}
63EOF
64 chmod 755 /etc/init.d/rosettad
65 rc-update add rosettad default
66 rc-service rosettad start
67 else
68 cat >/etc/systemd/system/rosettad.service <<EOF
69[Unit]
70Description=Rosetta AOT Caching Daemon
71RequiresMountsFor=/mnt/lima-rosetta
72[Service]
73RuntimeDirectory=rosettad
74CacheDirectory=rosettad
75# To detect creation of the socket by rosettad, remove the old socket
76ExecStartPre=sh -c "test ! -e \"${DEFAULT_SOCKET}\" || rm -f \"${DEFAULT_SOCKET}\""
77ExecStart=/mnt/lima-rosetta/rosettad daemon "${CACHE_DIRECTORY}"
78# Set the socket permission to world-writable and create the symlink as expected by the configuration to enable Rosetta AOT caching.
79ExecStartPost=sh -c "while ! chmod -f go+w \"${DEFAULT_SOCKET}\"; do sleep 1; done; ln -sf \"${DEFAULT_SOCKET}\" \"${EXPECTED_SOCKET}\""
80OOMPolicy=continue
81OOMScoreAdjust=-500
82[Install]
83WantedBy=default.target
84EOF
85 systemctl is-enabled rosettad || systemctl enable --now rosettad
86 fi
87
88 # Create CDI configuration for Rosetta
89 mkdir -p /etc/cdi /var/run/cdi /etc/buildkit/cdi
90 cat >/etc/cdi/rosetta.yaml <<EOF
91cdiVersion: "0.6.0"
92kind: "lima-vm.io/rosetta"
93devices:
94- name: cached
95 containerEdits:
96 mounts:
97 - hostPath: /var/cache/rosettad/uds/rosetta.sock
98 containerPath: /run/rosettad/rosetta.sock
99 options: [bind]
100annotations:
101 org.mobyproject.buildkit.device.autoallow: true
102EOF
103 # nerdctl requires user-specific CDI configuration directories
104 mkdir -p "${LIMA_CIDATA_HOME}/.config/cdi"
105 ln -sf /etc/cdi/rosetta.yaml "${LIMA_CIDATA_HOME}/.config/cdi/"
106 chown -R "${LIMA_CIDATA_USER}" "${LIMA_CIDATA_HOME}/.config"
107else
108 # Remove CDI configuration for Rosetta AOT Caching
109 [ ! -f /etc/cdi/rosetta.yaml ] || rm /etc/cdi/rosetta.yaml
110 [ ! -L "${LIMA_CIDATA_HOME}/.config/cdi/rosetta.yaml" ] || rm "${LIMA_CIDATA_HOME}/.config/cdi/rosetta.yaml"
111fi