跳到主要内容

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

浏览文件

test-upgrade.sh

109 行 · 3.1 KB历史下载
1#!/usr/bin/env bash
2
3# SPDX-FileCopyrightText: Copyright The Lima Authors
4# SPDX-License-Identifier: Apache-2.0
5
6set -eu -o pipefail
7
8scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9# shellcheck source=common.inc.sh
10source "${scriptdir}/common.inc.sh"
11cd "${scriptdir}/.."
12
13if [ "$#" -ne 2 ]; then
14 ERROR "Usage: $0 OLDVER NEWVER"
15 exit 1
16fi
17
18OLDVER="$1"
19NEWVER="$2"
20
21PREFIX="/usr/local"
22function install_lima() {
23 ver="$1"
24 git checkout "${ver}"
25 make clean
26 make
27 if [ -w "${PREFIX}/bin" ] && [ -w "${PREFIX}/share" ] && [ -w "${PREFIX}/libexec" ]; then
28 make install
29 else
30 sudo make install
31 fi
32}
33
34function install_lima_binary() {
35 ver="$1"
36 tar="tar"
37 if [ ! -w "${PREFIX}/bin" ] || [ ! -w "${PREFIX}/share" ] || [ ! -w "${PREFIX}/libexec" ]; then
38 tar="sudo ${tar}"
39 fi
40 curl -fsSL "https://github.com/lima-vm/lima/releases/download/${ver}/lima-${ver:1}-$(uname -s)-$(uname -m).tar.gz" | ${tar} Cxzvm "${PREFIX}"
41}
42
43function uninstall_lima() {
44 files="${PREFIX}/bin/lima ${PREFIX}/bin/limactl ${PREFIX}/share/lima ${PREFIX}/share/doc/lima ${PREFIX}/libexec/lima"
45 if [ -w "${PREFIX}/bin" ] && [ -w "${PREFIX}/share" ] && [ -w "${PREFIX}/libexec" ]; then
46 # shellcheck disable=SC2086
47 rm -rf $files
48 else
49 # shellcheck disable=SC2086
50 sudo rm -rf $files
51 fi
52}
53
54function show_lima_log() {
55 tail -n 100 ~/.lima/"${LIMA_INSTANCE}"/*.log || true
56 mkdir -p failure-logs
57 cp -pf ~/.lima/"${LIMA_INSTANCE}"/*.log failure-logs/ || true
58 limactl shell "${LIMA_INSTANCE}" sudo cat /var/log/cloud-init-output.log | tee failure-logs/cloud-init-output.log || true
59}
60
61INFO "Uninstalling lima"
62uninstall_lima
63
64INFO "Installing the old Lima ${OLDVER}"
65install_lima_binary "${OLDVER}" || install_lima "${OLDVER}"
66
67export LIMA_INSTANCE="test-upgrade"
68
69INFO "Creating an instance \"${LIMA_INSTANCE}\" with the old Lima"
70defer "show_lima_log;limactl delete -f \"${LIMA_INSTANCE}\""
71limactl start --tty=false --name="${LIMA_INSTANCE}" template://ubuntu-lts || (
72 show_lima_log
73 exit 1
74)
75lima nerdctl info
76
77image_name="lima-test-upgrade-containerd-${RANDOM}"
78image_context="${HOME}/${image_name}"
79INFO "Building containerd image \"${image_name}\" from \"${image_context}\""
80defer "rm -rf \"${image_context}\""
81mkdir -p "${image_context}"
82cat <<EOF >"${image_context}"/Dockerfile
83# Use GHCR to avoid hitting Docker Hub rate limit
84FROM ghcr.io/containerd/alpine:3.14.0
85CMD ["echo", "Built with Lima ${OLDVER}"]
86EOF
87lima nerdctl build -t "${image_name}" "${image_context}"
88lima nerdctl run --rm "${image_name}"
89
90INFO "Stopping the instance"
91limactl stop "${LIMA_INSTANCE}"
92
93INFO "=============================================================================="
94
95INFO "Installing the new Lima ${NEWVER}"
96install_lima "${NEWVER}"
97
98INFO "Editing the instance to specify vm-type as qemu explicitly"
99limactl edit --vm-type=qemu "${LIMA_INSTANCE}"
100
101INFO "Restarting the instance"
102limactl start --tty=false --vm-type=qemu "${LIMA_INSTANCE}" || show_lima_log
103lima nerdctl info
104
105INFO "Confirming that the host filesystem is still mounted"
106"${scriptdir}"/test-mount-home.sh "${LIMA_INSTANCE}"
107
108INFO "Confirming that the image \"${image_name}\" still exists"
109lima nerdctl run --rm "${image_name}"