source: BLFS/gen_pkg_book.sh@ 7a82194

ablfs-more legacy trunk
Last change on this file since 7a82194 was 625cb14, checked in by Pierre Labastie <pierre@…>, 6 years ago

Add possibility to automate bash shell startup files, vimrc, and rng.
This adds a new variable to the configuration (LANGUAGE).
Also automate the generation of various <replaceable> instructions

  • Property mode set to 100755
File size: 5.7 KB
Line 
1#!/bin/bash
2#
3# $Id$
4#
5# Read and parse the configuration parameters..
6#
7set -e
8
9TOPDIR=$1
10if test -z "$TOPDIR"; then
11 TOPDIR=$(pwd)
12fi
13BLFS_FULL=$2
14if test -z "$BLFS_FULL"; then
15 BLFS_FULL=${TOPDIR}/blfs-xml/tmp/blfs-full.xml
16fi
17LFS_FULL=$3
18if test -z "$LFS_FULL"; then
19 LFS_FULL=${TOPDIR}/lfs-xml/tmp/lfs-full.xml
20fi
21declare -r ConfigFile="${TOPDIR}/configuration"
22declare DepDir="${TOPDIR}/dependencies"
23declare LibDir="${TOPDIR}/libs"
24declare PackFile="${TOPDIR}/packages.xml"
25declare BookXml="${TOPDIR}/book.xml"
26declare MakeBook="${TOPDIR}/xsl/make_book.xsl"
27declare MakeScripts="${TOPDIR}/xsl/scripts.xsl"
28declare BookHtml="${TOPDIR}/book-html"
29declare BLFS_XML="${TOPDIR}/blfs-xml"
30declare -a TARGET
31declare DEP_LEVEL
32declare SUDO
33declare LANGUAGE
34declare WRAP_INSTALL
35declare DEL_LA_FILES
36declare STATS
37
38#--------------------------#
39parse_configuration() { #
40#--------------------------#
41 local -i cntr=0
42 local -a optTARGET
43
44 while read; do
45
46 # Garbage collection
47 case ${REPLY} in
48 \#* | '') continue ;;
49 esac
50
51 case "${REPLY}" in
52 # Create global variables for these parameters.
53 optDependency=* | \
54 MAIL_SERVER=* | \
55 WRAP_INSTALL=* | \
56 DEL_LA_FILES=* | \
57 STATS=* | \
58 LANGUAGE=* | \
59 SUDO=* ) eval ${REPLY} # Define/set a global variable..
60 continue ;;
61 esac
62
63 if [[ "${REPLY}" =~ ^CONFIG_ ]]; then
64 echo "$REPLY"
65 optTARGET[$((cntr++))]=$( echo $REPLY | sed -e 's@CONFIG_@@' -e 's@=y@@' )
66 fi
67 done < $ConfigFile
68
69 if (( $cntr == 0 )); then
70 echo -e "\n>>> NO TARGET SELECTED.. application terminated"
71 echo -e " Run <make> again and select (a) package(s) to build\n"
72 exit 0
73 fi
74 TARGET=(${optTARGET[*]})
75 DEP_LEVEL=$optDependency
76 SUDO=${SUDO:-n}
77 WRAP_INSTALL=${WRAP_INSTALL:-n}
78 DEL_LA_FILES=${DEL_LA_FILES:-n}
79 STATS=${STATS:-n}
80}
81
82#--------------------------#
83validate_configuration() { #
84#--------------------------#
85 local -r dotSTR=".................."
86 local -r PARAM_LIST="DEP_LEVEL SUDO LANGUAGE MAIL_SERVER WRAP_INSTALL DEL_LA_FILES STATS"
87 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
88 local config_param
89 local -i index
90
91 for config_param in ${PARAM_LIST}; do
92 echo -e "`eval echo $PARAM_VALS`"
93 done
94 for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
95 echo -e "TARGET${index}${dotSTR:6} ${L_arrow}${BOLD}${TARGET[${index}]}${OFF}${R_arrow}"
96 done
97}
98
99#
100# Generates the root of the dependency tree
101#
102#--------------------------#
103generate_deps() { #
104#--------------------------#
105
106 local -i index
107 local DepDir=$1
108 rm -f $DepDir/*.{tree,dep}
109 for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
110 echo 1 b ${TARGET[${index}]} >> $DepDir/root.dep
111 done
112}
113
114#
115# Clean configuration file keeping only global default settings.
116# That prevent "trying to assign nonexistent symbol" messages
117# and assures that there is no TARGET selected from a previous run
118#
119#--------------------------#
120clean_configuration() { #
121#--------------------------#
122
123tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
124mv ${ConfigFile}.tmp ${ConfigFile}
125
126}
127
128#---------------------
129# Constants
130source ${LibDir}/constants.inc
131[[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
132
133#---------------------
134# Dependencies module
135source ${LibDir}/func_dependencies
136[[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
137
138#------- MAIN --------
139if [[ ! -f ${PackFile} ]] ; then
140 echo -e "\tNo packages file has been found.\n"
141 echo -e "\tExecution aborted.\n"
142 exit 1
143fi
144
145
146parse_configuration
147validate_configuration
148echo "${SD_BORDER}${nl_}"
149echo -n "Are you happy with these settings? yes/no (no): "
150read ANSWER
151if [ x$ANSWER != "xyes" ] ; then
152 echo "${nl_}Rerun make and fix your settings.${nl_}"
153 exit 1
154fi
155echo "${nl_}${SD_BORDER}${nl_}"
156
157rm -rf $DepDir
158mkdir $DepDir
159generate_deps $DepDir
160pushd $DepDir > /dev/null
161set +e
162generate_subgraph root.dep 1 1 b
163echo -e "\n${SD_BORDER}"
164echo Graph contains $(ls |wc -l) nodes
165echo -e "${SD_BORDER}"
166echo Cleaning subgraph...
167clean_subgraph
168echo done
169echo Generating the tree
170echo 1 > root.tree
171echo 1 >> root.tree
172cat root.dep >> root.tree
173generate_dependency_tree root.tree 1
174echo -e "\n${SD_BORDER}"
175#echo -e \\n provisional end...
176#exit
177echo Generating the ordered package list
178LIST="$(tree_browse root.tree)"
179set -e
180popd > /dev/null
181rm -f ${BookXml}
182echo Making XML book
183xsltproc --stringparam list "$LIST" \
184 --stringparam MTA "$MAIL_SERVER" \
185 --stringparam lfsbook "$LFS_FULL" \
186 -o ${BookXml} \
187 ${MakeBook} \
188 $BLFS_FULL
189echo "making HTML book (may take some time...)"
190xsltproc -o ${BookHtml}/ \
191 -stringparam chunk.quietly 1 \
192 ${BLFS_XML}/stylesheets/blfs-chunked.xsl \
193 ${BookXml}
194if [ ! -d ${BookHtml}/stylesheets ]
195 then mkdir -p ${BookHtml}/stylesheets
196 cp ${BLFS_XML}/stylesheets/lfs-xsl/*.css ${BookHtml}/stylesheets
197fi
198if [ ! -d ${BookHtml}/images ]
199 then mkdir -p ${BookHtml}/images
200 cp ${BLFS_XML}/images/*.png ${BookHtml}/images
201fi
202for ht in ${BookHtml}/*.html
203 do sed -i 's@\.\./stylesheets@stylesheets@' $ht
204 sed -i 's@\.\./images@images@' $ht
205done
206echo -en "\n\tGenerating the build scripts ...\n"
207rm -rf scripts
208if test $STATS = y; then
209 LIST_STAT="${TARGET[*]}"
210else
211 LIST_STAT=""
212fi
213xsltproc --xinclude --nonet \
214 --stringparam sudo "$SUDO" \
215 --stringparam wrap-install "$WRAP_INSTALL" \
216 --stringparam del-la-files "$DEL_LA_FILES" \
217 --stringparam list-stat "$LIST_STAT" \
218 --stringparam language "$LANGUAGE" \
219 -o ./scripts/ ${MakeScripts} \
220 ${BookXml}
221# Make the scripts executable.
222chmod -R +x scripts
223echo -e "done\n"
224
225#clean_configuration
Note: See TracBrowser for help on using the repository browser.