Dash:
[t2-trunk.git] / target / share / install / build_stage2.sh
blobdb5e25eaddab8aab952b8f73d5c187dcbda78c29
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: target/share/install/build_stage2.sh
3 # Copyright (C) 2004 - 2021 The T2 SDE Project
4 #
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2.
10 # --- T2-COPYRIGHT-NOTE-END ---
12 . $base/misc/target/functions.in
14 set -e
16 echo_header "Creating 2nd stage filesystem:"
17 rm -rf $disksdir/2nd_stage*
18 mkdir -p $disksdir/2nd_stage; cd $disksdir/2nd_stage
20 # package map to include
21 package_map="00-dirtree zlib parted cryptsetup
22 xfsprogs dosfstools jfsutils btrfs-progs
23 e2fsprogs reiserfsprogs reiser4progs genromfs
24 popt raidtools mdadm pcre
25 lvm lvm2 device-mapper libaio
26 dump eject disktype mac-fdisk
27 hdparm memtest86 cpuburn bonnie++
28 ncurses readline libgpg-error libgcrypt
29 bash attr acl findutils
30 mktemp coreutils pciutils libcap
31 grep sed gzip bzip2
32 tar gawk lzo lzop
33 less nvi bc cpio
34 xz zstd ed zile
35 curl dialog minicom kmod
36 lrzsz rsync tcpdump module-init-tools
37 sysvinit shadow util-linux wireless-tools
38 runit runit-logacct runit-shutdown
39 net-tools procps psmisc
40 modutils pciutils portmap
41 sysklogd setserial iproute2
42 netkit-base netkit-ftp netkit-telnet netkit-tftp
43 sysfiles libpcap iptables tcp_wrappers
44 stone rocknet
45 kbd ntfsprogs libol memtester
46 openssl openssh iproute2"
48 # TODO: a global multilib package multiplexer that allows distrinct control
49 # and avoids such hacks ...
50 if [ "$SDECFG_POWERPC64_32" = 1 -o "$SDECFG_SPARC64_32BIT" = 1 ]; then
51 package_map="$package_map ${SDECFG_LIBC}32"
52 else
53 package_map="$package_map ${SDECFG_LIBC}"
56 if pkginstalled mine; then
57 packager=mine
58 else
59 packager=bize
62 package_map=" $( echo "$packager $package_map" | tr '\n' ' ' | tr '\t' ' ' | tr -s ' ' ) "
64 echo_status "Copying files."
65 for pkg in `grep '^X ' $base/config/$config/packages | cut -d ' ' -f 5`; do
66 # include the package?
67 #echo maybe $pkg >&2
68 if [ "${package_map/ $pkg /}" != "$package_map" ]; then
69 cut -d ' ' -f 2 $build_root/var/adm/flists/$pkg
71 done | (
72 # quick and dirty filter
73 grep -v -e 'lib[^/]*/[^/]*\.\(a\|la\|o\)$' \
74 -e 'var/\(adm\|games\|mail\|opt\)' \
75 -e 'usr/\(local\|doc\|man\|info\|games\|share\|include\|src\)' \
76 -e 'usr/.*-linux-gnu' -e '/gconv/' -e '/locale/' -e '/pkgconfig/' \
77 -e 'bin/.*-config' \
78 -e 'bin/install' -e 'bin/openssl' -e 'bin/localedef' \
79 -e '/init.d/' -e '/rc.d/'
80 # TODO: usr/lib/*/
81 ) > ../files-wanted
83 # some more stuff
84 cut -d ' ' -f 2 $build_root/var/adm/flists/{kbd,pciutils,ncurses} |
85 grep -e 'usr/share/terminfo/.*/\(ansi\|linux\|.*xterm.*\|vt.*\|screen\|tmux\)' \
86 -e 'usr/share/kbd/keymaps/i386/\(include\|azerty\|qwertz\|qwerty\)' \
87 -e 'usr/share/kbd/keymaps/include' \
88 -e 'usr/share/pci.ids' \
89 >> ../files-wanted
91 copy_with_list_from_file $build_root $PWD $PWD/../files-wanted
93 copy_and_parse_from_source $base/target/share/install/rootfs $PWD
95 echo_status "Creating usability sym-links."
96 [ ! -e usr/bin/vi -a -e usr/bin/nvi ] && ln -s nvi usr/bin/vi
97 [ ! -e usr/bin/emacs -a -e usr/bin/zile ] && ln -s zile usr/bin/emacs
98 [ -e usr/sbin/stone ] && ln -s stone usr/sbin/install
100 [ "$SDECFG_CROSSBUILD" != 1 ] && (chroot . /sbin/ldconfig || true)
102 echo '$STONE install' > etc/stone.d/default.sh
104 cd $disksdir/
106 echo_header "Creating 2nd_stage_small filesystem:"
107 mkdir -p 2nd_stage_small; cd 2nd_stage_small
109 mkdir -p share {,usr/}{,s}bin
111 # we re-use some of the initrd files, too!
112 progs="agetty sh bash cat cp date dd df dmesg ifconfig ln ls $packager mkdir \
113 mkswap mount mv rm reboot route sleep swapoff swapon sync umount cut \
114 setsid eject chmod chroot grep halt rmdir init shutdown uname killall5 \
115 install stone tar mktemp sort fold sed mkreiserfs head tail disktype \
116 login-shell stat gzip mkfs.ext3 mkfs.fat mkfs.xfs gasgui dialog stty \
117 wc fmt"
119 progs="$progs parted fdisk sfdisk"
121 if [[ $arch = powerpc* ]]; then
122 progs="$progs mac-fdisk pdisk"
125 if [ $packager = bize ]; then
126 progs="$progs md5sum"
129 for x in $progs; do
130 fn=""
131 for f in ../2nd_stage/{,usr/}{s,}bin/$x; do
132 [ -e $f ] && fn=${f#../2nd_stage/} && break
133 done
135 if [ "$fn" ]; then
136 mv ../2nd_stage/$fn $fn
137 else
138 echo_error "\`- Program not found: $x"
140 done
142 echo_status "Moving the required libraries."
143 found=1
144 while [ $found = 1 ]; do
145 found=0
146 for x in ../2nd_stage/{,usr/}lib{64,}; do
147 for y in $( cd $x 2>/dev/null && ls *.so.* 2>/dev/null ); do
148 dir=${x#../2nd_stage/}
149 # TODO: maybe use readelf, too?
150 if [ ! -e $dir/$y ] &&
151 grep -q $y {s,}bin/* usr/{s,}bin/* lib{64,}/* 2> /dev/null
152 then
153 echo_status "\`- Found $dir/$y"
154 mkdir -p $dir
155 xx=$x # save for update in symlink loop
156 while z=`readlink $x/$y`; [ "$z" ]; do
157 echo " $dir/$y SYMLINKS to $z"
158 mv $x/$y $dir/
159 [[ $z = /* ]] && x=../2nd_stage/
160 y=$z
161 done
162 # if multiple symlinks, might have been moved already
163 [ -e $x/$y ] && mv $x/$y $dir/
164 x=$xx
165 found=1
167 done
168 done
169 done
172 echo_status "Moving SDE-CONFIG."
173 mkdir -p etc/SDE-CONFIG
174 mv ../2nd_stage/etc/SDE-CONFIG/config etc/SDE-CONFIG/
175 echo_status "Moving stone.d."
176 mkdir -p etc/stone.d
177 for i in gui_text gui_dialog mod_install mod_packages mod_gas default; do
178 mv ../2nd_stage/etc/stone.d/$i.sh etc/stone.d
179 done
180 echo_status "Moving additional files."
181 mkdir -p usr/share/terminfo/{v,l}/
182 mv ../2nd_stage/usr/share/terminfo/l/linux usr/share/terminfo/l/
183 mv ../2nd_stage/usr/share/terminfo/v/vt102 usr/share/terminfo/v/
184 mv ../2nd_stage/root root
186 echo_status "Removing shared libraries already in initrd."
188 # remove libs already in the regular initrd, for each available kernel:
189 for x in `egrep 'X .* KERNEL .*' $base/config/$config/packages |
190 cut -d ' ' -f 5`; do
191 kernel=${x/_*/}
192 for kernelver in `sed -n "s,.*boot/kconfig.,,p" $build_root/var/adm/flists/$kernel`; do
193 initrd="initrd-$kernelver"
194 kernelimg=`ls $build_root/boot/vmlinu?-$kernelver`
195 kernelimg=${kernelimg##*/}
197 zstd -d < $isofsdir/boot/$initrd | cpio -tv | grep -e "lib.*\.so" -e bin/ |
198 while read _ _ _ _ size _ _ _ exe _; do
199 for fn in ../2nd_stage{,_small}/$exe; do
200 if [ -e $fn -o -L $fn ]; then
201 if [[ $fn = *bin* ]]; then
202 size2=$(stat -c "%s" $fn) # or du
203 # only delete bin/* if diff. size, e.g. embutils replacement
204 [ -L $fn -o $size = $size2 ] && rm -vf $fn
205 else
206 rm -vf $fn
209 done
210 done
211 done
212 done
215 echo_status "Creating links for identical files."
216 link_identical_files
218 cd $disksdir/
220 echo_status "Creating stage2 archive."
221 (cd 2nd_stage_small; find ! -type d |
222 tar -cf- --no-recursion --files-from=-) | zstd -14 -T0 > $isofsdir/stage2.tar.zst
224 echo_status "Creating stage2ext archive."
225 (cd 2nd_stage; find ! -type d |
226 tar -cf- --no-recursion --files-from=-) | zstd -18 -T0 > $isofsdir/stage2ext.tar.zst