跳到主要内容

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

浏览文件

ignition.go

162 行 · 3.2 KB历史下载
1package e2eutils
2
3import (
4 "encoding/json"
5 "net/url"
6 "os"
7)
8
9var (
10 mode = 0644
11 dirMode = 0744
12 root = "root"
13 test = "test"
14 yes = true
15 no = false
16)
17
18func CreateIgnition(ignitionFile string, publicKey string, user string, password string) error {
19
20 linger := `[Unit]
21Description=Activate podman socket
22Wants=podman.socket
23[Service]
24ExecStart=/usr/bin/sleep infinity
25`
26
27 systemd := Systemd{
28 Units: []Unit{
29 {
30 Name: "systemd-resolved.service",
31 Enabled: &no,
32 Mask: &yes,
33 },
34 {
35 Name: "podman.socket",
36 Enabled: &yes,
37 },
38 },
39 }
40
41 passwd := Passwd{
42 Users: []PasswdUser{
43 {
44 Name: user,
45 PasswordHash: &password,
46 SSHAuthorizedKeys: []SSHAuthorizedKey{
47 SSHAuthorizedKey(publicKey),
48 },
49 Groups: []Group{
50 "wheel",
51 "sudo",
52 },
53 },
54 {
55 Name: "root",
56 PasswordHash: &password,
57 SSHAuthorizedKeys: []SSHAuthorizedKey{
58 SSHAuthorizedKey(publicKey),
59 },
60 },
61 },
62 }
63
64 storage := Storage{
65 // Replaces resolv.conf with an empty file that will be overwritten by NetworkManager
66 Files: []File{
67 {
68 Node: Node{
69 Group: NodeGroup{Name: &root},
70 Path: "/etc/resolv.conf",
71 User: NodeUser{Name: &root},
72 Overwrite: &yes,
73 },
74 FileEmbedded1: FileEmbedded1{
75 Contents: Resource{
76 Source: encodeData(""),
77 },
78 Mode: &mode,
79 },
80 },
81 {
82 Node: Node{
83 Group: NodeGroup{Name: &test},
84 Path: "/home/" + test + "/.config/systemd/user/linger-podman.service",
85 User: NodeUser{Name: &test},
86 Overwrite: &yes,
87 },
88 FileEmbedded1: FileEmbedded1{
89 Contents: Resource{
90 Source: encodeData(linger),
91 },
92 Mode: &mode,
93 },
94 },
95 {
96 Node: Node{
97 Group: NodeGroup{Name: &test},
98 Path: "/var/lib/systemd/linger/" + test,
99 User: NodeUser{Name: &test},
100 Overwrite: &yes,
101 },
102 FileEmbedded1: FileEmbedded1{
103 Contents: Resource{
104 Source: encodeData(""),
105 },
106 Mode: &mode,
107 },
108 },
109 },
110 Directories: []Directory{
111 dir("/home/" + test + "/.config"),
112 dir("/home/" + test + "/.config/containers"),
113 dir("/home/" + test + "/.config/systemd"),
114 dir("/home/" + test + "/.config/systemd/user"),
115 dir("/home/" + test + "/.config/systemd/user/default.target.wants"),
116 },
117 Links: []Link{
118 {
119 Node: Node{
120 Group: NodeGroup{Name: &test},
121 Path: "/home/" + test + "/.config/systemd/user/default.target.wants/linger-podman.service",
122 User: NodeUser{Name: &test},
123 },
124 LinkEmbedded1: LinkEmbedded1{
125 Hard: &no,
126 Target: "/home/" + test + "/.config/systemd/user/linger-podman.service",
127 },
128 },
129 },
130 }
131
132 config := Config{
133 Ignition: Ignition{Version: "3.2.0"},
134 Systemd: systemd,
135 Passwd: passwd,
136 Storage: storage,
137 }
138
139 contents, err := json.Marshal(config)
140 if err != nil {
141 return err
142 }
143
144 // #nosec
145 return os.WriteFile(ignitionFile, contents, 0644)
146}
147
148func dir(path string) Directory {
149 return Directory{
150 Node: Node{
151 Group: NodeGroup{Name: &test},
152 Path: path,
153 User: NodeUser{Name: &test},
154 },
155 DirectoryEmbedded1: DirectoryEmbedded1{Mode: &dirMode},
156 }
157}
158
159func encodeData(data string) *string {
160 str := "data:," + url.PathEscape(data)
161 return &str
162}