Repository navigation
Expand file tree
/
Copy pathDockerfile.test
More file actions
131 lines (107 loc) · 7.86 KB
/
Copy pathDockerfile.test
File metadata and controls
131 lines (107 loc) · 7.86 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
# =============================================================================
# Dockerfile.test — Test macbook_hardware_fixer.sh on Ubuntu 26.04
#
# Tests: package availability, config file generation, script logic, sysctl syntax
# Does NOT test: systemd services, kernel modules, hardware-specific paths
#
# Usage:
# docker build -f Dockerfile.test -t macbook-test .
# docker run --rm macbook-test
#
# Or via make:
# make test-docker
# =============================================================================
FROM ubuntu:26.04
# Non-interactive apt — prevents ALL interactive prompts including dpkg conffile
ENV DEBIAN_FRONTEND=noninteractive
ENV TERM=xterm-256color
# Force dpkg to keep new conffiles without prompting
RUN echo 'Dpkg::Options { "--force-confnew"; "--force-confdef"; }' \
> /etc/apt/apt.conf.d/99-docker-no-prompts
# Simulate SUDO_USER so gsettings/git blocks run
ENV SUDO_USER=testuser
# ─────────────────────────────────────────────────────────────────────────────
# Base tools needed before running the script
# ─────────────────────────────────────────────────────────────────────────────
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
sudo bash python3 iw \
2>/dev/null || true
# ─────────────────────────────────────────────────────────────────────────────
# Mock system commands that require hardware or systemd
# Each mock logs what it would do and exits 0 (non-blocking)
# ─────────────────────────────────────────────────────────────────────────────
# systemctl: log calls, always succeed
RUN printf '#!/bin/bash\necho " [MOCK] systemctl $*"\nexit 0\n' \
> /usr/local/bin/systemctl && chmod +x /usr/local/bin/systemctl
# udevadm: log and succeed
RUN printf '#!/bin/bash\necho " [MOCK] udevadm $*"\nexit 0\n' \
> /usr/local/bin/udevadm && chmod +x /usr/local/bin/udevadm
# update-grub / grub-mkconfig: log and succeed
RUN printf '#!/bin/bash\necho " [MOCK] update-grub $*"\nexit 0\n' \
> /usr/local/bin/update-grub && chmod +x /usr/local/bin/update-grub
RUN printf '#!/bin/bash\necho " [MOCK] grub-mkconfig $*"\nexit 0\n' \
> /usr/local/bin/grub-mkconfig && chmod +x /usr/local/bin/grub-mkconfig
# update-initramfs: log and succeed
RUN printf '#!/bin/bash\necho " [MOCK] update-initramfs $*"\nexit 0\n' \
> /usr/local/bin/update-initramfs && chmod +x /usr/local/bin/update-initramfs
# sensors-detect: interactive tool, mock it
RUN printf '#!/bin/bash\necho " [MOCK] sensors-detect (skipped in container)"\nexit 0\n' \
> /usr/local/bin/sensors-detect && chmod +x /usr/local/bin/sensors-detect
# gsettings: log and succeed (no GNOME in container)
RUN printf '#!/bin/bash\necho " [MOCK] gsettings $*"\nexit 0\n' \
> /usr/local/bin/gsettings && chmod +x /usr/local/bin/gsettings
# hciconfig: log and succeed (no BT hardware)
RUN printf '#!/bin/bash\necho " [MOCK] hciconfig $*"\nexit 0\n' \
> /usr/local/bin/hciconfig && chmod +x /usr/local/bin/hciconfig
# rfkill: return empty list (no BT hardware)
RUN printf '#!/bin/bash\necho " [MOCK] rfkill $*"\nexit 0\n' \
> /usr/local/bin/rfkill && chmod +x /usr/local/bin/rfkill
# fstrim: log and succeed (no real filesystem to trim)
RUN printf '#!/bin/bash\necho " [MOCK] fstrim $*"\nexit 0\n' \
> /usr/local/bin/fstrim && chmod +x /usr/local/bin/fstrim
# apfs-fuse: not available in container, fail gracefully so BT firmware scan skips
RUN printf '#!/bin/bash\necho " [MOCK] apfs-fuse: no macOS partition"\nexit 1\n' \
> /usr/local/bin/apfs-fuse && chmod +x /usr/local/bin/apfs-fuse
# boltctl: log and succeed
RUN printf '#!/bin/bash\necho " [MOCK] boltctl $*"\nexit 0\n' \
> /usr/local/bin/boltctl && chmod +x /usr/local/bin/boltctl
# ─────────────────────────────────────────────────────────────────────────────
# Pre-create directories and stub files that the script writes into
# NOTE: do NOT pre-create /etc/bluetooth/main.conf — let bluez install create it
# to avoid dpkg conffile prompt during apt-get install bluez
# ─────────────────────────────────────────────────────────────────────────────
# Fake GRUB config (script modifies this to add mem_sleep_default=s2idle)
RUN echo 'GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"' > /etc/default/grub
# Fake fstab (script adds noatime to this)
RUN echo '/dev/nvme0n1p2 / ext4 defaults 0 1' > /etc/fstab
# Create testuser (simulates the logged-in user running with sudo)
RUN useradd -m -s /bin/bash testuser \
&& echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# ─────────────────────────────────────────────────────────────────────────────
# Copy project
# ─────────────────────────────────────────────────────────────────────────────
COPY . /project
WORKDIR /project
# Mock install.cirrus.driver.sh — kernel compilation is not possible in a container
# (no kernel headers, no build environment matching the container kernel).
# The mock logs that it was called and exits 0 so the rest of the script continues.
RUN printf '#!/bin/bash\necho " [MOCK] install.cirrus.driver.sh (kernel compilation skipped in container)"\necho " [MOCK] On real hardware: compiles and installs snd-hda-codec-cs8409.ko"\nexit 0\n' \
> /project/install.cirrus.driver.sh && chmod +x /project/install.cirrus.driver.sh
# ─────────────────────────────────────────────────────────────────────────────
# Run the script and propagate its exit code correctly
# ─────────────────────────────────────────────────────────────────────────────
CMD ["/bin/bash", "-c", "\
echo ''; \
echo '══════════════════════════════════════════════════════'; \
echo ' macbook_hardware_fixer.sh — Docker test run'; \
echo ' Ubuntu 26.04 container — hardware mocked'; \
echo '══════════════════════════════════════════════════════'; \
echo ''; \
bash macbook_hardware_fixer.sh; \
RC=$?; \
echo ''; \
echo '══════════════════════════════════════════════════════'; \
echo \" Script finished. Exit code: $RC\"; \
echo '══════════════════════════════════════════════════════'; \
exit $RC \
"]