forked from emmett1/lfs-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-base
executable file
·176 lines (151 loc) · 3.82 KB
/
02-base
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
#!/bin/sh
lfs_dirs() {
mkdir -pv $LFS/bin $LFS/usr/lib $LFS/usr/bin $LFS/etc || true
for i in bash cat chmod dd echo ln mkdir pwd rm stty touch; do
ln -svf /tools/bin/$i $LFS/bin
done
for i in env install perl printf; do
ln -svf /tools/bin/$i $LFS/usr/bin
done
ln -svf /tools/lib/libgcc_s.so /tools/lib/libgcc_s.so.1 $LFS/usr/lib
ln -svf /tools/lib/libstdc++.a /tools/lib/libstdc++.so /tools/lib/libstdc++.so.6 $LFS/usr/lib
ln -svf bash $LFS/bin/sh
ln -svf /proc/self/mounts $LFS/etc/mtab
cat > $LFS/etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
EOF
cat > $LFS/etc/group << "EOF"
root:x:0:
bin:x:1:daemon
sys:x:2:
kmem:x:3:
tape:x:4:
tty:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
adm:x:16:
messagebus:x:18:
input:x:24:
mail:x:34:
kvm:x:61:
wheel:x:97:
nogroup:x:99:
users:x:999:
EOF
# pkgutils
mkdir -p \
$LFS/var/lib/pkg/pkg \
$LFS/var/lib/pkg/src \
$LFS/var/lib/pkg/work
touch $LFS/var/lib/pkg/db
}
mount_pseudo() {
mkdir -p $LFS/dev $LFS/run $LFS/proc $LFS/sys
mount --bind /dev $LFS/dev
mount -t devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -t proc proc $LFS/proc
mount -t sysfs sysfs $LFS/sys
mount -t tmpfs tmpfs $LFS/run
if [ -h $LFS/dev/shm ]; then
mkdir -p $LFS/$(readlink $LFS/dev/shm)
fi
}
umount_pseudo() {
unmount $LFS/dev/pts
unmount $LFS/dev
unmount $LFS/run
unmount $LFS/proc
unmount $LFS/sys
}
mountbind_srcpkg() {
mount --bind $SRCDIR $LFS/var/lib/pkg/src
mount --bind $PKGDIR $LFS/var/lib/pkg/pkg
}
unmountbind_srcpkg() {
unmount $LFS/var/lib/pkg/src
unmount $LFS/var/lib/pkg/pkg
}
unmount() {
while true; do
mountpoint -q $1 || break
umount $1 2>/dev/null
done
}
runinchroot() {
cd $LFS >/dev/null 2>&1
mount_pseudo
mountbind_srcpkg
cp -L /etc/resolv.conf $LFS/etc/
chroot "$LFS" $ENVLFS -i \
HOME=/root \
TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin $@
retval=$?
unmountbind_srcpkg
umount_pseudo
cd - >/dev/null 2>&1
return $retval
}
interrupted() {
die "script $(basename $0) aborted!"
}
die() {
[ "$@" ] && printerror $@
unmountbind_srcpkg
umount_pseudo
exit 1
}
printerror() {
echo "ERROR: $@"
}
trap "interrupted" 1 2 3 15
if [ $(id -u) != 0 ]; then
echo "$0 script need to run as root!"
exit 1
fi
CWD=$PWD
if [ -f $CWD/config ]; then
. $CWD/config
fi
MAKEFLAGS="${MAKEFLAGS:--j$(nproc)}"
LFS="${LFS:-$CWD/lfs-rootfs}"
PKGDIR="${PKGDIR:-$CWD/pkg}"
SRCDIR="${SRCDIR:-$CWD/src}"
WORKDIR="${WORKDIR:-$CWD/work}"
CFLAGS="${CFLAGS:--O2 -march=x86-64 -pipe}"
mkdir -p $PKGDIR $SRCDIR $WORKDIR
if [ -x $LFS/usr/bin/env ]; then
ENVLFS=/usr/bin/env
else
ENVLFS=/tools/bin/env
fi
PKGS="filesystem linux-api-headers man-pages glibc tzdata zlib bzip2 file readline m4 bc binutils gmp mpfr mpc attr acl shadow gcc
pkgconf ncurses libcap sed psmisc iana-etc bison flex grep bash libtool gdbm gperf expat inetutils
perl perl-xml-parser intltool autoconf automake xz kmod gettext openssl ca-certificates curl elfutils libffi python3 coreutils
diffutils gawk findutils groff fuse2 grub less gzip iproute2 kbd libpipeline make patch man-db tar texinfo vim procps-ng
util-linux e2fsprogs sysklogd sysvinit eudev lfs-bootscripts linux-firmware libarchive mkinitramfs linux libtasn1 p11-kit
wget pkgutils libnl dbus libxml2 dhcpcd wpa_supplicant lzo lz4 squashfs-tools popt efivar pciutils efibootmgr libpng which freetype2 dosfstools grub-efi
ports httpup gpm libevent links mtools syslinux"
if [ ! -f $LFS/var/lib/pkg/db ]; then
lfs_dirs
fi
rm -fr $LFS/usr/ports
mkdir -p $LFS/usr/ports/
echo "==> Copying ports"
cp -Ra ports/* $LFS/usr/ports/
for pkg in $PKGS; do
case $pkg in
filesystem|gcc|bash|perl|coreutils) runinchroot pkgin -i -ic $pkg || die;;
*) runinchroot pkgin -i $pkg || die;;
esac
done
exit 0