-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·397 lines (340 loc) · 13 KB
/
build
File metadata and controls
executable file
·397 lines (340 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/bin/sh
if [ "x$AS_ROOT" = "x" ]; then
AS_ROOT=doas
fi
SRCROOT=`pwd`
export SRCROOT
if [ ! -d tarball ]; then
mkdir -p tarball
fi
if [ ! -d dist ]; then
mkdir -p dist
fi
if [ ! -d initrd ]; then
$AS_ROOT mkdir -p initrd/proc
$AS_ROOT mkdir -p initrd/sys
$AS_ROOT mkdir -p initrd/tmp
$AS_ROOT mkdir -p initrd/dev
$AS_ROOT mkdir -p initrd/newroot
$AS_ROOT mkdir -p initrd/bin
$AS_ROOT mkdir -p initrd/lib
fi
if [ ! -d root ]; then
$AS_ROOT mkdir -p root/usr/include/sys
$AS_ROOT mkdir -p root/usr/share
$AS_ROOT mkdir -p root/usr/man
$AS_ROOT mkdir -p root/lib64
$AS_ROOT mkdir -p root/bin
$AS_ROOT mkdir -p root/tmp
$AS_ROOT mkdir -p root/run
$AS_ROOT mkdir -p root/var/run
$AS_ROOT mkdir -p root/var/log
$AS_ROOT mkdir -p root/var/db
$AS_ROOT mkdir -p root/root
$AS_ROOT mkdir -p root/var/mail
$AS_ROOT mkdir -p root/var/spool/mqueue
$AS_ROOT mkdir -p root/isolinux
$AS_ROOT mkdir -p root/etc
$AS_ROOT mkdir -p root/etc/rc.d
$AS_ROOT install -d -m755 root/etc/mail
$AS_ROOT mkdir -p root/proc
$AS_ROOT mkdir -p root/sys
$AS_ROOT mkdir -p root/dev
$AS_ROOT ln -s ../proc/mounts root/etc/mtab
$AS_ROOT ln -s ../tmp/resolv.conf root/etc/resolv.conf
$AS_ROOT ln -s ../man root/usr/share/man
$AS_ROOT ln -s ./ksh root/bin/sh
$AS_ROOT ln -s ./sbin root/usr/bin
$AS_ROOT ln -s ../bin root/usr/sbin
$AS_ROOT ln -s ./bin root/sbin
$AS_ROOT ln -s ../usr/linux/sbin/agetty root/sbin/getty
$AS_ROOT ln -s ../tmp root/var/tmp
$AS_ROOT ln -s ./lib root/usr/lib64
$AS_ROOT ln -s ../lib root/usr/lib
$AS_ROOT ln -s ./lib64 root/lib
fi
download () {
name=`echo "$1" | rev | cut -d"/" -f1 | rev`
topdir="$2"
if [ -f tarball/$name ]; then
echo " - not required to download $1"
else
echo " - getting $1"
wget -O tarball/$name $1
fi
if [ -d dist/$2 ]; then
echo " - not required to extract tarball/$name"
else
echo " - extracting tarball/$name"
tar xf tarball/$name -C dist
fi
}
OLD=""
NEW=""
enter () {
OLD=`pwd`
NEW=$1
echo " - entering $1"
cd $1
}
leave () {
echo " - leaving $NEW"
cd $OLD
}
set_cc () {
CC=$SRCROOT/dist/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc
CXX=$SRCROOT/dist/x86_64-linux-musl-cross/bin/x86_64-linux-musl-g++
AS=$SRCROOT/dist/x86_64-linux-musl-cross/bin/x86_64-linux-musl-as
LD=$SRCROOT/dist/x86_64-linux-musl-cross/bin/x86_64-linux-musl-ld
export CC
export CXX
export AS
export LD
CFLAGS="--sysroot=$SRCROOT/root -O2 -Wl,--sysroot=$SRCROOT/root"
CXXFLAGS="--sysroot=$SRCROOT/root -O2"
LDFLAGS="--sysroot=$SRCROOT/root -O2"
export CFLAGS
export CXXFLAGS
export LDFLAGS
}
build () {
enter $1
if [ -f .bootstrapped ]; then
if [ -f ".bootstrapped" ]; then
echo " - not bootstrapping"
else
echo " - bootstrapping"
./bootstrap.sh || exit 1
touch .bootstrapped
fi
fi
if [ -f configure -o $1 = dist/net-tools-2.10 ]; then
if [ -f ".configured" ]; then
echo " - not configuring"
else
echo " - configuring"
case "$1" in
dist/zlib-*)
./configure --prefix=/usr $4 || exit 1
;;
dist/util-linux-*)
./configure --prefix=/usr/linux --sysconfdir=/etc --mandir=/usr/man $4 || exit 1
;;
dist/net-tools-*)
yes | make config
sed -Ei 's/#define (HAVE_AFECONET|HAVE_HWSTRIP|HAVE_HWTR|HAVE_SELINUX|HAVE_AFBLUETOOTH|HAVE_AFDECnet) 1//g' config.h
sed -Ei 's/(HAVE_AFECONET|HAVE_HWSTRIP|HAVE_HWTR|HAVE_SELINUX|HAVE_AFBLUETOOTH|HAVE_AFDECnet)=1/\1=0/g' config.make
;;
*)
./configure --prefix=/usr --sysconfdir=/etc --mandir=/usr/man $4 || exit 1
;;
esac
touch .configured
fi
fi
if [ -f ".built" ]; then
echo " - not building"
else
echo " - building"
make -j $(nproc) || exit 1
touch .built
fi
if [ -f ".installed" ]; then
echo " - not installing"
else
echo " - installing"
$AS_ROOT make install -j $(nproc) $2=$SRCROOT/root $3 || exit 1
touch .installed
fi
leave
}
SLACKWARE_ROOT="http://mirror.slackware.jp/slackware"
LINUX_VER=`wget -O - "$SLACKWARE_ROOT/slackware64-current/kernels/VERSIONS.TXT" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+'`
echo " - Linux $LINUX_VER"
if [ ! -f root/usr/include/sys/cdefs.h ]; then
$AS_ROOT wget https://github.com/openembedded/openembedded-core/raw/refs/heads/master/meta/recipes-core/musl/bsd-headers/sys-cdefs.h -O root/usr/include/sys/cdefs.h
fi
if [ ! -f root/usr/include/sys/queue.h ]; then
$AS_ROOT wget https://github.com/openembedded/openembedded-core/raw/refs/heads/master/meta/recipes-core/musl/bsd-headers/sys-queue.h -O root/usr/include/sys/queue.h
fi
if [ ! -f root/usr/include/sys/tree.h ]; then
$AS_ROOT wget https://github.com/openembedded/openembedded-core/raw/refs/heads/master/meta/recipes-core/musl/bsd-headers/sys-tree.h -O root/usr/include/sys/tree.h
fi
download $SLACKWARE_ROOT/slackware64-current/source/k/linux-$LINUX_VER.tar.xz linux-$LINUX_VER
if [ ! -d root/usr/include/linux ]; then
enter dist/linux-$LINUX_VER
$AS_ROOT make headers_install ARCH=x86_64 INSTALL_HDR_PATH=$SRCROOT/root/usr
leave
fi
if [ ! -f root/bzImage ]; then
$AS_ROOT wget $SLACKWARE_ROOT/slackware64-current/kernels/generic.s/bzImage -O root/bzImage
fi
if [ ! -f tarball/kernel-$LINUX_VER.txz ]; then
wget $SLACKWARE_ROOT/slackware64-current/slackware64/a/kernel-generic-$LINUX_VER-x86_64-1.txz -O tarball/kernel-$LINUX_VER.txz
fi
if [ ! -d root/lib/modules ]; then
$AS_ROOT tar xkvf tarball/kernel-$LINUX_VER.txz -C root/usr lib
fi
download http://musl.cc/x86_64-linux-musl-cross.tgz x86_64-linux-musl-cross
download http://git.musl-libc.org/cgit/musl/snapshot/musl-1.2.5.tar.gz musl-1.2.5
download http://invisible-island.net/archives/ncurses/ncurses-6.5.tar.gz ncurses-6.5
download https://mandoc.bsd.lv/snapshots/mandoc-1.14.6.tar.gz mandoc-1.14.6
download http://www.zlib.net/zlib-1.3.1.tar.gz zlib-1.3.1
download https://ftp.gnu.org/gnu/less/less-668.tar.gz less-668
download https://www.kernel.org/pub/linux/utils/util-linux/v2.40/util-linux-2.40.tar.gz util-linux-2.40
download https://github.com/sqlite/sqlite/archive/refs/tags/version-3.47.0.tar.gz sqlite-version-3.47.0
download https://mirrors.edge.kernel.org/pub/linux/utils/kernel/kmod/kmod-33.tar.gz kmod-33
download https://downloads.sourceforge.net/project/net-tools/net-tools-2.10.tar.xz net-tools-2.10
download https://github.com/shadow-maint/shadow/releases/download/4.16.0/shadow-4.16.0.tar.xz shadow-4.16.0
download https://ftp.sendmail.org/sendmail.8.18.1.tar.gz sendmail-8.18.1
download https://github.com/htop-dev/htop/releases/download/3.3.0/htop-3.3.0.tar.xz htop-3.3.0
set_cc
cp source/sbrk.c dist/musl-1.2.5/src/linux/
build dist/musl-1.2.5 DESTDIR
build musl-fts DESTDIR
build dist/zlib-1.3.1 DESTDIR "" "--enable-shared"
build dist/shadow-4.16.0 DESTDIR "" "--without-libbsd --with-bcrypt --with-yescrypt"
echo "PREFIX=/usr" > dist/mandoc-1.14.6/configure.local
echo "CC=$CC" >> dist/mandoc-1.14.6/configure.local
echo "LD=$LD" >> dist/mandoc-1.14.6/configure.local
echo "CFLAGS=\"$CFLAGS\"" >> dist/mandoc-1.14.6/configure.local
echo "LDFLAGS=\"$LDFLAGS\"" >> dist/mandoc-1.14.6/configure.local
build dist/mandoc-1.14.6 DESTDIR
LD_LIBRARY_PATH=$SRCROOT/root/usr/lib
export LD_LIBRARY_PATH
build dist/ncurses-6.5 DESTDIR "" "--with-shared --with-termlib --enable-symlinks --disable-widec"
unset LD_LIBRARY_PATH
cp config/heritage.mk heritage/Config.mk
build heritage DESTDIR
build sysvinit ROOT "mandir=/usr/man"
build pdksh DESTDIR "prefix=$SRCROOT/root/usr"
build vi DESTDIR "MANDIR=/usr/man"
build dist/less-668 DESTDIR
build dist/sqlite-version-3.47.0 DESTDIR "" "--disable-tcl --disable-readline"
build dist/util-linux-2.40 DESTDIR "" "--without-systemd --without-python --without-ncursesw"
build dist/kmod-33 DESTDIR
build dist/net-tools-2.10 DESTDIR
$AS_ROOT groupadd -g 80 smmsp
$AS_ROOT useradd -u 80 -s /bin/false -d /dev/null -g smmsp -c "Sendmail Daemon" smmsp
cat > dist/sendmail-8.18.1/devtools/Site/site.config.m4 << EOF
define(\`confCC',\`$CC --sysroot=$SRCROOT/root')
define(\`confOPTIMIZE',\`-O2')
APPENDDEF(\`confENVDEF',\`-UNIS -DHASRRESVPORT=0 -DHASSTRERROR')
EOF
build dist/sendmail-8.18.1 DESTDIR
$AS_ROOT rm -rf $SRCROOT/root/etc/mail
$AS_ROOT mkdir -p $SRCROOT/root/etc/mail
enter dist/sendmail-8.18.1
cd cf/cf
cp generic-linux.mc sendmail.mc
$AS_ROOT sh Build sendmail.cf
cd ../..
$AS_ROOT install -m644 cf/cf/submit.mc $SRCROOT/root/etc/mail
$AS_ROOT install -m644 cf/cf/sendmail.mc $SRCROOT/root/etc/mail
$AS_ROOT install -m644 cf/cf/*.cf $SRCROOT/root/etc/mail
$AS_ROOT cp -R cf/* $SRCROOT/root/etc/mail
leave
$AS_ROOT groupdel smmsp
$AS_ROOT userdel smmsp
build dist/htop-3.3.0 DESTDIR "" "--disable-unicode"
if [ ! -f root/sbin/popdev ]; then
echo " - compiling popdev"
$AS_ROOT $CC $CFLAGS $LDFLAGS -o root/sbin/popdev source/popdev.c
else
echo " - not compiling popdev"
fi
if [ ! -f root/etc/rcorder ]; then
echo " - compiling rcorder"
$AS_ROOT $CC $CFLAGS $LDFLAGS -o root/etc/rcorder source/rcorder.c
else
echo " - not compiling rcorder"
fi
if [ ! -f root/sbin/irinit ]; then
echo " - compiling irinit"
$AS_ROOT $CC $CFLAGS $LDFLAGS -I$SRCROOT/root/usr/linux/include -L$SRCROOT/root/usr/linux/lib -o root/sbin/irinit source/irinit.c $SRCROOT/root/usr/linux/lib/libblkid.a
else
echo " - not compiling irinit"
fi
echo " - copying files"
for i in `ls -d base/*`; do
TO=`grep "TO: " $i | sed "s/# TO: //g"`
echo " - $i -> $TO"
$AS_ROOT cp $i $SRCROOT/root/$TO
done
$AS_ROOT chroot root makewhatis /usr/man
echo " - constructing initrd.gz"
if [ ! -f root/initrd.gz ]; then
$AS_ROOT cp root/bin/sh initrd/bin/sh
$AS_ROOT cp root/bin/echo initrd/bin/echo
$AS_ROOT cp root/bin/find initrd/bin/find
$AS_ROOT cp root/bin/cat initrd/bin/cat
$AS_ROOT cp root/bin/modprobe initrd/bin/modprobe
$AS_ROOT cp root/sbin/irinit initrd/init
$AS_ROOT cp root/sbin/popdev initrd/popdev
$AS_ROOT cp root/lib/libc.so initrd/lib/libc.so
$AS_ROOT cp root/lib/libc.so initrd/lib/ld-musl-x86_64.so.1
$AS_ROOT cp root/lib/libfts.so initrd/lib/libfts.so
$AS_ROOT cp root/lib/libfts.so initrd/lib/libfts.so.0
$AS_ROOT mkdir -p initrd/lib/modules/$LINUX_VER/kernel/drivers/usb
$AS_ROOT mkdir -p initrd/lib/modules/$LINUX_VER/kernel/drivers/scsi
$AS_ROOT mkdir -p initrd/lib/modules/$LINUX_VER/kernel/fs
$AS_ROOT mkdir -p initrd/lib/modules/$LINUX_VER/kernel/lib
$AS_ROOT mkdir -p initrd/lib/modules/$LINUX_VER/kernel/arch
$AS_ROOT mkdir -p initrd/lib/modules/$LINUX_VER/kernel/crypto
$AS_ROOT mkdir -p initrd/lib/modules/$LINUX_VER/kernel/block
$AS_ROOT cp -rf root/lib/modules/$LINUX_VER/modules.* initrd/lib/modules/$LINUX_VER/
$AS_ROOT cp -rf root/lib/modules/$LINUX_VER/kernel/drivers/scsi/* initrd/lib/modules/$LINUX_VER/kernel/drivers/scsi/
$AS_ROOT cp -rf root/lib/modules/$LINUX_VER/kernel/drivers/usb/* initrd/lib/modules/$LINUX_VER/kernel/drivers/usb/
$AS_ROOT cp -rf root/lib/modules/$LINUX_VER/kernel/fs/* initrd/lib/modules/$LINUX_VER/kernel/fs/
$AS_ROOT cp -rf root/lib/modules/$LINUX_VER/kernel/lib/* initrd/lib/modules/$LINUX_VER/kernel/lib/
$AS_ROOT cp -rf root/lib/modules/$LINUX_VER/kernel/arch/* initrd/lib/modules/$LINUX_VER/kernel/arch/
$AS_ROOT cp -rf root/lib/modules/$LINUX_VER/kernel/block/* initrd/lib/modules/$LINUX_VER/kernel/block/
$AS_ROOT cp -rf root/lib/modules/$LINUX_VER/kernel/crypto/* initrd/lib/modules/$LINUX_VER/kernel/crypto/
cd initrd
find . | cpio -o -H newc > ../init.rd
cd ..
gzip -c init.rd > initrd.gz
$AS_ROOT mv initrd.gz root/initrd.gz
rm -f init.rd
fi
$AS_ROOT cp /usr/lib/ISOLINUX/isolinux.bin root/isolinux/
$AS_ROOT cp /usr/lib/syslinux/modules/bios/ldlinux.c32 root/isolinux/
$AS_ROOT cp /usr/lib/syslinux/modules/bios/libutil.c32 root/isolinux/
$AS_ROOT cp /usr/lib/syslinux/modules/bios/menu.c32 root/isolinux/
$AS_ROOT sh -c 'cat > root/isolinux/isolinux.cfg' << EOF
default menu.c32
timeout 50
menu title Boot Menu
menu rows 1
label linux
kernel /bzImage
initrd /initrd.gz
append root=LABEL=BLNXINST rootfstype=iso9660 loglevel=4 installer
EOF
$AS_ROOT sh -c 'echo berkeley > root/etc/nodename'
$AS_ROOT sh -c 'echo berkeley > root/etc/mail/local-host-names'
$AS_ROOT sh -c 'cat > root/etc/mail/aliases' << EOF
postmater: root
MAILER-DAEMON: root
EOF
$AS_ROOT sh -c 'cat > root/etc/issue' << EOF
Welcome to Berkeley Linux - The Linux Distribution
from Nishi
System name: \n
EOF
$AS_ROOT chroot root /usr/sbin/groupadd -g 0 root
$AS_ROOT chroot root /usr/sbin/groupadd -g 1 daemon
$AS_ROOT chroot root /usr/sbin/groupadd -g 2 bin
$AS_ROOT chroot root /usr/sbin/groupadd -g 80 smmsp
$AS_ROOT chroot root /usr/sbin/useradd -p x -g 0 -u 0 -d /root -s /bin/sh root
$AS_ROOT chroot root /usr/sbin/useradd -u 80 -s /bin/false -d /dev/null -g smmsp -c "Sendmail Daemon" smmsp
echo "root:`mkpasswd -m sha512crypt root`:0::::::" | $AS_ROOT sh -c 'cat > root/etc/shadow'
echo root:root | $AS_ROOT chroot root /usr/sbin/chpasswd -c SHA512
$AS_ROOT cp /etc/services root/etc/
$AS_ROOT chmod 644 root/etc/passwd
$AS_ROOT chmod 644 root/etc/group
$AS_ROOT chmod 600 root/etc/shadow
$AS_ROOT chmod 4755 root/usr/sbin/unix_chkpwd
$AS_ROOT chmod 1777 root/var/mail
$AS_ROOT install -m700 -d root/var/spool/mqueue
$AS_ROOT xorriso -as mkisofs -V "BLNXINST" -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -o output.iso root