source: BLFS/gen_pkg_book.sh@ 78d04f3

ablfs-more trunk
Last change on this file since 78d04f3 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
RevLine 
[f4ed135]1#!/bin/bash
2#
3# Read and parse the configuration parameters..
4#
5set -e
6
[b8e5cad]7TRACKFILE=$1
8if test -z "$TRACKFILE"; then
[b734bfb]9 TRACKFILE=tracking-dir/instpkg.xml
[b8e5cad]10fi
11TOPDIR=$2
[e576789]12if test -z "$TOPDIR"; then
13 TOPDIR=$(pwd)
14fi
[b8e5cad]15BLFS_FULL=$3
[e576789]16if test -z "$BLFS_FULL"; then
17 BLFS_FULL=${TOPDIR}/blfs-xml/tmp/blfs-full.xml
18fi
[b8e5cad]19LFS_FULL=$4
[607ef21]20if test -z "$LFS_FULL"; then
21 LFS_FULL=${TOPDIR}/lfs-xml/tmp/lfs-full.xml
22fi
[e576789]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"
[a690d42]29declare GetVersion="${TOPDIR}/xsl/get_version.xsl"
[e576789]30declare MakeScripts="${TOPDIR}/xsl/scripts.xsl"
[42dfc6e]31declare ListLFS="${TOPDIR}/xsl/list_lfs.xsl"
[e576789]32declare BookHtml="${TOPDIR}/book-html"
33declare BLFS_XML="${TOPDIR}/blfs-xml"
34declare -a TARGET
[f4ed135]35declare DEP_LEVEL
36declare SUDO
[625cb14]37declare LANGUAGE
[945ccaa]38declare WRAP_INSTALL
[9daa202]39declare PACK_INSTALL
[625cb14]40declare DEL_LA_FILES
41declare STATS
[dedd502]42declare DEP_CHECK
[9daa202]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
[f4ed135]52
53#--------------------------#
54parse_configuration() { #
55#--------------------------#
[e576789]56 local -i cntr=0
57 local -a optTARGET
[f4ed135]58
[e576789]59 while read; do
[f4ed135]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=* | \
[945ccaa]70 WRAP_INSTALL=* | \
[9daa202]71 PACK_INSTALL=* | \
[dc7fd7b]72 DEL_LA_FILES=* | \
[67c3df4]73 STATS=* | \
[dedd502]74 DEP_CHECK=* | \
[625cb14]75 LANGUAGE=* | \
[9daa202]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..
[f4ed135]86 continue ;;
87 esac
88
[a96109a]89 if [[ "${REPLY}" =~ ^CONFIG_ ]]; then
[e576789]90 echo "$REPLY"
91 optTARGET[$((cntr++))]=$( echo $REPLY | sed -e 's@CONFIG_@@' -e 's@=y@@' )
[f4ed135]92 fi
[e576789]93 done < $ConfigFile
[f4ed135]94
[e576789]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"
[f4ed135]98 exit 0
99 fi
[e576789]100 TARGET=(${optTARGET[*]})
[f4ed135]101 DEP_LEVEL=$optDependency
102 SUDO=${SUDO:-n}
[945ccaa]103 WRAP_INSTALL=${WRAP_INSTALL:-n}
[dc7fd7b]104 DEL_LA_FILES=${DEL_LA_FILES:-n}
[67c3df4]105 STATS=${STATS:-n}
[9daa202]106# Other boolean variables are supposed to be either set or unset. Their values
107# are not relevant
[f4ed135]108}
109
110#--------------------------#
111validate_configuration() { #
112#--------------------------#
113 local -r dotSTR=".................."
[dedd502]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"
[f4ed135]115 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
116 local config_param
[e576789]117 local -i index
[f4ed135]118
119 for config_param in ${PARAM_LIST}; do
120 echo -e "`eval echo $PARAM_VALS`"
121 done
[e576789]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
[f4ed135]125}
126
127#
[e576789]128# Generates the root of the dependency tree
[f4ed135]129#
130#--------------------------#
[67c3df4]131generate_deps() { #
[f4ed135]132#--------------------------#
133
[e576789]134 local -i index
135 local DepDir=$1
[2140f22]136 rm -f $DepDir/*.{tree,dep}
[e576789]137 for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
[2140f22]138 echo 1 b ${TARGET[${index}]} >> $DepDir/root.dep
[f4ed135]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
[e576789]151tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
152mv ${ConfigFile}.tmp ${ConfigFile}
[f4ed135]153
154}
155
156#---------------------
157# Constants
[e576789]158source ${LibDir}/constants.inc
[f4ed135]159[[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
160
161#---------------------
162# Dependencies module
[e576789]163source ${LibDir}/func_dependencies
[f4ed135]164[[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
165
166#------- MAIN --------
[e576789]167if [[ ! -f ${PackFile} ]] ; then
[f4ed135]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_}"
[e576789]184
185rm -rf $DepDir
186mkdir $DepDir
187generate_deps $DepDir
188pushd $DepDir > /dev/null
189set +e
[2140f22]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}"
[a690d42]203echo Generating the ordered full dependency list
204FULL_LIST="$(tree_browse root.tree)"
205set -e
206popd > /dev/null
207#echo "$FULL_LIST"
[2140f22]208#echo -e \\n provisional end...
209#exit
210echo Generating the ordered package list
[a690d42]211LIST=
212while read p; do
[7ae9774]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
[a690d42]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
[e576789]244rm -f ${BookXml}
245echo Making XML book
[607ef21]246xsltproc --stringparam list "$LIST" \
[2140f22]247 --stringparam MTA "$MAIL_SERVER" \
[607ef21]248 --stringparam lfsbook "$LFS_FULL" \
[e576789]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
[c5650f9]266 do sed -i 's@\.\./stylesheets@stylesheets@' $ht
267 sed -i 's@\.\./images@images@' $ht
[e576789]268done
269echo -en "\n\tGenerating the build scripts ...\n"
270rm -rf scripts
[67c3df4]271if test $STATS = y; then
272 LIST_STAT="${TARGET[*]}"
273else
274 LIST_STAT=""
275fi
[9daa202]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} \
[e576789]295 ${BookXml}
296# Make the scripts executable.
297chmod -R +x scripts
298echo -e "done\n"
299
[1bf09c1]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)"
[4dfe8f9]324 sudo porg -rb \$p
[1bf09c1]325done
326
327# Function to restore packages
[4dfe8f9]328restore_pack () {
[1bf09c1]329for p in \$VERSIONED_LIST; do
[4dfe8f9]330 sudo porgball -e -l /var/lib/packages/\${p}.porg.tar.gz
[1bf09c1]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
[e576789]346#clean_configuration
Note: See TracBrowser for help on using the repository browser.