forked from Goldzxcbug/Droidspaces-rootfs-Desktop-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUbuntu-26.Dockerfile
More file actions
404 lines (358 loc) · 16.2 KB
/
Copy pathUbuntu-26.Dockerfile
File metadata and controls
404 lines (358 loc) · 16.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
FROM ubuntu:26.04 AS customizer
#######################################################
ARG DESKTOP
ARG DESKTOP_AUTOSTART
ARG PulseAudio
ARG ENABLE_zh_tz_ARG
ARG ENABLE_binfmt_ARG
ARG ENABLE_yj_ARG
ARG ENABLE_mesa_ARG
ARG ENABLE_kfgj_ARG
ARG ENABLE_zip_ARG
ARG ENABLE_docker_ARG
ARG ENABLE_srf_ARG
ARG ENABLE_tmoe_ARG
ARG DISPLAY_BACKEND
ARG ENABLE_8gen2_wayland_ARG
ARG ENABLE_nosnap_ARG
ARG ENABLE_systemd257_ARG
ARG USERNAME
ARG ANLAND_RELEASE_REPOSITORY=Goldzxcbug/droidspaces-package
ARG ANLAND_PACKAGE_REVISION=unknown
######################################################
ENV DEBIAN_FRONTEND=noninteractive
# 启用 APT 并行连接、HTTP(S) pipeline 和下载重试
RUN printf '%s\n' \
'Acquire::Queue-Mode "host";' \
'Acquire::http::Pipeline-Depth "10";' \
'Acquire::https::Pipeline-Depth "10";' \
'Acquire::Retries "3";' \
> /etc/apt/apt.conf.d/99parallel-downloads
# 优先复制自定义脚本
COPY scripts/download-firmware /usr/local/bin/
COPY scripts/nosnap.sh /usr/local/sbin/nosnap
COPY scripts/systemd257.sh /usr/local/sbin/systemd257
# 将自定义的 bashrc 脚本复制到根文件系统的 profile 目录
COPY scripts/bashrc.sh /etc/profile.d/ds-aliases.sh
# 通用 Droidspaces USB Manager 安装器
COPY scripts/install-usb-manager.sh /usr/local/sbin/install-droidspaces-usb-manager
COPY scripts/install-anland-kde.sh /usr/local/sbin/install-anland-kde
COPY scripts/install-anland-gnome.sh /usr/local/sbin/install-anland-gnome
COPY scripts/install-anland-desktop.sh /usr/local/sbin/install-anland-desktop
COPY scripts/install-mesa.sh /usr/local/sbin/install-mesa
COPY scripts/install-desktop.sh /usr/local/sbin/install-desktop
COPY scripts/configure-desktop.sh /usr/local/sbin/configure-desktop
COPY scripts/start-desktop-session.sh /usr/local/bin/start-desktop-session
COPY scripts/desktops/ /usr/local/lib/droidspaces/desktops/
# 赋予相关脚本可执行权限
RUN chmod +x /usr/local/bin/download-firmware /usr/local/sbin/nosnap /etc/profile.d/ds-aliases.sh /usr/local/sbin/install-anland-* /usr/local/sbin/install-mesa /usr/local/sbin/install-desktop /usr/local/sbin/configure-desktop /usr/local/bin/start-desktop-session /usr/local/lib/droidspaces/desktops/*.sh
RUN sed -i 's/Components: main/Components: main restricted universe multiverse/g' /etc/apt/sources.list.d/ubuntu.sources 2>/dev/null || \
sed -i 's/main/main restricted universe multiverse/g' /etc/apt/sources.list 2>/dev/null && \
apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl wget && \
if [ "$ENABLE_nosnap_ARG" = "true" ]; then \
echo "--> [开启] nosnap: 正在预配置并移除 Ubuntu Snap..." && \
bash /usr/local/sbin/nosnap; \
else \
echo "--> [跳过] 未开启 nosnap"; \
fi && \
rm -f /usr/local/sbin/nosnap && \
apt-get update && \
apt-get upgrade -y
RUN apt-get update && \
apt-get install -y --no-install-recommends \
# 核心工具组件
bash jq dialog coreutils file findutils grep sed gawk curl wget ca-certificates locales bash-completion udev dbus systemd-sysv systemd-resolved fastfetch \
# 用户请求的基础开发/编辑工具
git nano sudo \
# 网络与 SSH 工具
openssh-server net-tools iptables iputils-ping iproute2 dnsutils \
# 用于系统监控的 procps 进程工具
procps \
# 核心内核模块支持
kmod tzdata tar && \
/usr/local/sbin/install-desktop "$DESKTOP" && \
############################################## Anland Wayland 支持 ################################################
if [ "$DISPLAY_BACKEND" = "anland-wayland" ]; then \
echo "--> [开启] 正在安装 $DESKTOP 的 Anland 包 (${ANLAND_PACKAGE_REVISION})..." && \
ANLAND_RELEASE_REPOSITORY="$ANLAND_RELEASE_REPOSITORY" \
/usr/local/sbin/install-anland-desktop "$DESKTOP" --1 && \
echo "--> [开启] $DESKTOP 的 Anland 支持已安装"; \
fi && \
######################################################################################################
#输入法 fcitx5 (可选)
if [ "$ENABLE_srf_ARG" = "true" ]; then \
apt-get install -y fcitx5; \
fi && \
if [ "$ENABLE_srf_ARG" = "true" ] && [ "$ENABLE_zh_tz_ARG" = "true" ]; then \
apt-get install -y fcitx5-chinese-addons; \
fi && \
## 开发工具集成 (可选)
if [ "$ENABLE_kfgj_ARG" = "true" ]; then \
apt-get install -y --no-install-recommends \
build-essential gcc g++ make cmake autoconf automake libtool pkg-config clang llvm python3 python3-pip python3-dev python3-venv python-is-python3; \
fi && \
## 压缩工具扩展 (可选)
if [ "$ENABLE_zip_ARG" = "true" ]; then \
apt-get install -y --no-install-recommends \
zip unzip p7zip-full bzip2 xz-utils tar gzip; \
fi && \
## docker (可选)
if [ "$ENABLE_docker_ARG" = "true" ]; then \
apt-get install -y --no-install-recommends \
docker.io docker-compose-v2; \
fi && \
## 集成tmoe (可选)
if [ "$ENABLE_tmoe_ARG" = "true" ]; then \
git clone --depth=1 https://github.com/2moe/tmoe-linux.git /usr/local/etc/tmoe-linux/git && \
ln -sf /usr/local/etc/tmoe-linux/git/debian.sh /usr/local/bin/tmoe && \
chmod -R 755 /usr/local/etc/tmoe-linux; \
fi && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 强制配置使用 iptables-legacy
RUN update-alternatives --set iptables /usr/sbin/iptables-legacy && \
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
RUN sed -i '/en_US.UTF-8/s/^# //' /etc/locale.gen && \
if [ "$ENABLE_zh_tz_ARG" = "true" ]; then \
export DEBIAN_FRONTEND=noninteractive && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
dpkg-reconfigure -f noninteractive tzdata && \
sed -i '/zh_CN.UTF-8/s/^# //' /etc/locale.gen && \
locale-gen && \
update-locale LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8; \
else \
locale-gen && \
update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8; \
fi && \
mkdir -p /var/run/sshd && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config && \
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
# Ubuntu 默认用户是 ubuntu,删除它避免冲突
(deluser --remove-home ubuntu || true) && \
# 创建自定义用户并直接加入 shadow 组,确保锁屏验证权限
useradd -m -s /bin/bash -G shadow ${USERNAME} && echo "${USERNAME}:1234" | chpasswd && \
systemctl enable ssh
# 为所有 Ubuntu RootFS 安装 Droidspaces USB Manager
RUN /usr/local/sbin/install-droidspaces-usb-manager --user "${USERNAME}"
# 初始化环境变量文件;桌面专属变量由对应 profile 管理。
RUN : > /etc/environment
RUN if [ "$ENABLE_mesa_ARG" = "true" ] && [ "$DISPLAY_BACKEND" = "anland-wayland" ]; then \
echo "MESA_LOADER_DRIVER_OVERRIDE=kgsl" >> /etc/environment; \
echo "GALLIUM_DRIVER=kgsl" >> /etc/environment; \
echo "FD_FORCE_KGSL=1" >> /etc/environment; \
fi
# 修复骁龙8 Gen 2 设备在 Wayland 下的花屏问题
RUN if [ "$ENABLE_8gen2_wayland_ARG" = "true" ]; then \
echo "FD_DEV_FEATURES=enable_tp_ubwc_flag_hint=1" >> /etc/environment; \
fi
# 音频选择
RUN if [ "$PulseAudio" = "socket" ]; then \
echo "PULSE_SERVER=unix:/tmp/.pulse-socket" >> /etc/environment; \
elif [ "$PulseAudio" = "tcp" ]; then \
echo "PULSE_SERVER=tcp:127.0.0.1:4713" >> /etc/environment; \
fi
# 修复anland 音频堵塞
# RUN if [ "$DISPLAY_BACKEND" = "anland-wayland" ]; then \
# mkdir -p /home/${USERNAME}/.config && \
# echo -e "\n[Sounds]\nEnable=false" >> /home/${USERNAME}/.config/kdeglobals ; \
# fi
# 输入法与桌面会话配置
COPY scripts/start/ /tmp/droidspaces-start/
RUN <<'EOF_RUN'
if [ "$ENABLE_srf_ARG" = "true" ]; then
mkdir -p /home/${USERNAME}/.config/autostart
cat <<'EOF' > /home/${USERNAME}/.config/autostart/fcitx5.desktop
[Desktop Entry]
Name=Fcitx5
GenericName=Input Method
Comment=Start Input Method
Exec=fcitx5 -d
Icon=fcitx
Terminal=false
Type=Application
Categories=System;Utility;
StartupNotify=false
NoDisplay=true
EOF
cat <<'EOF' >> /etc/environment
XMODIFIERS=@im=fcitx5
GTK_IM_MODULE=fcitx5
QT_IM_MODULE=fcitx5
SDL_IM_MODULE=fcitx5
GLFW_IM_MODULE=fcitx
EOF
fi
if [ "$ENABLE_mesa_ARG" = "true" ] && [ "$DISPLAY_BACKEND" != "anland-wayland" ] ; then
cat <<'EOF' >> /etc/environment
MESA_LOADER_DRIVER_OVERRIDE=kgsl
TU_DEBUG=noconform
EOF
fi
echo 'export XDG_RUNTIME_DIR=/run/user/$(id -u)' >> /home/${USERNAME}/.bashrc
/usr/local/sbin/configure-desktop "$DESKTOP" "$DISPLAY_BACKEND" "$DESKTOP_AUTOSTART" "$USERNAME"
rm -rf /tmp/droidspaces-start
EOF_RUN
# Mesa 驱动适配
RUN if [ "$ENABLE_mesa_ARG" = "true" ]; then \
/usr/local/sbin/install-mesa --1; \
else \
echo "--> [跳过] 未开启 Mesa 驱动安装"; \
fi
# 从 Google 官方 APT 软件源安装原生 ARM64 Chrome,替换 Chromium。
RUN if [ "$DESKTOP" != "none" ]; then \
install -d -m 0755 /etc/apt/keyrings /etc/apt/sources.list.d && \
curl -fsSL https://dl.google.com/linux/linux_signing_key.pub -o /etc/apt/keyrings/google-chrome.asc && \
grep -q 'BEGIN PGP PUBLIC KEY BLOCK' /etc/apt/keyrings/google-chrome.asc && \
printf 'deb [arch=arm64 signed-by=/etc/apt/keyrings/google-chrome.asc] https://dl.google.com/linux/chrome/deb/ stable main\n' > /etc/apt/sources.list.d/google-chrome.list && \
apt-get update && \
apt-get install -y --no-install-recommends google-chrome-stable; \
else \
echo "--> [跳过] 命令行 RootFS 不安装 Google Chrome"; \
fi
# 修复容器内的 DHCP 网络服务配置
RUN mkdir -p /etc/systemd/network && \
cat <<'EOF' > /etc/systemd/network/10-eth-dhcp.network
[Match]
Name=eth*
[Network]
DHCP=yes
IPv6AcceptRA=yes
[DHCPv4]
UseDNS=yes
UseDomains=yes
RouteMetric=100
EOF
# 应用 Android 运行环境兼容性修复(重点针对 Systemd 和 Udev)
RUN <<'EOF_RUN'
# --- 1. 常规兼容性修复 ---
grep -q '^aid_inet:' /etc/group || echo 'aid_inet:x:3003:' >> /etc/group
grep -q '^aid_net_raw:' /etc/group || echo 'aid_net_raw:x:3004:' >> /etc/group
grep -q '^aid_net_admin:' /etc/group || echo 'aid_net_admin:x:3005:' >> /etc/group
getent group droidspaces-gpu >/dev/null || groupadd -g 786 -r droidspaces-gpu
usermod -a -G aid_inet,aid_net_raw,input,video,tty,droidspaces-gpu root || true
usermod -a -G aid_inet,aid_net_raw,input,video,tty,sudo,droidspaces-gpu ${USERNAME} || true
grep -q '^_apt:' /etc/passwd && usermod -g aid_inet _apt || true
if [ -f /etc/adduser.conf ]; then
sed -i '/^EXTRA_GROUPS=/d; /^ADD_EXTRA_GROUPS=/d' /etc/adduser.conf
echo 'ADD_EXTRA_GROUPS=1' >> /etc/adduser.conf
echo 'EXTRA_GROUPS="aid_inet aid_net_raw input video tty"' >> /etc/adduser.conf
fi
# --- 2. 针对 Systemd 的特定修复 ---
ln -sf /dev/null /etc/systemd/system/systemd-networkd-wait-online.service
ln -sf /dev/null /etc/systemd/system/systemd-journald-audit.socket
cat >> /etc/systemd/journald.conf << 'EOT'
[Journal]
ReadKMsg=no
Audit=no
Storage=volatile
EOT
mkdir -p /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/ds-logging.conf << 'EOT'
[Journal]
SystemMaxUse=200M
RuntimeMaxUse=200M
MaxRetentionSec=7day
MaxLevelStore=info
EOT
mkdir -p /etc/systemd/system/multi-user.target.wants
GUEST_SYSTEMD_PATH="/lib/systemd/system"
if [ -f "$GUEST_SYSTEMD_PATH/dbus.service" ]; then
ln -sf "$GUEST_SYSTEMD_PATH/dbus.service" "/etc/systemd/system/multi-user.target.wants/dbus.service"
fi
if [ "$ENABLE_yj_ARG" = "true" ]; then
for service in systemd-udevd.service systemd-resolved.service systemd-networkd.service NetworkManager.service; do
if [ -f "$GUEST_SYSTEMD_PATH/$service" ]; then
ln -sf "$GUEST_SYSTEMD_PATH/$service" "/etc/systemd/system/multi-user.target.wants/$service"
fi
done
else
for service in systemd-udevd.service systemd-resolved.service systemd-networkd.service NetworkManager.service; do
ln -sf /dev/null "/etc/systemd/system/$service"
done
fi
mkdir -p /etc/systemd/logind.conf.d
cat > /etc/systemd/logind.conf.d/99-power-key.conf << 'EOF'
[Login]
HandlePowerKey=ignore
HandleSuspendKey=ignore
HandleHibernateKey=ignore
HandlePowerKeyLongPress=ignore
HandlePowerKeyLongPressHibernate=ignore
EOF
mkdir -p /etc/systemd/system/systemd-udev-trigger.service.d
cat > /etc/systemd/system/systemd-udev-trigger.service.d/override.conf << 'EOF'
[Service]
ExecStart=
ExecStart=-/usr/bin/udevadm trigger --subsystem-match=usb --subsystem-match=block --subsystem-match=input --subsystem-match=tty --subsystem-match=net
EOF
for unit in systemd-udevd.service systemd-udev-trigger.service systemd-udev-settle.service systemd-udevd-kernel.socket systemd-udevd-control.socket; do
mkdir -p "/etc/systemd/system/${unit}.d"
printf "[Unit]\nConditionPathIsReadWrite=\n" > "/etc/systemd/system/${unit}.d/99-readonly-fix.conf"
done
for unit in NetworkManager.service dhcpcd.service systemd-resolved.service systemd-networkd.service; do
if [ -f "$GUEST_SYSTEMD_PATH/$unit" ] || [ -f "/etc/systemd/system/multi-user.target.wants/$unit" ]; then
mkdir -p "/etc/systemd/system/${unit}.d"
cat > "/etc/systemd/system/${unit}.d/99-netmode-limit.conf" << 'EOF'
[Service]
ExecCondition=
ExecCondition=/bin/sh -c "grep -qE 'net_mode=(nat|gateway)' /run/droidspaces/container.config"
EOF
fi
done
for unit in systemd-udevd.service systemd-udev-trigger.service systemd-udev-settle.service; do
if [ -f "$GUEST_SYSTEMD_PATH/$unit" ] || [ -f "/etc/systemd/system/multi-user.target.wants/$unit" ]; then
mkdir -p "/etc/systemd/system/${unit}.d"
cat > "/etc/systemd/system/${unit}.d/99-hwaccess-limit.conf" << 'EOF'
[Service]
ExecCondition=
ExecCondition=/bin/sh -c "grep -q 'enable_hw_access=1' /run/droidspaces/container.config"
EOF
fi
done
if [ -f /etc/logrotate.conf ]; then
sed -i 's/^#maxsize.*/maxsize 50M/' /etc/logrotate.conf
if ! grep -q "maxsize 50M" /etc/logrotate.conf; then
echo "maxsize 50M" >> /etc/logrotate.conf
fi
fi
echo "Post-extraction fixes applied on $(date)" > /etc/droidspaces
EOF_RUN
COPY scripts/binfmt/qemu-binfmt-register.sh /usr/local/bin/
COPY scripts/binfmt/qemu-binfmt-register.service /etc/systemd/system/
RUN if [ "$ENABLE_binfmt_ARG" = "false" ]; then \
rm -rf /usr/local/bin/qemu-binfmt-register.sh && \
rm -rf /etc/systemd/system/qemu-binfmt-register.service ; \
fi
RUN if [ "$ENABLE_binfmt_ARG" = "true" ]; then \
chmod +x /usr/local/bin/qemu-binfmt-register.sh && \
chmod 644 /etc/systemd/system/qemu-binfmt-register.service && \
mkdir -p /etc/systemd/system/multi-user.target.wants && \
ln -sf /etc/systemd/system/qemu-binfmt-register.service /etc/systemd/system/multi-user.target.wants/qemu-binfmt-register.service && \
(apt-get purge -y qemu-* binfmt-support || true) && \
apt-get autoremove -y && \
apt-get autoclean && \
rm -rf /var/lib/binfmts/* /etc/binfmt.d/* /usr/lib/binfmt.d/qemu-* && \
dpkg --add-architecture amd64 && \
sed -i '/^Types: deb/a Architectures: arm64' /etc/apt/sources.list.d/ubuntu.sources && \
printf "Types: deb\nURIs: http://archive.ubuntu.com/ubuntu/\nSuites: resolute resolute-updates resolute-security\nComponents: main universe restricted multiverse\nArchitectures: amd64\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg\n" > /etc/apt/sources.list.d/ubuntu-amd64.sources && \
apt-get update && \
(apt-get install -y --no-install-recommends qemu-user-binfmt libc6:amd64 libc6:arm64 libc-bin || \
apt-get install -y --no-install-recommends qemu-user-binfmt) && \
apt-get clean; \
else \
rm -f /usr/local/bin/qemu-binfmt-register.sh /etc/systemd/system/qemu-binfmt-register.service; \
fi
# 可选:为 Ubuntu 26.04 的旧 Android 内核运行环境构建 systemd 257。
RUN if [ "$ENABLE_systemd257_ARG" = "true" ]; then \
bash /usr/local/sbin/systemd257; \
else \
echo "--> [跳过] 未启用 systemd 257 旧内核兼容"; \
fi && \
rm -f /usr/local/sbin/systemd257
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
FROM scratch AS export
COPY --from=customizer / /