ci: Make a simple little bare-metal fastboot mode for db410c.
[mesa.git] / .gitlab-ci / create-rootfs.sh
1 #!/bin/bash
2
3 set -ex
4
5 apt-get -y install --no-install-recommends \
6 ca-certificates \
7 initramfs-tools \
8 libpng16-16 \
9 strace \
10 libsensors5 \
11 libexpat1 \
12 libdrm2 \
13 libdrm-nouveau2 \
14 firmware-qcom-media \
15 wget \
16 xz-utils
17 passwd root -d
18 chsh -s /bin/sh
19
20 cat > /init <<EOF
21 #!/bin/sh
22 export PS1=lava-shell:
23 exec sh
24 EOF
25 chmod +x /init
26
27 mkdir -p /lib/firmware/rtl_nic
28 wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/rtl_nic/rtl8153a-3.fw -O /lib/firmware/rtl_nic/rtl8153a-3.fw
29
30 #######################################################################
31 # Strip the image to a small minimal system without removing the debian
32 # toolchain.
33
34 # xz compress firmware so it doesn't waste RAM at runtime.
35 find /lib/firmware -type f -print0 | xargs -0r -P4 -n4 xz -T1 -C crc32
36
37 # Copy timezone file and remove tzdata package
38 rm -rf /etc/localtime
39 cp /usr/share/zoneinfo/Etc/UTC /etc/localtime
40
41 UNNEEDED_PACKAGES="libfdisk1
42 tzdata
43 diffutils"
44
45 export DEBIAN_FRONTEND=noninteractive
46
47 # Removing unused packages
48 for PACKAGE in ${UNNEEDED_PACKAGES}
49 do
50 echo ${PACKAGE}
51 if ! apt-get remove --purge --yes "${PACKAGE}"
52 then
53 echo "WARNING: ${PACKAGE} isn't installed"
54 fi
55 done
56
57 apt-get autoremove --yes || true
58
59 # Dropping logs
60 rm -rf /var/log/*
61
62 # Dropping documentation, localization, i18n files, etc
63 rm -rf /usr/share/doc/*
64 rm -rf /usr/share/locale/*
65 rm -rf /usr/share/man
66 rm -rf /usr/share/i18n/*
67 rm -rf /usr/share/info/*
68 rm -rf /usr/share/lintian/*
69 rm -rf /usr/share/common-licenses/*
70 rm -rf /usr/share/mime/*
71
72 # Dropping reportbug scripts
73 rm -rf /usr/share/bug
74
75 # Drop udev hwdb not required on a stripped system
76 rm -rf /lib/udev/hwdb.bin /lib/udev/hwdb.d/*
77
78 # Drop all gconv conversions && binaries
79 rm -rf usr/bin/iconv
80 rm -rf usr/sbin/iconvconfig
81 rm -rf usr/lib/*/gconv/
82
83 # Remove libusb database
84 rm -rf usr/sbin/update-usbids
85 rm -rf var/lib/usbutils/usb.ids
86 rm -rf usr/share/misc/usb.ids
87
88 #######################################################################
89 # Crush into a minimal production image to be deployed via some type of image
90 # updating system.
91 # IMPORTANT: The Debian system is not longer functional at this point,
92 # for example, apt and dpkg will stop working
93
94 UNNEEDED_PACKAGES="apt libapt-pkg5.0 "\
95 "ncurses-bin ncurses-base libncursesw5 libncurses5 "\
96 "perl-base "\
97 "debconf libdebconfclient0 "\
98 "e2fsprogs e2fslibs libfdisk1 "\
99 "insserv "\
100 "udev "\
101 "init-system-helpers "\
102 "bash "\
103 "cpio "\
104 "xz-utils "\
105 "passwd "\
106 "libsemanage1 libsemanage-common "\
107 "libsepol1 "\
108 "gpgv "\
109 "hostname "\
110 "adduser "\
111 "debian-archive-keyring "\
112
113 # Removing unneeded packages
114 for PACKAGE in ${UNNEEDED_PACKAGES}
115 do
116 echo "Forcing removal of ${PACKAGE}"
117 if ! dpkg --purge --force-remove-essential --force-depends "${PACKAGE}"
118 then
119 echo "WARNING: ${PACKAGE} isn't installed"
120 fi
121 done
122
123 # Show what's left package-wise before dropping dpkg itself
124 COLUMNS=300 dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1n
125
126 # Drop dpkg
127 dpkg --purge --force-remove-essential --force-depends dpkg
128
129 # No apt or dpkg, no need for its configuration archives
130 rm -rf etc/apt
131 rm -rf etc/dpkg
132
133 # Drop directories not part of ostree
134 # Note that /var needs to exist as ostree bind mounts the deployment /var over
135 # it
136 rm -rf var/* opt srv share
137
138 # ca-certificates are in /etc drop the source
139 rm -rf usr/share/ca-certificates
140
141 # No bash, no need for completions
142 rm -rf usr/share/bash-completion
143
144 # No zsh, no need for comletions
145 rm -rf usr/share/zsh/vendor-completions
146
147 # drop gcc-6 python helpers
148 rm -rf usr/share/gcc-6
149
150 # Drop sysvinit leftovers
151 rm -rf etc/init.d
152 rm -rf etc/rc[0-6S].d
153
154 # Drop upstart helpers
155 rm -rf etc/init
156
157 # Various xtables helpers
158 rm -rf usr/lib/xtables
159
160 # Drop all locales
161 # TODO: only remaining locale is actually "C". Should we really remove it?
162 rm -rf usr/lib/locale/*
163
164 # partition helpers
165 rm usr/sbin/*fdisk
166
167 # local compiler
168 rm usr/bin/localedef
169
170 # Systemd dns resolver
171 find usr etc -name '*systemd-resolve*' -prune -exec rm -r {} \;
172
173 # Systemd network configuration
174 find usr etc -name '*networkd*' -prune -exec rm -r {} \;
175
176 # systemd ntp client
177 find usr etc -name '*timesyncd*' -prune -exec rm -r {} \;
178
179 # systemd hw database manager
180 find usr etc -name '*systemd-hwdb*' -prune -exec rm -r {} \;
181
182 # No need for fuse
183 find usr etc -name '*fuse*' -prune -exec rm -r {} \;
184
185 # lsb init function leftovers
186 rm -rf usr/lib/lsb
187
188 # Only needed when adding libraries
189 rm usr/sbin/ldconfig*
190
191 # Games, unused
192 rmdir usr/games
193
194 # Remove pam module to authenticate against a DB
195 # plus libdb-5.3.so that is only used by this pam module
196 rm usr/lib/*/security/pam_userdb.so
197 rm usr/lib/*/libdb-5.3.so
198
199 # remove NSS support for nis, nisplus and hesiod
200 rm usr/lib/*/libnss_hesiod*
201 rm usr/lib/*/libnss_nis*