source: BLFS/gen_pkg_book.sh@ 57a5e9a

trunk
Last change on this file since 57a5e9a was 4dfe8f9, checked in by Pierre Labastie <pierre.labastie@…>, 20 months ago

gen_pkg_book: fixes for dependency checkings

Fix a typo in function definition
use sudo for porg -r and porgball -e

  • Property mode set to 100755
File size: 9.7 KB
Line 
1#!/bin/bash
2#
3# Read and parse the configuration parameters..
4#
5set -e
6
7TRACKFILE=$1
8if test -z "$TRACKFILE"; then
9 TRACKFILE=tracking-dir/instpkg.xml
10fi
11TOPDIR=$2
12if test -z "$TOPDIR"; then
13 TOPDIR=$(pwd)
14fi
15BLFS_FULL=$3
16if test -z "$BLFS_FULL"; then
17 BLFS_FULL=${TOPDIR}/blfs-xml/tmp/blfs-full.xml
18fi
19LFS_FULL=$4
20if test -z "$LFS_FULL"; then
21 LFS_FULL=${TOPDIR}/lfs-xml/tmp/lfs-full.xml
22fi
23declare -r ConfigFile="${TOPDIR}/configuration"
24declare DepDir="${TOPDIR}/dependencies"
25declare LibDir="${TOPDIR}/libs"
26declare PackFile="${TOPDIR}/packages.xml"
27declare BookXml="${TOPDIR}/book.xml"
28declare MakeBook="${TOPDIR}/xsl/make_book.xsl"
29declare GetVersion="${TOPDIR}/xsl/get_version.xsl"
30declare MakeScripts="${TOPDIR}/xsl/scripts.xsl"
31declare ListLFS="${TOPDIR}/xsl/list_lfs.xsl"
32declare BookHtml="${TOPDIR}/book-html"
33declare BLFS_XML="${TOPDIR}/blfs-xml"
34declare -a TARGET
35declare DEP_LEVEL
36declare SUDO
37declare LANGUAGE
38declare WRAP_INSTALL
39declare PACK_INSTALL
40declare DEL_LA_FILES
41declare STATS
42declare DEP_CHECK
43declare SRC_ARCHIVE
44declare SRC_SUBDIRS
45declare BUILD_ROOT
46declare BUILD_SUBDIRS
47declare KEEP_FILES
48declare -i JOBS
49declare CFG_CFLAGS
50declare CFG_CXXFLAGS
51declare CFG_LDFLAGS
52
53#--------------------------#
54parse_configuration() { #
55#--------------------------#
56 local -i cntr=0
57 local -a optTARGET
58
59 while read; do
60
61 # Garbage collection
62 case ${REPLY} in
63 \#* | '') continue ;;
64 esac
65
66 case "${REPLY}" in
67 # Create global variables for these parameters.
68 optDependency=* | \
69 MAIL_SERVER=* | \
70 WRAP_INSTALL=* | \
71 PACK_INSTALL=* | \
72 DEL_LA_FILES=* | \
73 STATS=* | \
74 DEP_CHECK=* | \
75 LANGUAGE=* | \
76 SUDO=* | \
77 SRC_ARCHIVE=* | \
78 SRC_SUBDIRS=* | \
79 BUILD_ROOT=* | \
80 BUILD_SUBDIRS=* | \
81 KEEP_FILES=* | \
82 JOBS=* | \
83 CFG_CFLAGS=* | \
84 CFG_CXXFLAGS=* | \
85 CFG_LDFLAGS=* ) eval ${REPLY} # Define/set a global variable..
86 continue ;;
87 esac
88
89 if [[ "${REPLY}" =~ ^CONFIG_ ]]; then
90 echo "$REPLY"
91 optTARGET[$((cntr++))]=$( echo $REPLY | sed -e 's@CONFIG_@@' -e 's@=y@@' )
92 fi
93 done < $ConfigFile
94
95 if (( $cntr == 0 )); then
96 echo -e "\n>>> NO TARGET SELECTED.. application terminated"
97 echo -e " Run <make> again and select (a) package(s) to build\n"
98 exit 0
99 fi
100 TARGET=(${optTARGET[*]})
101 DEP_LEVEL=$optDependency
102 SUDO=${SUDO:-n}
103 WRAP_INSTALL=${WRAP_INSTALL:-n}
104 DEL_LA_FILES=${DEL_LA_FILES:-n}
105 STATS=${STATS:-n}
106# Other boolean variables are supposed to be either set or unset. Their values
107# are not relevant
108}
109
110#--------------------------#
111validate_configuration() { #
112#--------------------------#
113 local -r dotSTR=".................."
114 local -r PARAM_LIST="DEP_LEVEL SUDO LANGUAGE MAIL_SERVER WRAP_INSTALL PACK_INSTALL DEL_LA_FILES STATS DEP_CHECK SRC_ARCHIVE SRC_SUBDIRS BUILD_ROOT BUILD_SUBDIRS KEEP_FILES JOBS CFG_CFLAGS CFG_CXXFLAGS CFG_LDFLAGS"
115 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
116 local config_param
117 local -i index
118
119 for config_param in ${PARAM_LIST}; do
120 echo -e "`eval echo $PARAM_VALS`"
121 done
122 for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
123 echo -e "TARGET${index}${dotSTR:6} ${L_arrow}${BOLD}${TARGET[${index}]}${OFF}${R_arrow}"
124 done
125}
126
127#
128# Generates the root of the dependency tree
129#
130#--------------------------#
131generate_deps() { #
132#--------------------------#
133
134 local -i index
135 local DepDir=$1
136 rm -f $DepDir/*.{tree,dep}
137 for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
138 echo 1 b ${TARGET[${index}]} >> $DepDir/root.dep
139 done
140}
141
142#
143# Clean configuration file keeping only global default settings.
144# That prevent "trying to assign nonexistent symbol" messages
145# and assures that there is no TARGET selected from a previous run
146#
147#--------------------------#
148clean_configuration() { #
149#--------------------------#
150
151tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
152mv ${ConfigFile}.tmp ${ConfigFile}
153
154}
155
156#---------------------
157# Constants
158source ${LibDir}/constants.inc
159[[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
160
161#---------------------
162# Dependencies module
163source ${LibDir}/func_dependencies
164[[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
165
166#------- MAIN --------
167if [[ ! -f ${PackFile} ]] ; then
168 echo -e "\tNo packages file has been found.\n"
169 echo -e "\tExecution aborted.\n"
170 exit 1
171fi
172
173
174parse_configuration
175validate_configuration
176echo "${SD_BORDER}${nl_}"
177echo -n "Are you happy with these settings? yes/no (no): "
178read ANSWER
179if [ x$ANSWER != "xyes" ] ; then
180 echo "${nl_}Rerun make and fix your settings.${nl_}"
181 exit 1
182fi
183echo "${nl_}${SD_BORDER}${nl_}"
184
185rm -rf $DepDir
186mkdir $DepDir
187generate_deps $DepDir
188pushd $DepDir > /dev/null
189set +e
190generate_subgraph root.dep 1 1 b
191echo -e "\n${SD_BORDER}"
192echo Graph contains $(ls |wc -l) nodes
193echo -e "${SD_BORDER}"
194echo Cleaning subgraph...
195clean_subgraph
196echo done
197echo Generating the tree
198echo 1 > root.tree
199echo 1 >> root.tree
200cat root.dep >> root.tree
201generate_dependency_tree root.tree 1
202echo -e "\n${SD_BORDER}"
203echo Generating the ordered full dependency list
204FULL_LIST="$(tree_browse root.tree)"
205set -e
206popd > /dev/null
207#echo "$FULL_LIST"
208#echo -e \\n provisional end...
209#exit
210echo Generating the ordered package list
211LIST=
212while read p; do
213 if [ "$p" != "${p%-pass1}" ]; then
214# If the pass2 is installed, no need for pass1. We get its
215# installed version from TRACKFILE; We could use PackFile, but
216# the test would be slightly more complicated.
217echo Treating $p
218 pass2_v=$(xsltproc --stringparam package "${p%-pass1}" \
219 $GetVersion $TRACKFILE | head -n1)
220echo Found pass2_v=$pass2_v
221 if [ -n "$pass2_v" ]; then continue; fi
222# We need to get the installed version from TRACKFILE
223 inst_v=$(xsltproc --stringparam package "$p" $GetVersion $TRACKFILE | \
224 head -n1)
225 if [ -z "$inst_v" ]; then inst_v=0; fi
226echo Found inst_v=$inst_v
227# The available version is taken from PackFile
228 avail_v=$(xsltproc --stringparam package "${p%-pass1}" \
229 $GetVersion $PackFile | head -n1)
230echo Found avail_v=$avail_v
231 versions="$avail_v
232$inst_v"
233 echo which gives versions=$versions
234 else
235 versions=$(xsltproc --stringparam package "$p" $GetVersion $PackFile)
236 fi
237 if [ "$versions" != "$(sort -V <<<$versions)" ]; then
238 LIST="$LIST $p"
239 fi
240done <<<$FULL_LIST
241#echo \""$LIST"\"
242#echo -e \\n provisional end...
243#exit
244rm -f ${BookXml}
245echo Making XML book
246xsltproc --stringparam list "$LIST" \
247 --stringparam MTA "$MAIL_SERVER" \
248 --stringparam lfsbook "$LFS_FULL" \
249 -o ${BookXml} \
250 ${MakeBook} \
251 $BLFS_FULL
252echo "making HTML book (may take some time...)"
253xsltproc -o ${BookHtml}/ \
254 -stringparam chunk.quietly 1 \
255 ${BLFS_XML}/stylesheets/blfs-chunked.xsl \
256 ${BookXml}
257if [ ! -d ${BookHtml}/stylesheets ]
258 then mkdir -p ${BookHtml}/stylesheets
259 cp ${BLFS_XML}/stylesheets/lfs-xsl/*.css ${BookHtml}/stylesheets
260fi
261if [ ! -d ${BookHtml}/images ]
262 then mkdir -p ${BookHtml}/images
263 cp ${BLFS_XML}/images/*.png ${BookHtml}/images
264fi
265for ht in ${BookHtml}/*.html
266 do sed -i 's@\.\./stylesheets@stylesheets@' $ht
267 sed -i 's@\.\./images@images@' $ht
268done
269echo -en "\n\tGenerating the build scripts ...\n"
270rm -rf scripts
271if test $STATS = y; then
272 LIST_STAT="${TARGET[*]}"
273else
274 LIST_STAT=""
275fi
276xsltproc --xinclude --nonet \
277 --stringparam language "$LANGUAGE" \
278 --stringparam sudo "$SUDO" \
279 --stringparam wrap-install "$WRAP_INSTALL" \
280 --stringparam pack-install "$PACK_INSTALL" \
281 --stringparam del-la-files "$DEL_LA_FILES" \
282 --stringparam list-stat "$LIST_STAT" \
283 --stringparam src-archive "$SRC_ARCHIVE" \
284 --stringparam src-subdirs "$SRC_SUBDIRS" \
285 --stringparam build-root "$BUILD_ROOT" \
286 --stringparam build-subdirs "$BUILD_SUBDIRS" \
287 --stringparam keep-files "$KEEP_FILES" \
288 --param jobs "$JOBS" \
289 --stringparam cfg-cflags "$CFG_CFLAGS" \
290 --stringparam cfg-cxxflags "$CFG_CXXFLAGS" \
291 --stringparam cfg-ldflags "$CFG_LDFLAGS" \
292 --stringparam fqdn "$(hostname -f)" \
293 --output ./scripts/ \
294 ${MakeScripts} \
295 ${BookXml}
296# Make the scripts executable.
297chmod -R +x scripts
298echo -e "done\n"
299
300if [ -n "$DEP_CHECK" ]; then
301 if (( ${#TARGET[*]} != 1 )); then
302 printf "\nWARNING: If dependencies are checked, only one package\n"
303 printf " shoud be selected. Not generating check code.\n"
304 exit
305 fi
306
307 LIST_LFS="$(xsltproc $ListLFS $LFS_FULL)"
308 LIST_NEEDED="$(echo $FULL_LIST)"
309 LIST_INSTALLED="$(porg -a | sed 's/-[[:digit:]].*//')"
310 LIST_UNNEEDED=
311 for p in $LIST_INSTALLED; do
312 case " $LIST_LFS " in *" $p "*) continue ;; esac
313 case " $LIST_NEEDED " in *" $p "*) continue ;; esac
314 LIST_UNNEEDED="$LIST_UNNEEDED $p"
315 done
316 cat >head.tmp <<EOF
317#!/bin/bash
318set -e
319
320# Remove all unneeded packages
321VERSIONED_LIST=
322for p in $LIST_UNNEEDED; do
323 VERSIONED_LIST="\$VERSIONED_LIST \$(porg \$p)"
324 sudo porg -rb \$p
325done
326
327# Function to restore packages
328restore_pack () {
329for p in \$VERSIONED_LIST; do
330 sudo porgball -e -l /var/lib/packages/\${p}.porg.tar.gz
331done
332}
333
334trap restore_pack ERR
335
336EOF
337 cat >tail.tmp <<EOF
338restore_pack
339exit
340EOF
341
342 sed -e "1,2d" -e '$d' scripts/*${TARGET} >script.tmp
343 cat head.tmp script.tmp tail.tmp >scripts/*${TARGET}
344 rm *.tmp
345fi
346#clean_configuration
Note: See TracBrowser for help on using the repository browser.