跳到主要内容

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

浏览文件

limactl.bash

48 行 · 2.0 KB历史下载
1# SPDX-FileCopyrightText: Copyright The Lima Authors
2# SPDX-License-Identifier: Apache-2.0
3
4# Create a dummy Lima instance for testing purposes. It cannot be started because it doesn't have an actual image.
5# This function intentionally doesn't use create/editflags, but modifies the template with yq instead.
6create_dummy_instance() {
7 local name=$1
8 local expr=${2:-}
9
10 # Template does not validate without an image, and the image must point to a file that exists (for clonefile).
11 local template="{images: [location: /etc/profile]}"
12 if [[ -n $expr ]]; then
13 template="$(limactl yq "$expr" <<<"$template")"
14 fi
15 limactl create --name "$name" - <<<"$template"
16}
17
18# Ensure a Lima instance exists. When LIMA_BATS_REUSE_INSTANCE is set, reuse an
19# existing running instance. Otherwise delete and recreate it.
20# The instance configuration is determined by its name; add a case below for new names.
21# Close file handles 3 and 4 so the host agent doesn't block BATS from exiting.
22ensure_instance() {
23 local instance=$1
24 if [[ -n "${LIMA_BATS_REUSE_INSTANCE:-}" ]]; then
25 run limactl list --format '{{.Status}}' "$instance"
26 [[ $status == 0 ]] && [[ $output == "Running" ]] && return
27 fi
28 limactl unprotect "$instance" || :
29 limactl delete --force "$instance" || :
30 case "$instance" in
31 bats) limactl start --yes --name "$instance" template:default 3>&- 4>&- ;;
32 bats-nomount) limactl start --yes --name "$instance" --mount-none template:default 3>&- 4>&- ;;
33 bats-dummy) create_dummy_instance "$instance" '.disk = "1M"' ;;
34 *)
35 echo "ensure_instance: unknown instance name '$instance'" >&2
36 return 1
37 ;;
38 esac
39}
40
41# Delete the given Lima instance unless LIMA_BATS_REUSE_INSTANCE is set.
42delete_instance() {
43 local instance=$1
44 if [[ -z "${LIMA_BATS_REUSE_INSTANCE:-}" ]]; then
45 limactl unprotect "$instance" || :
46 limactl delete --force "$instance" || :
47 fi
48}