1bf215546Sopenharmony_ci#!/bin/bash
2bf215546Sopenharmony_ci
3bf215546Sopenharmony_ciset -ex
4bf215546Sopenharmony_ci
5bf215546Sopenharmony_ciif [ $DEBIAN_ARCH = arm64 ]; then
6bf215546Sopenharmony_ci    ARCH_PACKAGES="firmware-qcom-media
7bf215546Sopenharmony_ci                   firmware-linux-nonfree
8bf215546Sopenharmony_ci                   libfontconfig1
9bf215546Sopenharmony_ci                   libgl1
10bf215546Sopenharmony_ci                   libglu1-mesa
11bf215546Sopenharmony_ci                   libvulkan-dev
12bf215546Sopenharmony_ci    "
13bf215546Sopenharmony_cielif [ $DEBIAN_ARCH = amd64 ]; then
14bf215546Sopenharmony_ci    # Add llvm 13 to the build image
15bf215546Sopenharmony_ci    apt-get -y install --no-install-recommends wget gnupg2 software-properties-common
16bf215546Sopenharmony_ci    apt-key add /llvm-snapshot.gpg.key
17bf215546Sopenharmony_ci    add-apt-repository "deb https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-13 main"
18bf215546Sopenharmony_ci
19bf215546Sopenharmony_ci    ARCH_PACKAGES="firmware-amd-graphics
20bf215546Sopenharmony_ci                   inetutils-syslogd
21bf215546Sopenharmony_ci                   iptables
22bf215546Sopenharmony_ci                   libcap2
23bf215546Sopenharmony_ci                   libfontconfig1
24bf215546Sopenharmony_ci                   libelf1
25bf215546Sopenharmony_ci                   libfdt1
26bf215546Sopenharmony_ci                   libgl1
27bf215546Sopenharmony_ci                   libglu1-mesa
28bf215546Sopenharmony_ci                   libllvm13
29bf215546Sopenharmony_ci                   libllvm11
30bf215546Sopenharmony_ci                   libva2
31bf215546Sopenharmony_ci                   libva-drm2
32bf215546Sopenharmony_ci                   libvulkan-dev
33bf215546Sopenharmony_ci                   socat
34bf215546Sopenharmony_ci                   spirv-tools
35bf215546Sopenharmony_ci                   sysvinit-core
36bf215546Sopenharmony_ci                  "
37bf215546Sopenharmony_cifi
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ciINSTALL_CI_FAIRY_PACKAGES="git
40bf215546Sopenharmony_ci                           python3-dev
41bf215546Sopenharmony_ci                           python3-pip
42bf215546Sopenharmony_ci                           python3-setuptools
43bf215546Sopenharmony_ci                           python3-wheel
44bf215546Sopenharmony_ci                           "
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ciapt-get update
47bf215546Sopenharmony_ciapt-get -y install --no-install-recommends \
48bf215546Sopenharmony_ci    $ARCH_PACKAGES \
49bf215546Sopenharmony_ci    $INSTALL_CI_FAIRY_PACKAGES \
50bf215546Sopenharmony_ci    $EXTRA_LOCAL_PACKAGES \
51bf215546Sopenharmony_ci    bash \
52bf215546Sopenharmony_ci    ca-certificates \
53bf215546Sopenharmony_ci    firmware-realtek \
54bf215546Sopenharmony_ci    initramfs-tools \
55bf215546Sopenharmony_ci    libasan6 \
56bf215546Sopenharmony_ci    libexpat1 \
57bf215546Sopenharmony_ci    libpng16-16 \
58bf215546Sopenharmony_ci    libpython3.9 \
59bf215546Sopenharmony_ci    libsensors5 \
60bf215546Sopenharmony_ci    libvulkan1 \
61bf215546Sopenharmony_ci    libwaffle-1-0 \
62bf215546Sopenharmony_ci    libx11-6 \
63bf215546Sopenharmony_ci    libx11-xcb1 \
64bf215546Sopenharmony_ci    libxcb-dri2-0 \
65bf215546Sopenharmony_ci    libxcb-dri3-0 \
66bf215546Sopenharmony_ci    libxcb-glx0 \
67bf215546Sopenharmony_ci    libxcb-present0 \
68bf215546Sopenharmony_ci    libxcb-randr0 \
69bf215546Sopenharmony_ci    libxcb-shm0 \
70bf215546Sopenharmony_ci    libxcb-sync1 \
71bf215546Sopenharmony_ci    libxcb-xfixes0 \
72bf215546Sopenharmony_ci    libxdamage1 \
73bf215546Sopenharmony_ci    libxext6 \
74bf215546Sopenharmony_ci    libxfixes3 \
75bf215546Sopenharmony_ci    libxkbcommon0 \
76bf215546Sopenharmony_ci    libxrender1 \
77bf215546Sopenharmony_ci    libxshmfence1 \
78bf215546Sopenharmony_ci    libxxf86vm1 \
79bf215546Sopenharmony_ci    netcat-openbsd \
80bf215546Sopenharmony_ci    python3 \
81bf215546Sopenharmony_ci    python3-lxml \
82bf215546Sopenharmony_ci    python3-mako \
83bf215546Sopenharmony_ci    python3-numpy \
84bf215546Sopenharmony_ci    python3-packaging \
85bf215546Sopenharmony_ci    python3-pil \
86bf215546Sopenharmony_ci    python3-renderdoc \
87bf215546Sopenharmony_ci    python3-requests \
88bf215546Sopenharmony_ci    python3-simplejson \
89bf215546Sopenharmony_ci    python3-yaml \
90bf215546Sopenharmony_ci    sntp \
91bf215546Sopenharmony_ci    strace \
92bf215546Sopenharmony_ci    waffle-utils \
93bf215546Sopenharmony_ci    wget \
94bf215546Sopenharmony_ci    xinit \
95bf215546Sopenharmony_ci    xserver-xorg-core
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci# Needed for ci-fairy, this revision is able to upload files to
98bf215546Sopenharmony_ci# MinIO and doesn't depend on git
99bf215546Sopenharmony_cipip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates@ffe4d1b10aab7534489f0c4bbc4c5899df17d3f2
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ciapt-get purge -y \
102bf215546Sopenharmony_ci        $INSTALL_CI_FAIRY_PACKAGES
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_cipasswd root -d
105bf215546Sopenharmony_cichsh -s /bin/sh
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_cicat > /init <<EOF
108bf215546Sopenharmony_ci#!/bin/sh
109bf215546Sopenharmony_ciexport PS1=lava-shell:
110bf215546Sopenharmony_ciexec sh
111bf215546Sopenharmony_ciEOF
112bf215546Sopenharmony_cichmod +x  /init
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci#######################################################################
115bf215546Sopenharmony_ci# Strip the image to a small minimal system without removing the debian
116bf215546Sopenharmony_ci# toolchain.
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci# Copy timezone file and remove tzdata package
119bf215546Sopenharmony_cirm -rf /etc/localtime
120bf215546Sopenharmony_cicp /usr/share/zoneinfo/Etc/UTC /etc/localtime
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ciUNNEEDED_PACKAGES="
123bf215546Sopenharmony_ci        libfdisk1
124bf215546Sopenharmony_ci        "
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ciexport DEBIAN_FRONTEND=noninteractive
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_ci# Removing unused packages
129bf215546Sopenharmony_cifor PACKAGE in ${UNNEEDED_PACKAGES}
130bf215546Sopenharmony_cido
131bf215546Sopenharmony_ci	echo ${PACKAGE}
132bf215546Sopenharmony_ci	if ! apt-get remove --purge --yes "${PACKAGE}"
133bf215546Sopenharmony_ci	then
134bf215546Sopenharmony_ci		echo "WARNING: ${PACKAGE} isn't installed"
135bf215546Sopenharmony_ci	fi
136bf215546Sopenharmony_cidone
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ciapt-get autoremove --yes || true
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_ci# Dropping logs
141bf215546Sopenharmony_cirm -rf /var/log/*
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci# Dropping documentation, localization, i18n files, etc
144bf215546Sopenharmony_cirm -rf /usr/share/doc/*
145bf215546Sopenharmony_cirm -rf /usr/share/locale/*
146bf215546Sopenharmony_cirm -rf /usr/share/X11/locale/*
147bf215546Sopenharmony_cirm -rf /usr/share/man
148bf215546Sopenharmony_cirm -rf /usr/share/i18n/*
149bf215546Sopenharmony_cirm -rf /usr/share/info/*
150bf215546Sopenharmony_cirm -rf /usr/share/lintian/*
151bf215546Sopenharmony_cirm -rf /usr/share/common-licenses/*
152bf215546Sopenharmony_cirm -rf /usr/share/mime/*
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci# Dropping reportbug scripts
155bf215546Sopenharmony_cirm -rf /usr/share/bug
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci# Drop udev hwdb not required on a stripped system
158bf215546Sopenharmony_cirm -rf /lib/udev/hwdb.bin /lib/udev/hwdb.d/*
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci# Drop all gconv conversions && binaries
161bf215546Sopenharmony_cirm -rf usr/bin/iconv
162bf215546Sopenharmony_cirm -rf usr/sbin/iconvconfig
163bf215546Sopenharmony_cirm -rf usr/lib/*/gconv/
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci# Remove libusb database
166bf215546Sopenharmony_cirm -rf usr/sbin/update-usbids
167bf215546Sopenharmony_cirm -rf var/lib/usbutils/usb.ids
168bf215546Sopenharmony_cirm -rf usr/share/misc/usb.ids
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_cirm -rf /root/.pip
171bf215546Sopenharmony_ci
172bf215546Sopenharmony_ci#######################################################################
173bf215546Sopenharmony_ci# Crush into a minimal production image to be deployed via some type of image
174bf215546Sopenharmony_ci# updating system.
175bf215546Sopenharmony_ci# IMPORTANT: The Debian system is not longer functional at this point,
176bf215546Sopenharmony_ci# for example, apt and dpkg will stop working
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ciUNNEEDED_PACKAGES="apt libapt-pkg6.0 "\
179bf215546Sopenharmony_ci"ncurses-bin ncurses-base libncursesw6 libncurses6 "\
180bf215546Sopenharmony_ci"perl-base "\
181bf215546Sopenharmony_ci"debconf libdebconfclient0 "\
182bf215546Sopenharmony_ci"e2fsprogs e2fslibs libfdisk1 "\
183bf215546Sopenharmony_ci"insserv "\
184bf215546Sopenharmony_ci"udev "\
185bf215546Sopenharmony_ci"init-system-helpers "\
186bf215546Sopenharmony_ci"cpio "\
187bf215546Sopenharmony_ci"passwd "\
188bf215546Sopenharmony_ci"libsemanage1 libsemanage-common "\
189bf215546Sopenharmony_ci"libsepol1 "\
190bf215546Sopenharmony_ci"gpgv "\
191bf215546Sopenharmony_ci"hostname "\
192bf215546Sopenharmony_ci"adduser "\
193bf215546Sopenharmony_ci"debian-archive-keyring "\
194bf215546Sopenharmony_ci"libegl1-mesa-dev "\
195bf215546Sopenharmony_ci"libegl-mesa0 "\
196bf215546Sopenharmony_ci"libgl1-mesa-dev "\
197bf215546Sopenharmony_ci"libgl1-mesa-dri "\
198bf215546Sopenharmony_ci"libglapi-mesa "\
199bf215546Sopenharmony_ci"libgles2-mesa-dev "\
200bf215546Sopenharmony_ci"libglx-mesa0 "\
201bf215546Sopenharmony_ci"mesa-common-dev "\
202bf215546Sopenharmony_ci"gnupg2 "\
203bf215546Sopenharmony_ci"software-properties-common " \
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci# Removing unneeded packages
206bf215546Sopenharmony_cifor PACKAGE in ${UNNEEDED_PACKAGES}
207bf215546Sopenharmony_cido
208bf215546Sopenharmony_ci	echo "Forcing removal of ${PACKAGE}"
209bf215546Sopenharmony_ci	if ! dpkg --purge --force-remove-essential --force-depends "${PACKAGE}"
210bf215546Sopenharmony_ci	then
211bf215546Sopenharmony_ci		echo "WARNING: ${PACKAGE} isn't installed"
212bf215546Sopenharmony_ci	fi
213bf215546Sopenharmony_cidone
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci# Show what's left package-wise before dropping dpkg itself
216bf215546Sopenharmony_ciCOLUMNS=300 dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1n
217bf215546Sopenharmony_ci
218bf215546Sopenharmony_ci# Drop dpkg
219bf215546Sopenharmony_cidpkg --purge --force-remove-essential --force-depends  dpkg
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_ci# No apt or dpkg, no need for its configuration archives
222bf215546Sopenharmony_cirm -rf etc/apt
223bf215546Sopenharmony_cirm -rf etc/dpkg
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ci# Drop directories not part of ostree
226bf215546Sopenharmony_ci# Note that /var needs to exist as ostree bind mounts the deployment /var over
227bf215546Sopenharmony_ci# it
228bf215546Sopenharmony_cirm -rf var/* opt srv share
229bf215546Sopenharmony_ci
230bf215546Sopenharmony_ci# ca-certificates are in /etc drop the source
231bf215546Sopenharmony_cirm -rf usr/share/ca-certificates
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci# No need for completions
234bf215546Sopenharmony_cirm -rf usr/share/bash-completion
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci# No zsh, no need for comletions
237bf215546Sopenharmony_cirm -rf usr/share/zsh/vendor-completions
238bf215546Sopenharmony_ci
239bf215546Sopenharmony_ci# drop gcc python helpers
240bf215546Sopenharmony_cirm -rf usr/share/gcc
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_ci# Drop sysvinit leftovers
243bf215546Sopenharmony_cirm -rf etc/init.d
244bf215546Sopenharmony_cirm -rf etc/rc[0-6S].d
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_ci# Drop upstart helpers
247bf215546Sopenharmony_cirm -rf etc/init
248bf215546Sopenharmony_ci
249bf215546Sopenharmony_ci# Various xtables helpers
250bf215546Sopenharmony_cirm -rf usr/lib/xtables
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_ci# Drop all locales
253bf215546Sopenharmony_ci# TODO: only remaining locale is actually "C". Should we really remove it?
254bf215546Sopenharmony_cirm -rf usr/lib/locale/*
255bf215546Sopenharmony_ci
256bf215546Sopenharmony_ci# partition helpers
257bf215546Sopenharmony_cirm -rf usr/sbin/*fdisk
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci# local compiler
260bf215546Sopenharmony_cirm -rf usr/bin/localedef
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci# Systemd dns resolver
263bf215546Sopenharmony_cifind usr etc -name '*systemd-resolve*' -prune -exec rm -r {} \;
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_ci# Systemd network configuration
266bf215546Sopenharmony_cifind usr etc -name '*networkd*' -prune -exec rm -r {} \;
267bf215546Sopenharmony_ci
268bf215546Sopenharmony_ci# systemd ntp client
269bf215546Sopenharmony_cifind usr etc -name '*timesyncd*' -prune -exec rm -r {} \;
270bf215546Sopenharmony_ci
271bf215546Sopenharmony_ci# systemd hw database manager
272bf215546Sopenharmony_cifind usr etc -name '*systemd-hwdb*' -prune -exec rm -r {} \;
273bf215546Sopenharmony_ci
274bf215546Sopenharmony_ci# No need for fuse
275bf215546Sopenharmony_cifind usr etc -name '*fuse*' -prune -exec rm -r {} \;
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ci# lsb init function leftovers
278bf215546Sopenharmony_cirm -rf usr/lib/lsb
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci# Only needed when adding libraries
281bf215546Sopenharmony_cirm -rf usr/sbin/ldconfig*
282bf215546Sopenharmony_ci
283bf215546Sopenharmony_ci# Games, unused
284bf215546Sopenharmony_cirmdir usr/games
285bf215546Sopenharmony_ci
286bf215546Sopenharmony_ci# Remove pam module to authenticate against a DB
287bf215546Sopenharmony_ci# plus libdb-5.3.so that is only used by this pam module
288bf215546Sopenharmony_cirm -rf usr/lib/*/security/pam_userdb.so
289bf215546Sopenharmony_cirm -rf usr/lib/*/libdb-5.3.so
290bf215546Sopenharmony_ci
291bf215546Sopenharmony_ci# remove NSS support for nis, nisplus and hesiod
292bf215546Sopenharmony_cirm -rf usr/lib/*/libnss_hesiod*
293bf215546Sopenharmony_cirm -rf usr/lib/*/libnss_nis*
294