Skip to content

Commit 5169f1f

Browse files
committed
deblobbify, replacing the system folder with several other components
1 parent e3c861f commit 5169f1f

File tree

99 files changed

+889
-2460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+889
-2460
lines changed

.github/workflows/docker_build.yml

Lines changed: 156 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,162 @@ env:
1414
DOCKER_BUILDKIT: 1
1515

1616
jobs:
17-
main:
17+
aarch64:
18+
runs-on: ubuntu-24.04-arm
19+
steps:
20+
21+
- name: Clone repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set architecture variable
25+
run: echo "ARCHITECTURE=$(uname -m)" >> $GITHUB_ENV
26+
27+
- name: Build image
28+
run: ./generate.sh
29+
30+
- name: Login to Docker Hub
31+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-docker'
32+
uses: docker/login-action@v3
33+
with:
34+
username: grimler
35+
password: ${{ secrets.GRIMLER_DOCKER_TOKEN }}
36+
37+
- name: Push to Docker Hub
38+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-docker'
39+
run: |
40+
docker push termux/termux-docker:${{ matrix.CPU_ARCH }}
41+
if [ ${{ matrix.CPU_ARCH }} = i686 ]; then
42+
docker tag termux/termux-docker:i686 termux/termux-docker:latest
43+
docker push termux/termux-docker:latest
44+
fi
45+
46+
- name: Export container as tar archive
47+
if: always()
48+
run: |
49+
docker run \
50+
--name termux-docker \
51+
termux/termux-docker:"${ARCHITECTURE}" \
52+
uname -a
53+
docker stop termux-docker
54+
docker export -o termux-docker.tar \
55+
termux-docker
56+
sha256sum termux-docker.tar
57+
58+
- name: Store tar archive
59+
if: always()
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: termux-docker-${{ github.sha }}
63+
path: termux-docker.tar
64+
65+
arm:
66+
runs-on: ubuntu-24.04-arm
67+
steps:
68+
69+
- name: Clone repository
70+
uses: actions/checkout@v4
71+
72+
- name: Set architecture variable
73+
run: echo "ARCHITECTURE=arm" >> $GITHUB_ENV
74+
75+
- name: Build image
76+
run: ./generate.sh
77+
78+
- name: Login to Docker Hub
79+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-docker'
80+
uses: docker/login-action@v3
81+
with:
82+
username: grimler
83+
password: ${{ secrets.GRIMLER_DOCKER_TOKEN }}
84+
85+
- name: Push to Docker Hub
86+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-docker'
87+
run: |
88+
docker push termux/termux-docker:${{ matrix.CPU_ARCH }}
89+
if [ ${{ matrix.CPU_ARCH }} = i686 ]; then
90+
docker tag termux/termux-docker:i686 termux/termux-docker:latest
91+
docker push termux/termux-docker:latest
92+
fi
93+
94+
- name: Export container as tar archive
95+
if: always()
96+
run: |
97+
docker run \
98+
--name termux-docker \
99+
termux/termux-docker:"${ARCHITECTURE}" \
100+
uname -a
101+
docker stop termux-docker
102+
docker export -o termux-docker.tar \
103+
termux-docker
104+
sha256sum termux-docker.tar
105+
106+
- name: Store tar archive
107+
if: always()
108+
uses: actions/upload-artifact@v4
109+
with:
110+
name: termux-docker-${{ github.sha }}
111+
path: termux-docker.tar
112+
113+
x86_64:
18114
runs-on: ubuntu-latest
19-
strategy:
20-
matrix:
21-
CPU_ARCH:
22-
- aarch64
23-
- arm
24-
- i686
25-
- x86_64
26115
steps:
27116

28117
- name: Clone repository
29118
uses: actions/checkout@v4
30119

31-
- name: Setup binfmt_misc
32-
if: (matrix.CPU_ARCH == 'aarch64') || (matrix.CPU_ARCH == 'arm')
33-
run: docker run --rm --privileged aptman/qus -s -- -p aarch64 arm
120+
- name: Set architecture variable
121+
run: echo "ARCHITECTURE=$(uname -m)" >> $GITHUB_ENV
34122

35-
- name: Build images
123+
- name: Build image
124+
run: ./generate.sh
125+
126+
- name: Login to Docker Hub
127+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-docker'
128+
uses: docker/login-action@v3
129+
with:
130+
username: grimler
131+
password: ${{ secrets.GRIMLER_DOCKER_TOKEN }}
132+
133+
- name: Push to Docker Hub
134+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-docker'
36135
run: |
37-
case '${{ matrix.CPU_ARCH }}' in
38-
arm) SYSTEM_TYPE=arm; PLATFORM_TAG="linux/arm/v7";;
39-
aarch64) SYSTEM_TYPE=arm; PLATFORM_TAG="linux/arm64";;
40-
i686) SYSTEM_TYPE=x86; PLATFORM_TAG="linux/386";;
41-
*) SYSTEM_TYPE=x86; PLATFORM_TAG="linux/amd64";;
42-
esac
43-
docker buildx build -t \
44-
termux/termux-docker:${{ matrix.CPU_ARCH }} \
45-
--platform "$PLATFORM_TAG" \
46-
--build-arg BOOTSTRAP_ARCH=${{ matrix.CPU_ARCH }} \
47-
--build-arg SYSTEM_TYPE="${SYSTEM_TYPE}" \
48-
.
136+
docker push termux/termux-docker:${{ matrix.CPU_ARCH }}
137+
if [ ${{ matrix.CPU_ARCH }} = i686 ]; then
138+
docker tag termux/termux-docker:i686 termux/termux-docker:latest
139+
docker push termux/termux-docker:latest
140+
fi
141+
142+
- name: Export container as tar archive
143+
if: always()
144+
run: |
145+
docker run \
146+
--name termux-docker \
147+
termux/termux-docker:"${ARCHITECTURE}" \
148+
uname -a
149+
docker stop termux-docker
150+
docker export -o termux-docker.tar \
151+
termux-docker
152+
sha256sum termux-docker.tar
153+
154+
- name: Store tar archive
155+
if: always()
156+
uses: actions/upload-artifact@v4
157+
with:
158+
name: termux-docker-${{ github.sha }}
159+
path: termux-docker.tar
160+
161+
i686:
162+
runs-on: ubuntu-latest
163+
steps:
164+
165+
- name: Clone repository
166+
uses: actions/checkout@v4
167+
168+
- name: Set architecture variable
169+
run: echo "ARCHITECTURE=i686" >> $GITHUB_ENV
170+
171+
- name: Build image
172+
run: ./generate.sh
49173

50174
- name: Login to Docker Hub
51175
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-docker'
@@ -67,18 +191,17 @@ jobs:
67191
if: always()
68192
run: |
69193
docker run \
70-
--privileged \
71-
--name termux-docker-${{ matrix.CPU_ARCH }} \
72-
termux/termux-docker:${{ matrix.CPU_ARCH }} \
194+
--name termux-docker \
195+
termux/termux-docker:"${ARCHITECTURE}" \
73196
uname -a
74-
docker stop termux-docker-${{ matrix.CPU_ARCH }}
75-
docker export -o termux-docker-${{ matrix.CPU_ARCH }}.tar \
76-
termux-docker-${{ matrix.CPU_ARCH }}
77-
sha256sum termux-docker-${{ matrix.CPU_ARCH }}.tar
197+
docker stop termux-docker
198+
docker export -o termux-docker.tar \
199+
termux-docker
200+
sha256sum termux-docker.tar
78201
79202
- name: Store tar archive
80203
if: always()
81204
uses: actions/upload-artifact@v4
82205
with:
83-
name: termux-docker-${{ matrix.CPU_ARCH }}-${{ github.sha }}
84-
path: termux-docker-${{ matrix.CPU_ARCH }}.tar
206+
name: termux-docker-${{ github.sha }}
207+
path: termux-docker.tar

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
termux-docker-rootfs

Dockerfile

Lines changed: 47 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,50 @@
1-
##############################################################################
2-
# Bootstrap Termux environment.
3-
FROM scratch AS bootstrap
4-
5-
ARG BOOTSTRAP_VERSION=2023.02.19-r1%2Bapt-android-7
6-
ARG BOOTSTRAP_ARCH=i686
7-
ARG SYSTEM_TYPE=x86
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
12-
13-
# Copy libc, linker and few utilities.
14-
COPY /system/$SYSTEM_TYPE /system
15-
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
71-
72-
##############################################################################
73-
# Create final image.
741
FROM scratch
752

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
84-
85-
COPY --from=bootstrap / /
86-
87-
WORKDIR /data/data/com.termux/files/home
88-
SHELL ["/data/data/com.termux/files/usr/bin/sh", "-c"]
89-
3+
ARG ROOTFS
4+
ARG TERMUX_APP_PACKAGE
5+
ARG TERMUX_BASE_DIR
6+
ARG TERMUX_PREFIX
7+
8+
# Install generated rootfs containing bionic libc,
9+
# toybox, mksh, iputils, dnsmasq, and termux bootstrap
10+
COPY --chown=1000:1000 ${ROOTFS} /
11+
12+
# Docker uses /bin/sh by default, but we don't have it.
13+
# This ENV PATH line selects /system/bin/sh.
14+
# The final ENV PATH line later below then selects
15+
# $TERMUX_PREFIX/bin/sh -> bash without having
16+
# to add an additional SHELL line.
17+
ENV PATH=/system/bin
18+
SHELL ["sh", "-c"]
19+
20+
# Install updates and cleanup
21+
# Start dnsmasq to resolve hostnames, and,
22+
# for some reason the -c argument of toybox-su is not working,
23+
# so this odd-looking script forces the update process
24+
# to work using the -s argument of toybox-su instead, which is working.
25+
RUN sh -T /dev/ptmx -c "$TERMUX_PREFIX/bin/dnsmasq -u root -g root --pid-file=/dnsmasq.pid" && \
26+
sleep 1 && \
27+
echo '#!/system/bin/sh' > /update.sh && \
28+
echo "PATH=$TERMUX_PREFIX/bin" >> /update.sh && \
29+
echo 'pkg update' >> /update.sh && \
30+
echo 'apt-get upgrade -o Dpkg::Options::=--force-confnew -y' >> /update.sh && \
31+
chmod +x /update.sh && \
32+
su system -s /update.sh && \
33+
rm -f /update.sh && \
34+
rm -rf ${TERMUX_PREFIX}/var/lib/apt/* && \
35+
rm -rf ${TERMUX_PREFIX}/var/log/apt/* && \
36+
rm -rf /data/data/${TERMUX_APP_PACKAGE}/cache/apt/*
37+
38+
ENV ANDROID_DATA=/data
39+
ENV ANDROID_ROOT=/system
40+
ENV HOME=${TERMUX_BASE_DIR}/home
41+
ENV LANG=en_US.UTF-8
42+
ENV PATH=${TERMUX_PREFIX}/bin
43+
ENV PREFIX=${TERMUX_PREFIX}
44+
ENV TMPDIR=${TERMUX_PREFIX}/tmp
45+
ENV TZ=UTC
46+
ENV TERM=xterm
47+
48+
WORKDIR ${TERMUX_BASE_DIR}/home
9049
ENTRYPOINT ["/entrypoint.sh"]
91-
CMD ["/data/data/com.termux/files/usr/bin/login"]
50+
CMD ["login"]

0 commit comments

Comments
 (0)