|
2 | 2 | # Bootstrap Termux environment. |
3 | 3 | FROM scratch AS bootstrap |
4 | 4 |
|
5 | | -ARG BOOTSTRAP_VERSION=2023.02.19-r1%2Bapt-android-7 |
6 | | -ARG BOOTSTRAP_ARCH=i686 |
7 | | -ARG SYSTEM_TYPE=x86 |
| 5 | +ARG TERMUX_DOCKER__ROOTFS |
| 6 | +ARG TERMUX__PREFIX |
| 7 | +ARG TERMUX__CACHE_DIR |
8 | 8 |
|
9 | | -# Docker uses /bin/sh by default, but we don't have it currently. |
10 | | -SHELL ["/system/bin/sh", "-c"] |
11 | | -ENV PATH /system/bin |
| 9 | +# Install generated rootfs containing: |
| 10 | +# - termux bootstrap |
| 11 | +# - aosp-libs (bionic libc, linker, boringssl, zlib, libicuuc, debuggerd) |
| 12 | +# - aosp-utils (toybox, mksh, iputils) |
| 13 | +# - libandroid-stub |
| 14 | +# - dnsmasq |
| 15 | +# Since /system is now a symbolic link to $PREFIX/opt/aosp, |
| 16 | +# which has contents that can be updated by the system user via apt, |
| 17 | +# the entire rootfs is now owned by the system user (1000:1000). |
| 18 | +COPY --chown=1000:1000 ${TERMUX_DOCKER__ROOTFS} / |
12 | 19 |
|
13 | | -# Copy libc, linker and few utilities. |
14 | | -COPY /system/$SYSTEM_TYPE /system |
| 20 | +# Docker uses /bin/sh by default, but we don't have it. |
| 21 | +ENV PATH=/system/bin |
| 22 | +SHELL ["sh", "-c"] |
15 | 23 |
|
16 | | -# Copy entrypoint script. |
17 | | -COPY /entrypoint.sh /entrypoint.sh |
18 | | -COPY /entrypoint_root.sh /entrypoint_root.sh |
19 | | - |
20 | | -# Extract bootstrap archive and create symlinks. |
21 | | -ADD https://github.com/termux/termux-packages/releases/download/bootstrap-$BOOTSTRAP_VERSION/bootstrap-$BOOTSTRAP_ARCH.zip /bootstrap.zip |
22 | | -RUN busybox mkdir -p /data/data/com.termux/files && \ |
23 | | - cd /data/data/com.termux/files && \ |
24 | | - busybox mkdir ../cache ./usr ./home && \ |
25 | | - busybox unzip -d usr /bootstrap.zip && \ |
26 | | - busybox rm /bootstrap.zip && \ |
27 | | - cd ./usr && \ |
28 | | - busybox cat SYMLINKS.txt | while read -r line; do \ |
29 | | - dest=$(echo "$line" | busybox awk -F '←' '{ print $1 }'); \ |
30 | | - link=$(echo "$line" | busybox awk -F '←' '{ print $2 }'); \ |
31 | | - busybox ln -s "$dest" "$link"; \ |
32 | | - done && \ |
33 | | - busybox rm SYMLINKS.txt && \ |
34 | | - busybox ln -s /data/data/com.termux/files/usr /usr && \ |
35 | | - busybox ln -s /data/data/com.termux/files/usr/bin /bin && \ |
36 | | - busybox ln -s /data/data/com.termux/files/usr/tmp /tmp |
37 | | - |
38 | | -# Link some utilities to busybox. |
39 | | -# Some utilities in $PREFIX are actually a wrapper of the same binary |
40 | | -# from /system/bin. See termux-tools/build.sh#L29. |
41 | | -RUN for tool in df mount ping ping6 su top umount; do \ |
42 | | - busybox ln -s /system/bin/busybox /system/bin/$tool; \ |
43 | | - done |
44 | | - |
45 | | -# Set ownership and file access modes: |
46 | | -# * User content is owned by 1000:1000. |
47 | | -# * Termux file modes are set only for user. |
48 | | -# * Rest is owned by root and has 755/644 modes. |
49 | | -RUN busybox chown -Rh 0:0 /system && \ |
50 | | - busybox chown -Rh 1000:1000 /data/data/com.termux && \ |
51 | | - busybox ln -s /system/etc/passwd /etc/passwd && \ |
52 | | - busybox ln -s /system/etc/group /etc/group && \ |
53 | | - busybox find /system -type d -exec busybox chmod 755 "{}" \; && \ |
54 | | - busybox find /system -type f -executable -exec busybox chmod 755 "{}" \; && \ |
55 | | - busybox find /system -type f ! -executable -exec busybox chmod 644 "{}" \; && \ |
56 | | - busybox find /data -type d -exec busybox chmod 755 "{}" \; && \ |
57 | | - busybox find /data/data/com.termux/files -type f -o -type d -exec busybox chmod g-rwx,o-rwx "{}" \; && \ |
58 | | - cd /data/data/com.termux/files/usr && \ |
59 | | - busybox find ./bin ./lib/apt ./libexec -type f -exec busybox chmod 700 "{}" \; |
60 | | - |
61 | | -# Install updates and cleanup when not building for arm. |
62 | | -ENV PATH /data/data/com.termux/files/usr/bin |
63 | | -RUN if [ ${SYSTEM_TYPE} = 'arm' ]; then exit; else \ |
64 | | - /system/bin/mksh -T /dev/ptmx -c "/system/bin/dnsmasq -u root -g root --pid-file /dnsmasq.pid" && sleep 1 && \ |
65 | | - su - system -c "/data/data/com.termux/files/usr/bin/apt update" && \ |
66 | | - su - system -c "/data/data/com.termux/files/usr/bin/apt upgrade -o Dpkg::Options::=--force-confnew -yq" && \ |
67 | | - rm -rf /data/data/com.termux/files/usr/var/lib/apt/* && \ |
68 | | - rm -rf /data/data/com.termux/files/usr/var/log/apt/* && \ |
69 | | - rm -rf /data/data/com.termux/cache/apt/* ;\ |
70 | | - fi |
| 24 | +# Install updates and cleanup |
| 25 | +# Start dnsmasq to resolve hostnames, and, |
| 26 | +# for some reason the -c argument of toybox-su is not working, |
| 27 | +# so this odd-looking script forces the update process |
| 28 | +# to work using the -s argument of toybox-su instead, which is working. |
| 29 | +RUN sh -T /dev/ptmx -c "$TERMUX__PREFIX/bin/dnsmasq -u root -g root --pid-file=/dnsmasq.pid" && \ |
| 30 | + sleep 1 && \ |
| 31 | + echo '#!/system/bin/sh' > /update.sh && \ |
| 32 | + echo "PATH=$TERMUX__PREFIX/bin" >> /update.sh && \ |
| 33 | + echo 'apt update' >> /update.sh && \ |
| 34 | + echo 'apt upgrade -o Dpkg::Options::=--force-confnew -y' >> /update.sh && \ |
| 35 | + chmod +x /update.sh && \ |
| 36 | + su system -s /update.sh && \ |
| 37 | + rm -f /update.sh && \ |
| 38 | + rm -rf "${TERMUX__PREFIX}"/var/lib/apt/* && \ |
| 39 | + rm -rf "${TERMUX__PREFIX}"/var/log/apt/* && \ |
| 40 | + rm -rf "${TERMUX__CACHE_DIR}"/apt/* |
71 | 41 |
|
72 | 42 | ############################################################################## |
73 | 43 | # Create final image. |
74 | 44 | FROM scratch |
75 | 45 |
|
76 | | -ENV ANDROID_DATA /data |
77 | | -ENV ANDROID_ROOT /system |
78 | | -ENV HOME /data/data/com.termux/files/home |
79 | | -ENV LANG en_US.UTF-8 |
80 | | -ENV PATH /data/data/com.termux/files/usr/bin |
81 | | -ENV PREFIX /data/data/com.termux/files/usr |
82 | | -ENV TMPDIR /data/data/com.termux/files/usr/tmp |
83 | | -ENV TZ UTC |
| 46 | +ARG TERMUX__PREFIX |
| 47 | +ARG TERMUX__HOME |
| 48 | + |
| 49 | +ENV ANDROID_DATA=/data |
| 50 | +ENV ANDROID_ROOT=/system |
| 51 | +ENV HOME=${TERMUX__HOME} |
| 52 | +ENV LANG=en_US.UTF-8 |
| 53 | +ENV PATH=${TERMUX__PREFIX}/bin |
| 54 | +ENV PREFIX=${TERMUX__PREFIX} |
| 55 | +ENV TMPDIR=${TERMUX__PREFIX}/tmp |
| 56 | +ENV TZ=UTC |
| 57 | +ENV TERM=xterm |
84 | 58 |
|
85 | 59 | COPY --from=bootstrap / / |
86 | 60 |
|
87 | | -WORKDIR /data/data/com.termux/files/home |
88 | | -SHELL ["/data/data/com.termux/files/usr/bin/sh", "-c"] |
| 61 | +WORKDIR ${TERMUX__HOME} |
| 62 | +SHELL ["sh", "-c"] |
89 | 63 |
|
90 | 64 | ENTRYPOINT ["/entrypoint.sh"] |
91 | | -CMD ["/data/data/com.termux/files/usr/bin/login"] |
| 65 | +CMD ["login"] |
0 commit comments