1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # Read and parse the configuration parameters..
|
---|
4 | #
|
---|
5 | set -e
|
---|
6 |
|
---|
7 | TRACKFILE=$1
|
---|
8 | if test -z "$TRACKFILE"; then
|
---|
9 | TRACKFILE=tracking-dir/instpkg.xml
|
---|
10 | fi
|
---|
11 | TOPDIR=$2
|
---|
12 | if test -z "$TOPDIR"; then
|
---|
13 | TOPDIR=$(pwd)
|
---|
14 | fi
|
---|
15 | BLFS_FULL=$3
|
---|
16 | if test -z "$BLFS_FULL"; then
|
---|
17 | BLFS_FULL=${TOPDIR}/blfs-xml/tmp/blfs-full.xml
|
---|
18 | fi
|
---|
19 | LFS_FULL=$4
|
---|
20 | if test -z "$LFS_FULL"; then
|
---|
21 | LFS_FULL=${TOPDIR}/lfs-xml/tmp/lfs-full.xml
|
---|
22 | fi
|
---|
23 | declare -r ConfigFile="${TOPDIR}/configuration"
|
---|
24 | declare DepDir="${TOPDIR}/dependencies"
|
---|
25 | declare LibDir="${TOPDIR}/libs"
|
---|
26 | declare PackFile="${TOPDIR}/packages.xml"
|
---|
27 | declare BookXml="${TOPDIR}/book.xml"
|
---|
28 | declare MakeBook="${TOPDIR}/xsl/make_book.xsl"
|
---|
29 | declare GetVersion="${TOPDIR}/xsl/get_version.xsl"
|
---|
30 | declare MakeScripts="${TOPDIR}/xsl/scripts.xsl"
|
---|
31 | declare ListLFS="${TOPDIR}/xsl/list_lfs.xsl"
|
---|
32 | declare BookHtml="${TOPDIR}/book-html"
|
---|
33 | declare BLFS_XML="${TOPDIR}/blfs-xml"
|
---|
34 | declare -a TARGET
|
---|
35 | declare DEP_LEVEL
|
---|
36 | declare SUDO
|
---|
37 | declare LANGUAGE
|
---|
38 | declare WRAP_INSTALL
|
---|
39 | declare PACK_INSTALL
|
---|
40 | declare DEL_LA_FILES
|
---|
41 | declare STATS
|
---|
42 | declare DEP_CHECK
|
---|
43 | declare SRC_ARCHIVE
|
---|
44 | declare SRC_SUBDIRS
|
---|
45 | declare BUILD_ROOT
|
---|
46 | declare BUILD_SUBDIRS
|
---|
47 | declare KEEP_FILES
|
---|
48 | declare -i JOBS
|
---|
49 | declare CFG_CFLAGS
|
---|
50 | declare CFG_CXXFLAGS
|
---|
51 | declare CFG_LDFLAGS
|
---|
52 |
|
---|
53 | #--------------------------#
|
---|
54 | parse_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 | #--------------------------#
|
---|
111 | validate_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 | #--------------------------#
|
---|
131 | generate_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 | #--------------------------#
|
---|
148 | clean_configuration() { #
|
---|
149 | #--------------------------#
|
---|
150 |
|
---|
151 | tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
|
---|
152 | mv ${ConfigFile}.tmp ${ConfigFile}
|
---|
153 |
|
---|
154 | }
|
---|
155 |
|
---|
156 | #---------------------
|
---|
157 | # Constants
|
---|
158 | source ${LibDir}/constants.inc
|
---|
159 | [[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
|
---|
160 |
|
---|
161 | #---------------------
|
---|
162 | # Dependencies module
|
---|
163 | source ${LibDir}/func_dependencies
|
---|
164 | [[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
|
---|
165 |
|
---|
166 | #------- MAIN --------
|
---|
167 | if [[ ! -f ${PackFile} ]] ; then
|
---|
168 | echo -e "\tNo packages file has been found.\n"
|
---|
169 | echo -e "\tExecution aborted.\n"
|
---|
170 | exit 1
|
---|
171 | fi
|
---|
172 |
|
---|
173 |
|
---|
174 | parse_configuration
|
---|
175 | validate_configuration
|
---|
176 | echo "${SD_BORDER}${nl_}"
|
---|
177 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
178 | read ANSWER
|
---|
179 | if [ x$ANSWER != "xyes" ] ; then
|
---|
180 | echo "${nl_}Rerun make and fix your settings.${nl_}"
|
---|
181 | exit 1
|
---|
182 | fi
|
---|
183 | echo "${nl_}${SD_BORDER}${nl_}"
|
---|
184 |
|
---|
185 | rm -rf $DepDir
|
---|
186 | mkdir $DepDir
|
---|
187 | generate_deps $DepDir
|
---|
188 | pushd $DepDir > /dev/null
|
---|
189 | set +e
|
---|
190 | generate_subgraph root.dep 1 1 b
|
---|
191 | echo -e "\n${SD_BORDER}"
|
---|
192 | echo Graph contains $(ls |wc -l) nodes
|
---|
193 | echo -e "${SD_BORDER}"
|
---|
194 | echo Cleaning subgraph...
|
---|
195 | clean_subgraph
|
---|
196 | echo done
|
---|
197 | echo Generating the tree
|
---|
198 | echo 1 > root.tree
|
---|
199 | echo 1 >> root.tree
|
---|
200 | cat root.dep >> root.tree
|
---|
201 | generate_dependency_tree root.tree 1
|
---|
202 | echo -e "\n${SD_BORDER}"
|
---|
203 | echo Generating the ordered full dependency list
|
---|
204 | FULL_LIST="$(tree_browse root.tree)"
|
---|
205 | set -e
|
---|
206 | popd > /dev/null
|
---|
207 | #echo "$FULL_LIST"
|
---|
208 | #echo -e \\n provisional end...
|
---|
209 | #exit
|
---|
210 | echo Generating the ordered package list
|
---|
211 | LIST=
|
---|
212 | while 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.
|
---|
217 | echo Treating $p
|
---|
218 | pass2_v=$(xsltproc --stringparam package "${p%-pass1}" \
|
---|
219 | $GetVersion $TRACKFILE | head -n1)
|
---|
220 | echo 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
|
---|
226 | echo 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)
|
---|
230 | echo 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
|
---|
240 | done <<<$FULL_LIST
|
---|
241 | #echo \""$LIST"\"
|
---|
242 | #echo -e \\n provisional end...
|
---|
243 | #exit
|
---|
244 | rm -f ${BookXml}
|
---|
245 | echo Making XML book
|
---|
246 | xsltproc --stringparam list "$LIST" \
|
---|
247 | --stringparam MTA "$MAIL_SERVER" \
|
---|
248 | --stringparam lfsbook "$LFS_FULL" \
|
---|
249 | -o ${BookXml} \
|
---|
250 | ${MakeBook} \
|
---|
251 | $BLFS_FULL
|
---|
252 | echo "making HTML book (may take some time...)"
|
---|
253 | xsltproc -o ${BookHtml}/ \
|
---|
254 | -stringparam chunk.quietly 1 \
|
---|
255 | ${BLFS_XML}/stylesheets/blfs-chunked.xsl \
|
---|
256 | ${BookXml}
|
---|
257 | if [ ! -d ${BookHtml}/stylesheets ]
|
---|
258 | then mkdir -p ${BookHtml}/stylesheets
|
---|
259 | cp ${BLFS_XML}/stylesheets/lfs-xsl/*.css ${BookHtml}/stylesheets
|
---|
260 | fi
|
---|
261 | if [ ! -d ${BookHtml}/images ]
|
---|
262 | then mkdir -p ${BookHtml}/images
|
---|
263 | cp ${BLFS_XML}/images/*.png ${BookHtml}/images
|
---|
264 | fi
|
---|
265 | for ht in ${BookHtml}/*.html
|
---|
266 | do sed -i 's@\.\./stylesheets@stylesheets@' $ht
|
---|
267 | sed -i 's@\.\./images@images@' $ht
|
---|
268 | done
|
---|
269 | echo -en "\n\tGenerating the build scripts ...\n"
|
---|
270 | rm -rf scripts
|
---|
271 | if test $STATS = y; then
|
---|
272 | LIST_STAT="${TARGET[*]}"
|
---|
273 | else
|
---|
274 | LIST_STAT=""
|
---|
275 | fi
|
---|
276 | xsltproc --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.
|
---|
297 | chmod -R +x scripts
|
---|
298 | echo -e "done\n"
|
---|
299 |
|
---|
300 | if [ -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
|
---|
318 | set -e
|
---|
319 |
|
---|
320 | # Remove all unneeded packages
|
---|
321 | VERSIONED_LIST=
|
---|
322 | for p in $LIST_UNNEEDED; do
|
---|
323 | VERSIONED_LIST="\$VERSIONED_LIST \$(porg \$p)"
|
---|
324 | sudo porg -rb \$p
|
---|
325 | done
|
---|
326 |
|
---|
327 | # Function to restore packages
|
---|
328 | restore_pack () {
|
---|
329 | for p in \$VERSIONED_LIST; do
|
---|
330 | sudo porgball -e -l /var/lib/packages/\${p}.porg.tar.gz
|
---|
331 | done
|
---|
332 | }
|
---|
333 |
|
---|
334 | trap restore_pack ERR
|
---|
335 |
|
---|
336 | EOF
|
---|
337 | cat >tail.tmp <<EOF
|
---|
338 | restore_pack
|
---|
339 | exit
|
---|
340 | EOF
|
---|
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
|
---|
345 | fi
|
---|
346 | #clean_configuration
|
---|