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
|
#!/bin/bash
#----------------------------# Prepare BLFS_ROOT and extract
install_blfs_tools() { # the scriptlets to build
#----------------------------# the dependency tools
set -e
# Install the files
[[ ! -d "${BUILDDIR}${BLFS_ROOT}" ]] && {
sudo mkdir -pv "${BUILDDIR}${BLFS_ROOT}"
sudo chown "$USER" "${BUILDDIR}${BLFS_ROOT}"
}
cp -r BLFS/* ${BUILDDIR}${BLFS_ROOT}
cp -r menu ${BUILDDIR}${BLFS_ROOT}
cp $COMMON_DIR/progress_bar.sh ${BUILDDIR}${BLFS_ROOT}
cp README.BLFS ${BUILDDIR}${BLFS_ROOT}
if [ "$WRAP_INSTALL" = y ]; then
sed -e 's/PKGDIR/JH_UNPACKDIR/' \
-e 's/PKG_DEST/JH_PKG_DIR/' \
$PKGMNGTDIR/packInstall.sh > ${BUILDDIR}${BLFS_ROOT}/packInstall.sh
fi
# Set some harcoded envars to their proper values
sed -i s@tracking-dir@$TRACKING_DIR@ \
${BUILDDIR}${BLFS_ROOT}/{Makefile,gen-makefile.sh,gen_pkg_book.sh}
# If we have a working copy, copy it:
if [[ "$BLFS_WORKING_COPY" = "y" ]]; then
echo "copying the local BLFS working copy (may take some time)"
# -r: recursive; -u: only if newer; -T: otherwise, would copy to a subdirectory
# of blfs-xml, if blfs-xml already exists; --preserve=timestamps: if the local
# book has already been validated, tmp is posterior to the others, and
# validation will not be done again.
# sudo is needed because make (below) may already have been run and
# may have put some files owned by root
sudo cp -ruT --preserve=timestamps $BLFS_WC_LOCATION \
${BUILDDIR}${BLFS_ROOT}/$BLFS_XML
fi
# Copy the LFS book. Note that now, the book is downloaded before running
# the BLFS tools.
sudo cp -ruT --preserve=timestamps $BOOK \
${BUILDDIR}${BLFS_ROOT}/$LFS_XML
# Downloads the book if necessary, initialize the tracking file and the
# package database.
# updating first is needed if the xml sources have already been cloned
# and we want to set the branches.
# Note that if LFS-BRANCH or BLFS-BRANCH is empty, which may happen
# if using a working copy, then the corresponding update is not
# performed by make (see BLFS/Makefile).
# sudo is needed if $BUILDDIR/var/lib is owned by root and /var/lib/jhalfs
# has to be created
sudo make -j1 -C $BUILDDIR$BLFS_ROOT \
REV=$INITSYS \
LFS-BRANCH=${COMMIT} \
BLFS-BRANCH=${BLFS_COMMIT} \
update
sudo make -j1 -C $BUILDDIR$BLFS_ROOT \
REV=$INITSYS \
TRACKING_DIR=$BUILDDIR$TRACKING_DIR \
LFS_XML=$BUILDDIR$BLFS_ROOT/$LFS_XML \
LFS-BRANCH="${COMMIT}" \
BLFS_XML=$BUILDDIR$BLFS_ROOT/$BLFS_XML \
BLFS-BRANCH=${BLFS_COMMIT} \
$BUILDDIR$BLFS_ROOT/packages.xml
# But then $BUILDDIR/var/lib/ is owned by root if just created, which
# prevents $LUSER to create "nss_db". The problem is that $LUSER
# May not have been created yet. So do not change ownership here
# and do it in master.sh for chapter 4.
#sudo chown $LUSER:$LGROUP $BUILDDIR/var/lib
# Because the BLFS Makefile is supposed to be used in chroot (or booted)
# mode, the tracking file has wrong path for DTD. Change it:
sudo sed -i s@$BUILDDIR@@ $BUILDDIR$TRACKING_DIR/instpkg.xml
# Manually build a 'configuration' file
if [ "$DEP_LIBXML" = y ]; then
LINE_LIBXML='CONFIG_libxml2=y'
else
LINE_LIBXML='#CONFIG_libxml2 is not set'
fi
if [ "$DEP_LIBXSLT" = y ]; then
LINE_LIBXSLT='CONFIG_libxslt=y'
else
LINE_LIBXSLT='#CONFIG_libxslt is not set'
fi
# DocBook is a rec dep of libxslt
# if [ "$DEP_DBXML" = y ]; then
# LINE_DBXML='CONFIG_DocBook=y'
# else
# LINE_DBXML='#CONFIG_DocBook is not set'
# fi
if [ "$DEP_LYNX" = y ]; then
LINE_LYNX='CONFIG_lynx=y'
else
LINE_LYNX='#CONFIG_lynx is not set'
fi
if [ "$DEP_SUDO" = y ]; then
LINE_SUDO='CONFIG_sudo=y'
else
LINE_SUDO='#CONFIG_sudo is not set'
fi
if [ "$DEP_WGET" = y ]; then
LINE_WGET='CONFIG_wget=y'
else
LINE_WGET='#CONFIG_wget is not set'
fi
if [ "$DEP_GPM" = y ]; then
LINE_GPM='CONFIG_gpm=y'
else
LINE_GPM='#CONFIG_gpm is not set'
fi
if [ "$DEP_GIT" = y ]; then
LINE_GIT='CONFIG_git=y'
else
LINE_GIT='#CONFIG_git is not set'
fi
cat >$BUILDDIR$BLFS_ROOT/configuration <<EOF
$LINE_LIBXML
$LINE_LIBXSLT
$LINE_WGET
$LINE_GIT
$LINE_GPM
$LINE_LYNX
$LINE_SUDO
MAIL_SERVER=sendmail
optDependency=2
SUDO=n
LANGUAGE=$LANG
WRAP_INSTALL=$WRAP_INSTALL
PACK_INSTALL=/blfs_root/packInstall.sh
DEL_LA_FILES=$DEL_LA_FILES
STATS=n
SRC_ARCHIVE=/sources
BUILD_ROOT=/sources
BUILD_SUBDIRS=y
JOBS=$(if [ -n "$N_PARALLEL" ]; then echo $N_PARALLEL; else echo 1; fi)
EOF
for OPT_VAR in CFLAGS CXXFLAGS LDFLAGS; do
eval optVal=\$${OPT_VAR}_$DEF_OPT_MODE
if [ -n "$optVal" ] && [ "$optVal" != unset ]; then
echo "CFG_$OPT_VAR"=\"$optVal\" >> $BUILDDIR$BLFS_ROOT/configuration
else
echo "CFG_$OPT_VAR"=EMPTY >> $BUILDDIR$BLFS_ROOT/configuration
fi
done
# Generates the scripts for the blfs tools dependencies (in ./scripts)
yes "yes" | $BUILDDIR$BLFS_ROOT/gen_pkg_book.sh \
$BUILDDIR$TRACKING_DIR/instpkg.xml \
$BUILDDIR$BLFS_ROOT
# Move the scriptlets where they should be
sudo rm -rf $BUILDDIR$BLFS_ROOT/scripts
mv scripts $BUILDDIR$BLFS_ROOT
# Generates a list containing download and copying instructions for tarballs
echo -e '#!/bin/bash\nset -e\n' > $BUILDDIR$BLFS_ROOT/download_script
sed -n -e '/PACKAGE=/,/^fi/{/^fi/a\
[ ! -f "$JH_SRC_ARCHIVE/$PACKAGE" ] && cp $PACKAGE $JH_SRC_ARCHIVE
p}' \
-e '/|[ ]*md5sum/p' \
-e '/PACKAGE1=/,/^fi/{/^fi/a\
[ ! -f "$JH_SRC_ARCHIVE/$PACKAGE1" ] && cp $PACKAGE1 $JH_SRC_ARCHIVE
p}' \
-e '/PATCH=/,/^fi/{/^fi/a\
[ ! -f "$JH_SRC_ARCHIVE/$PATCH" ] && cp $PATCH $JH_SRC_ARCHIVE
p}' \
-e '/URL=/,/^fi/{/^fi/a\
[ ! -f "$JH_SRC_ARCHIVE/$BOOTPACKG" ] && cp $BOOTPACKG $JH_SRC_ARCHIVE
p}' \
$BUILDDIR$BLFS_ROOT/scripts/* >> $BUILDDIR$BLFS_ROOT/download_script
chmod u+x $BUILDDIR$BLFS_ROOT/download_script
# Downloads (or copy) to build_dir/sources
pushd $BUILDDIR/sources
# Remove `unpacked' files if some have been left
sudo find . -name unpacked -exec rm \{\} \;
if [ "$GETPKG" = "y" ]; then
JH_FTP_SERVER=$SERVER/pub/blfs/ \
JH_SRC_ARCHIVE=${SRC_ARCHIVE:-/dev/null} \
$BUILDDIR$BLFS_ROOT/download_script
else # Save the download script in case the user wants to run it later
cp $BUILDDIR$BLFS_ROOT/download_script .
fi
popd
rm -v $BUILDDIR$BLFS_ROOT/download_script
# Suppresses unneeded parts of the scriptlets
if [ "$DEP_LIBXSLT" = y ]; then
# libxslt pulls docbook-xsl in, which populates the catalog with annoying
# **EDITME** references. Fortunately, those lines are regognizable because
# they occur between lines containing '/etc/xml/catalog' at the end of the
# line (without '&&'). I have not found a simple way to delete lines
# between 2 addresses, excluding either the first or the last one. So use
# a loop for accumulating lines and deleting at the end.
# Sorry for sed syntax.
sed -i '\@^[[:space:]]*/etc/xml/catalog$@{
n
:a
\@/etc/xml/catalog$@bb
N
ba
:b
d}' \
$BUILDDIR$BLFS_ROOT/scripts/*docbook-xsl
fi
if [ "$DEP_SUDO" = y ]; then
sed -i '/cat.*pam.d/i mkdir -p /etc/pam.d' $BUILDDIR$BLFS_ROOT/scripts/*sudo
fi
# At last generates the build Makefile
mkdir -p $BUILDDIR$BLFS_ROOT/work
pushd $BUILDDIR$BLFS_ROOT/work
../gen-makefile.sh
# The generated Makefile updates the tracking file after each package
# installation, using libxslt, which is not installed yet. So move
# updating to the end of the process, adding an 'update' target
sed -i -e '/xsltproc/,+6d' \
-e '/^all/s@$@ update@' \
-e 's/touch/@touch/' Makefile
cat >> Makefile << EOF
update:
@echo Updating the tracking file
@for pack in \$\$(grep '<productname' ../$LFS_XML/tmp/lfs-full.xml | \\
sed 's/.*>\([^<]*\)<.*/\1/' | \\
sort | uniq); do \\
case "x\$\$pack" in \\
xgcc* | *pass[12] | xvim | \\
xshadow | xPython | xlinux-headers | xdbus | xsystemd )\\
continue ;; \\
esac; \\
VERSION=\$\$(grep -A1 ">\$\$pack</product" \\
../$LFS_XML/tmp/lfs-full.xml | \\
head -n2| \\
sed -n '2s/.*>\([^<]*\)<.*/\1/p'); \\
xsltproc --stringparam packages ../packages.xml \\
--stringparam package \$\$pack \\
--stringparam version \$\$VERSION \\
-o track.tmp \\
../xsl/bump.xsl \$(TRACKING_FILE); \\
sed -i 's@PACKDESC@$BLFS_ROOT/packdesc.dtd@' track.tmp; \\
xmllint --format --postvalid track.tmp > \$(TRACKING_FILE); \\
rm track.tmp; \\
done; \\
VERSION=\$\$(grep 'echo.*lfs-release' ../$LFS_XML/tmp/lfs-full.xml | \\
sed 's/.*echo[ ]*\([^ ]*\).*/\1/'); \\
xsltproc --stringparam packages ../packages.xml \\
--stringparam package LFS-Release \\
--stringparam version \$\$VERSION \\
-o track.tmp \\
../xsl/bump.xsl \$(TRACKING_FILE); \\
sed -i 's@PACKDESC@$BLFS_ROOT/packdesc.dtd@' track.tmp; \\
xmllint --format --postvalid track.tmp > \$(TRACKING_FILE); \\
rm track.tmp; \\
for file in *-*; do \\
xsltproc --stringparam packages ../packages.xml \\
--stringparam package \$\${file##*z-} \\
-o track.tmp \\
../xsl/bump.xsl \$(TRACKING_FILE); \\
sed -i 's@PACKDESC@$BLFS_ROOT/packdesc.dtd@' track.tmp; \\
xmllint --format --postvalid track.tmp > \$(TRACKING_FILE); \\
rm track.tmp; \\
done
@touch \$@
@echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK
@echo --------------------------------------------------------------------------------\$(WHITE)
EOF
popd
}
|