跳到主要内容

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

浏览文件

escape_fstab.sh

68 行 · 2.9 KB历史下载
1#!/bin/bash
2
3# SPDX-FileCopyrightText: Copyright The Lima Authors
4# SPDX-License-Identifier: Apache-2.0
5
6# Read an /etc/fstab on stdin and write it to stdout with the mount-point field
7# octal-escaped (per fstab(5)) for cloud-config virtiofs entries whose path
8# contains a space or tab. cloud-init's cc_mounts writes the mount point verbatim,
9# so a space/tab produces an unparsable line that mount(8) silently skips via the
10# nofail option. Fields are tab-separated, so -F'\t' isolates the mount point;
11# already-escaped paths have no literal space/tab, so the transformation is
12# idempotent (and stays correct once cloud-init escapes the field itself).
13#
14# See:
15# https://github.com/lima-vm/lima/issues/5136
16# https://github.com/abiosoft/colima/issues/1471
17# https://github.com/canonical/cloud-init/issues/3603 (cc_mounts does not escape)
18# https://github.com/canonical/cloud-init/issues/6911 (the upstream cloud-init fix)
19
20set -eu
21
22: "${SELFTEST:=}"
23if [ -n "${SELFTEST}" ]; then
24 unset SELFTEST
25 tab=$(printf '\t')
26 check() {
27 local desc=$1 input=$2 want=$3 got
28 got=$(printf '%s\n' "${input}" | "$0")
29 if [ "${got}" = "${want}" ]; then
30 echo "ok: ${desc}"
31 else
32 echo "FAIL: ${desc}" >&2
33 printf ' want: %q\n got: %q\n' "${want}" "${got}" >&2
34 return 1
35 fi
36 }
37 echo >&2 "=== Running tests ==="
38 check "space in the mount point is escaped" \
39 "tag${tab}/tmp/dir with spaces${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" \
40 "tag${tab}/tmp/dir\\040with\\040spaces${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0"
41 check "already-escaped path is unchanged (idempotent)" \
42 "tag${tab}/tmp/dir\\040with\\040spaces${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" \
43 "tag${tab}/tmp/dir\\040with\\040spaces${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0"
44 check "path without whitespace is unchanged" \
45 "tag${tab}/mnt/nospace${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" \
46 "tag${tab}/mnt/nospace${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0"
47 check "backslash is escaped before the space" \
48 "tag${tab}/a b\\c${tab}virtiofs${tab}rw,comment=cloudconfig${tab}0${tab}0" \
49 "tag${tab}/a\\040b\\134c${tab}virtiofs${tab}rw,comment=cloudconfig${tab}0${tab}0"
50 check "entry without comment=cloudconfig is unchanged" \
51 "tag${tab}/tmp/dir with spaces${tab}virtiofs${tab}rw${tab}0${tab}0" \
52 "tag${tab}/tmp/dir with spaces${tab}virtiofs${tab}rw${tab}0${tab}0"
53 check "non-virtiofs entry is unchanged" \
54 "/dev/sda1${tab}/data dir${tab}ext4${tab}defaults,comment=cloudconfig${tab}0${tab}0" \
55 "/dev/sda1${tab}/data dir${tab}ext4${tab}defaults,comment=cloudconfig${tab}0${tab}0"
56 echo >&2 "=== All tests passed ==="
57 exit 0
58fi
59
60awk -F'\t' 'BEGIN { OFS = "\t" }
61 $3 == "virtiofs" && $4 ~ /comment=cloudconfig/ && $2 ~ /[ \t]/ {
62 p = $2
63 gsub(/\\/, "\\134", p) # backslash first so introduced escapes are not re-escaped
64 gsub(/ /, "\\040", p)
65 gsub(/\t/, "\\011", p)
66 $2 = p
67 }
68 { print }'