1 | #!/bin/bash
|
---|
2 |
|
---|
3 | #----------------------------# Prepare BLFS_ROOT and extract
|
---|
4 | install_blfs_tools() { # the scriptlets to build
|
---|
5 | #----------------------------# the dependency tools
|
---|
6 | set -e
|
---|
7 | # Install the files
|
---|
8 | [[ ! -d "${BUILDDIR}${BLFS_ROOT}" ]] && {
|
---|
9 | sudo mkdir -pv "${BUILDDIR}${BLFS_ROOT}"
|
---|
10 | sudo chown "$USER" "${BUILDDIR}${BLFS_ROOT}"
|
---|
11 | }
|
---|
12 | cp -r BLFS/* ${BUILDDIR}${BLFS_ROOT}
|
---|
13 | cp -r menu ${BUILDDIR}${BLFS_ROOT}
|
---|
14 | cp $COMMON_DIR/progress_bar.sh ${BUILDDIR}${BLFS_ROOT}
|
---|
15 | cp README.BLFS ${BUILDDIR}${BLFS_ROOT}
|
---|
16 | if [ "$WRAP_INSTALL" = y ]; then
|
---|
17 | sed -e 's/PKGDIR/JH_UNPACKDIR/' \
|
---|
18 | -e 's/PKG_DEST/JH_PKG_DIR/' \
|
---|
19 | $PKGMNGTDIR/packInstall.sh > ${BUILDDIR}${BLFS_ROOT}/packInstall.sh
|
---|
20 | fi
|
---|
21 |
|
---|
22 | # Set some harcoded envars to their proper values
|
---|
23 | sed -i s@tracking-dir@$TRACKING_DIR@ \
|
---|
24 | ${BUILDDIR}${BLFS_ROOT}/{Makefile,gen-makefile.sh,gen_pkg_book.sh}
|
---|
25 |
|
---|
26 | # If we have a working copy, copy it:
|
---|
27 | if [[ "$BLFS_WORKING_COPY" = "y" ]]; then
|
---|
28 | echo "copying the local BLFS working copy (may take some time)"
|
---|
29 | # -r: recursive; -u: only if newer; -T: otherwise, would copy to a subdirectory
|
---|
30 | # of blfs-xml, if blfs-xml already exists; --preserve=timestamps: if the local
|
---|
31 | # book has already been validated, tmp is posterior to the others, and
|
---|
32 | # validation will not be done again.
|
---|
33 | # sudo is needed because make (below) may already have been run and
|
---|
34 | # may have put some files owned by root
|
---|
35 | sudo cp -ruT --preserve=timestamps $BLFS_WC_LOCATION \
|
---|
36 | ${BUILDDIR}${BLFS_ROOT}/$BLFS_XML
|
---|
37 | fi
|
---|
38 |
|
---|
39 | # Copy the LFS book. Note that now, the book is downloaded before running
|
---|
40 | # the BLFS tools.
|
---|
41 | sudo cp -ruT --preserve=timestamps $BOOK \
|
---|
42 | ${BUILDDIR}${BLFS_ROOT}/$LFS_XML
|
---|
43 |
|
---|
44 | # Downloads the book if necessary, initialize the tracking file and the
|
---|
45 | # package database.
|
---|
46 | # updating first is needed if the xml sources have already been cloned
|
---|
47 | # and we want to set the branches.
|
---|
48 | # Note that if LFS-BRANCH or BLFS-BRANCH is empty, which may happen
|
---|
49 | # if using a working copy, then the corresponding update is not
|
---|
50 | # performed by make (see BLFS/Makefile).
|
---|
51 | # sudo is needed if $BUILDDIR/var/lib is owned by root and /var/lib/jhalfs
|
---|
52 | # has to be created
|
---|
53 | sudo make -j1 -C $BUILDDIR$BLFS_ROOT \
|
---|
54 | REV=$INITSYS \
|
---|
55 | LFS-BRANCH=${COMMIT} \
|
---|
56 | BLFS-BRANCH=${BLFS_TREE} \
|
---|
57 | update
|
---|
58 | sudo make -j1 -C $BUILDDIR$BLFS_ROOT \
|
---|
59 | REV=$INITSYS \
|
---|
60 | TRACKING_DIR=$BUILDDIR$TRACKING_DIR \
|
---|
61 | LFS_XML=$BUILDDIR$BLFS_ROOT/$LFS_XML \
|
---|
62 | LFS-BRANCH="${COMMIT}" \
|
---|
63 | BLFS_XML=$BUILDDIR$BLFS_ROOT/$BLFS_XML \
|
---|
64 | BLFS-BRANCH=${BLFS_TREE} \
|
---|
65 | $BUILDDIR$BLFS_ROOT/packages.xml
|
---|
66 |
|
---|
67 | # But then $BUILDDIR/var/lib/ is owned by root if just created, which
|
---|
68 | # prevents $LUSER to create "nss_db". The problem is that $LUSER
|
---|
69 | # May not have been created yet. So do not change ownership here
|
---|
70 | # and do it in master.sh for chapter 4.
|
---|
71 | #sudo chown $LUSER:$LGROUP $BUILDDIR/var/lib
|
---|
72 |
|
---|
73 | # Because the BLFS Makefile is supposed to be used in chroot (or booted)
|
---|
74 | # mode, the tracking file has wrong path for DTD. Change it:
|
---|
75 | sudo sed -i s@$BUILDDIR@@ $BUILDDIR$TRACKING_DIR/instpkg.xml
|
---|
76 |
|
---|
77 | # Manually build a 'configuration' file
|
---|
78 | if [ "$DEP_LIBXML" = y ]; then
|
---|
79 | LINE_LIBXML='CONFIG_libxml2=y'
|
---|
80 | else
|
---|
81 | LINE_LIBXML='#CONFIG_libxml2 is not set'
|
---|
82 | fi
|
---|
83 | if [ "$DEP_LIBXSLT" = y ]; then
|
---|
84 | LINE_LIBXSLT='CONFIG_libxslt=y'
|
---|
85 | else
|
---|
86 | LINE_LIBXSLT='#CONFIG_libxslt is not set'
|
---|
87 | fi
|
---|
88 | # DocBook is a rec dep of libxslt
|
---|
89 | # if [ "$DEP_DBXML" = y ]; then
|
---|
90 | # LINE_DBXML='CONFIG_DocBook=y'
|
---|
91 | # else
|
---|
92 | # LINE_DBXML='#CONFIG_DocBook is not set'
|
---|
93 | # fi
|
---|
94 | if [ "$DEP_LYNX" = y ]; then
|
---|
95 | LINE_LYNX='CONFIG_lynx=y'
|
---|
96 | else
|
---|
97 | LINE_LYNX='#CONFIG_lynx is not set'
|
---|
98 | fi
|
---|
99 | if [ "$DEP_SUDO" = y ]; then
|
---|
100 | LINE_SUDO='CONFIG_sudo=y'
|
---|
101 | else
|
---|
102 | LINE_SUDO='#CONFIG_sudo is not set'
|
---|
103 | fi
|
---|
104 | if [ "$DEP_WGET" = y ]; then
|
---|
105 | LINE_WGET='CONFIG_wget=y'
|
---|
106 | else
|
---|
107 | LINE_WGET='#CONFIG_wget is not set'
|
---|
108 | fi
|
---|
109 | if [ "$DEP_GPM" = y ]; then
|
---|
110 | LINE_GPM='CONFIG_gpm=y'
|
---|
111 | else
|
---|
112 | LINE_GPM='#CONFIG_gpm is not set'
|
---|
113 | fi
|
---|
114 | if [ "$DEP_GIT" = y ]; then
|
---|
115 | LINE_GIT='CONFIG_git=y'
|
---|
116 | else
|
---|
117 | LINE_GIT='#CONFIG_git is not set'
|
---|
118 | fi
|
---|
119 |
|
---|
120 | cat >$BUILDDIR$BLFS_ROOT/configuration <<EOF
|
---|
121 | $LINE_LIBXML
|
---|
122 | $LINE_LIBXSLT
|
---|
123 | $LINE_WGET
|
---|
124 | $LINE_GIT
|
---|
125 | $LINE_GPM
|
---|
126 | $LINE_LYNX
|
---|
127 | $LINE_SUDO
|
---|
128 | MAIL_SERVER=sendmail
|
---|
129 | optDependency=2
|
---|
130 | SUDO=n
|
---|
131 | LANGUAGE=$LANG
|
---|
132 | WRAP_INSTALL=$WRAP_INSTALL
|
---|
133 | PACK_INSTALL=/blfs_root/packInstall.sh
|
---|
134 | DEL_LA_FILES=$DEL_LA_FILES
|
---|
135 | STATS=n
|
---|
136 | SRC_ARCHIVE=/sources
|
---|
137 | BUILD_ROOT=/sources
|
---|
138 | BUILD_SUBDIRS=y
|
---|
139 | JOBS=$(if [ -n "$N_PARALLEL" ]; then echo $N_PARALLEL; else echo 1; fi)
|
---|
140 | EOF
|
---|
141 | for OPT_VAR in CFLAGS CXXFLAGS LDFLAGS; do
|
---|
142 | eval optVal=\$${OPT_VAR}_$DEF_OPT_MODE
|
---|
143 | if [ -n "$optVal" ] && [ "$optVal" != unset ]; then
|
---|
144 | echo "CFG_$OPT_VAR"=\"$optVal\" >> $BUILDDIR$BLFS_ROOT/configuration
|
---|
145 | else
|
---|
146 | echo "CFG_$OPT_VAR"=EMPTY >> $BUILDDIR$BLFS_ROOT/configuration
|
---|
147 | fi
|
---|
148 | done
|
---|
149 |
|
---|
150 | # Generates the scripts for the blfs tools dependencies (in ./scripts)
|
---|
151 | yes "yes" | $BUILDDIR$BLFS_ROOT/gen_pkg_book.sh \
|
---|
152 | $BUILDDIR$TRACKING_DIR/instpkg.xml \
|
---|
153 | $BUILDDIR$BLFS_ROOT
|
---|
154 |
|
---|
155 | # Move the scriptlets where they should be
|
---|
156 | sudo rm -rf $BUILDDIR$BLFS_ROOT/scripts
|
---|
157 | mv scripts $BUILDDIR$BLFS_ROOT
|
---|
158 |
|
---|
159 | # Generates a list containing download and copying instructions for tarballs
|
---|
160 | echo -e '#!/bin/bash\nset -e\n' > $BUILDDIR$BLFS_ROOT/download_script
|
---|
161 | sed -n -e '/PACKAGE=/,/^fi/{/^fi/a\
|
---|
162 | [ ! -f "$JH_SRC_ARCHIVE/$PACKAGE" ] && cp $PACKAGE $JH_SRC_ARCHIVE
|
---|
163 | p}' \
|
---|
164 | -e '/|[ ]*md5sum/p' \
|
---|
165 | -e '/PACKAGE1=/,/^fi/{/^fi/a\
|
---|
166 | [ ! -f "$JH_SRC_ARCHIVE/$PACKAGE1" ] && cp $PACKAGE1 $JH_SRC_ARCHIVE
|
---|
167 | p}' \
|
---|
168 | -e '/PATCH=/,/^fi/{/^fi/a\
|
---|
169 | [ ! -f "$JH_SRC_ARCHIVE/$PATCH" ] && cp $PATCH $JH_SRC_ARCHIVE
|
---|
170 | p}' \
|
---|
171 | -e '/URL=/,/^fi/{/^fi/a\
|
---|
172 | [ ! -f "$JH_SRC_ARCHIVE/$BOOTPACKG" ] && cp $BOOTPACKG $JH_SRC_ARCHIVE
|
---|
173 | p}' \
|
---|
174 | $BUILDDIR$BLFS_ROOT/scripts/* >> $BUILDDIR$BLFS_ROOT/download_script
|
---|
175 | chmod u+x $BUILDDIR$BLFS_ROOT/download_script
|
---|
176 |
|
---|
177 | # Downloads (or copy) to build_dir/sources
|
---|
178 | pushd $BUILDDIR/sources
|
---|
179 | # Remove `unpacked' files if some have been left
|
---|
180 | sudo find . -name unpacked -exec rm \{\} \;
|
---|
181 | if [ "$GETPKG" = "y" ]; then
|
---|
182 | JH_FTP_SERVER=$SERVER/pub/blfs/ \
|
---|
183 | JH_SRC_ARCHIVE=${SRC_ARCHIVE:-/dev/null} \
|
---|
184 | $BUILDDIR$BLFS_ROOT/download_script
|
---|
185 | else # Save the download script in case the user wants to run it later
|
---|
186 | cp $BUILDDIR$BLFS_ROOT/download_script .
|
---|
187 | fi
|
---|
188 | popd
|
---|
189 | rm -v $BUILDDIR$BLFS_ROOT/download_script
|
---|
190 |
|
---|
191 | # Suppresses unneeded parts of the scriptlets
|
---|
192 | if [ "$DEP_LIBXSLT" = y ]; then
|
---|
193 | # libxslt pulls docbook-xsl in, which populates the catalog with annoying
|
---|
194 | # **EDITME** references. Fortunately, those lines are regognizable because
|
---|
195 | # they occur between lines containing '/etc/xml/catalog' at the end of the
|
---|
196 | # line (without '&&'). I have not found a simple way to delete lines
|
---|
197 | # between 2 addresses, excluding either the first or the last one. So use
|
---|
198 | # a loop for accumulating lines and deleting at the end.
|
---|
199 | # Sorry for sed syntax.
|
---|
200 | sed -i '\@^[[:space:]]*/etc/xml/catalog$@{
|
---|
201 | n
|
---|
202 | :a
|
---|
203 | \@/etc/xml/catalog$@bb
|
---|
204 | N
|
---|
205 | ba
|
---|
206 | :b
|
---|
207 | d}' \
|
---|
208 | $BUILDDIR$BLFS_ROOT/scripts/*docbook-xsl
|
---|
209 | fi
|
---|
210 | if [ "$DEP_SUDO" = y ]; then
|
---|
211 | sed -i '/cat.*pam.d/i mkdir -p /etc/pam.d' $BUILDDIR$BLFS_ROOT/scripts/*sudo
|
---|
212 | fi
|
---|
213 | # At last generates the build Makefile
|
---|
214 | mkdir -p $BUILDDIR$BLFS_ROOT/work
|
---|
215 | pushd $BUILDDIR$BLFS_ROOT/work
|
---|
216 | ../gen-makefile.sh
|
---|
217 | # The generated Makefile updates the tracking file after each package
|
---|
218 | # installation, using libxslt, which is not installed yet. So move
|
---|
219 | # updating to the end of the process, adding an 'update' target
|
---|
220 | sed -i -e '/xsltproc/,+6d' \
|
---|
221 | -e '/^all/s@$@ update@' \
|
---|
222 | -e 's/touch/@touch/' Makefile
|
---|
223 | cat >> Makefile << EOF
|
---|
224 | update:
|
---|
225 | @echo Updating the tracking file
|
---|
226 | @for pack in \$\$(grep '<productname' ../$LFS_XML/tmp/lfs-full.xml | \\
|
---|
227 | sed 's/.*>\([^<]*\)<.*/\1/' | \\
|
---|
228 | sort | uniq); do \\
|
---|
229 | case "x\$\$pack" in \\
|
---|
230 | xgcc* | *pass[12] | xvim | \\
|
---|
231 | xshadow | xPython | xlinux-headers | xdbus | xsystemd )\\
|
---|
232 | continue ;; \\
|
---|
233 | esac; \\
|
---|
234 | VERSION=\$\$(grep -A1 ">\$\$pack</product" \\
|
---|
235 | ../$LFS_XML/tmp/lfs-full.xml | \\
|
---|
236 | head -n2| \\
|
---|
237 | sed -n '2s/.*>\([^<]*\)<.*/\1/p'); \\
|
---|
238 | xsltproc --stringparam packages ../packages.xml \\
|
---|
239 | --stringparam package \$\$pack \\
|
---|
240 | --stringparam version \$\$VERSION \\
|
---|
241 | -o track.tmp \\
|
---|
242 | ../xsl/bump.xsl \$(TRACKING_FILE); \\
|
---|
243 | sed -i 's@PACKDESC@$BLFS_ROOT/packdesc.dtd@' track.tmp; \\
|
---|
244 | xmllint --format --postvalid track.tmp > \$(TRACKING_FILE); \\
|
---|
245 | rm track.tmp; \\
|
---|
246 | done; \\
|
---|
247 | VERSION=\$\$(grep 'echo.*lfs-release' ../$LFS_XML/tmp/lfs-full.xml | \\
|
---|
248 | sed 's/.*echo[ ]*\([^ ]*\).*/\1/'); \\
|
---|
249 | xsltproc --stringparam packages ../packages.xml \\
|
---|
250 | --stringparam package LFS-Release \\
|
---|
251 | --stringparam version \$\$VERSION \\
|
---|
252 | -o track.tmp \\
|
---|
253 | ../xsl/bump.xsl \$(TRACKING_FILE); \\
|
---|
254 | sed -i 's@PACKDESC@$BLFS_ROOT/packdesc.dtd@' track.tmp; \\
|
---|
255 | xmllint --format --postvalid track.tmp > \$(TRACKING_FILE); \\
|
---|
256 | rm track.tmp; \\
|
---|
257 | for file in *-*; do \\
|
---|
258 | xsltproc --stringparam packages ../packages.xml \\
|
---|
259 | --stringparam package \$\${file##*z-} \\
|
---|
260 | -o track.tmp \\
|
---|
261 | ../xsl/bump.xsl \$(TRACKING_FILE); \\
|
---|
262 | sed -i 's@PACKDESC@$BLFS_ROOT/packdesc.dtd@' track.tmp; \\
|
---|
263 | xmllint --format --postvalid track.tmp > \$(TRACKING_FILE); \\
|
---|
264 | rm track.tmp; \\
|
---|
265 | done
|
---|
266 | @touch \$@
|
---|
267 | @echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK
|
---|
268 | @echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
269 | EOF
|
---|
270 | popd
|
---|
271 | }
|
---|