[f4ed135] | 1 | #!/bin/bash
|
---|
| 2 | #
|
---|
| 3 | # Read and parse the configuration parameters..
|
---|
| 4 | #
|
---|
| 5 | set -e
|
---|
| 6 |
|
---|
[b8e5cad] | 7 | TRACKFILE=$1
|
---|
| 8 | if test -z "$TRACKFILE"; then
|
---|
[b734bfb] | 9 | TRACKFILE=tracking-dir/instpkg.xml
|
---|
[b8e5cad] | 10 | fi
|
---|
| 11 | TOPDIR=$2
|
---|
[e576789] | 12 | if test -z "$TOPDIR"; then
|
---|
| 13 | TOPDIR=$(pwd)
|
---|
| 14 | fi
|
---|
[b8e5cad] | 15 | BLFS_FULL=$3
|
---|
[e576789] | 16 | if test -z "$BLFS_FULL"; then
|
---|
| 17 | BLFS_FULL=${TOPDIR}/blfs-xml/tmp/blfs-full.xml
|
---|
| 18 | fi
|
---|
[b8e5cad] | 19 | LFS_FULL=$4
|
---|
[607ef21] | 20 | if test -z "$LFS_FULL"; then
|
---|
| 21 | LFS_FULL=${TOPDIR}/lfs-xml/tmp/lfs-full.xml
|
---|
| 22 | fi
|
---|
[e576789] | 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"
|
---|
[a690d42] | 29 | declare GetVersion="${TOPDIR}/xsl/get_version.xsl"
|
---|
[e576789] | 30 | declare MakeScripts="${TOPDIR}/xsl/scripts.xsl"
|
---|
[42dfc6e] | 31 | declare ListLFS="${TOPDIR}/xsl/list_lfs.xsl"
|
---|
[e576789] | 32 | declare BookHtml="${TOPDIR}/book-html"
|
---|
| 33 | declare BLFS_XML="${TOPDIR}/blfs-xml"
|
---|
| 34 | declare -a TARGET
|
---|
[f4ed135] | 35 | declare DEP_LEVEL
|
---|
| 36 | declare SUDO
|
---|
[625cb14] | 37 | declare LANGUAGE
|
---|
[945ccaa] | 38 | declare WRAP_INSTALL
|
---|
[9daa202] | 39 | declare PACK_INSTALL
|
---|
[625cb14] | 40 | declare DEL_LA_FILES
|
---|
| 41 | declare STATS
|
---|
[dedd502] | 42 | declare DEP_CHECK
|
---|
[9daa202] | 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
|
---|
[f4ed135] | 52 |
|
---|
| 53 | #--------------------------#
|
---|
| 54 | parse_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 | #--------------------------#
|
---|
| 111 | validate_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] | 131 | generate_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 | #--------------------------#
|
---|
| 148 | clean_configuration() { #
|
---|
| 149 | #--------------------------#
|
---|
| 150 |
|
---|
[e576789] | 151 | tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
|
---|
| 152 | mv ${ConfigFile}.tmp ${ConfigFile}
|
---|
[f4ed135] | 153 |
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | #---------------------
|
---|
| 157 | # Constants
|
---|
[e576789] | 158 | source ${LibDir}/constants.inc
|
---|
[f4ed135] | 159 | [[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
|
---|
| 160 |
|
---|
| 161 | #---------------------
|
---|
| 162 | # Dependencies module
|
---|
[e576789] | 163 | source ${LibDir}/func_dependencies
|
---|
[f4ed135] | 164 | [[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
|
---|
| 165 |
|
---|
| 166 | #------- MAIN --------
|
---|
[e576789] | 167 | if [[ ! -f ${PackFile} ]] ; then
|
---|
[f4ed135] | 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_}"
|
---|
[e576789] | 184 |
|
---|
| 185 | rm -rf $DepDir
|
---|
| 186 | mkdir $DepDir
|
---|
| 187 | generate_deps $DepDir
|
---|
| 188 | pushd $DepDir > /dev/null
|
---|
| 189 | set +e
|
---|
[2140f22] | 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}"
|
---|
[a690d42] | 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"
|
---|
[2140f22] | 208 | #echo -e \\n provisional end...
|
---|
| 209 | #exit
|
---|
| 210 | echo Generating the ordered package list
|
---|
[a690d42] | 211 | LIST=
|
---|
| 212 | while 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.
|
---|
| 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
|
---|
[a690d42] | 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
|
---|
[e576789] | 244 | rm -f ${BookXml}
|
---|
| 245 | echo Making XML book
|
---|
[607ef21] | 246 | xsltproc --stringparam list "$LIST" \
|
---|
[2140f22] | 247 | --stringparam MTA "$MAIL_SERVER" \
|
---|
[607ef21] | 248 | --stringparam lfsbook "$LFS_FULL" \
|
---|
[e576789] | 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
|
---|
[c5650f9] | 266 | do sed -i 's@\.\./stylesheets@stylesheets@' $ht
|
---|
| 267 | sed -i 's@\.\./images@images@' $ht
|
---|
[e576789] | 268 | done
|
---|
| 269 | echo -en "\n\tGenerating the build scripts ...\n"
|
---|
| 270 | rm -rf scripts
|
---|
[67c3df4] | 271 | if test $STATS = y; then
|
---|
| 272 | LIST_STAT="${TARGET[*]}"
|
---|
| 273 | else
|
---|
| 274 | LIST_STAT=""
|
---|
| 275 | fi
|
---|
[9daa202] | 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} \
|
---|
[e576789] | 295 | ${BookXml}
|
---|
| 296 | # Make the scripts executable.
|
---|
| 297 | chmod -R +x scripts
|
---|
| 298 | echo -e "done\n"
|
---|
| 299 |
|
---|
[1bf09c1] | 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)"
|
---|
[4dfe8f9] | 324 | sudo porg -rb \$p
|
---|
[1bf09c1] | 325 | done
|
---|
| 326 |
|
---|
| 327 | # Function to restore packages
|
---|
[4dfe8f9] | 328 | restore_pack () {
|
---|
[1bf09c1] | 329 | for p in \$VERSIONED_LIST; do
|
---|
[4dfe8f9] | 330 | sudo porgball -e -l /var/lib/packages/\${p}.porg.tar.gz
|
---|
[1bf09c1] | 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
|
---|
[e576789] | 346 | #clean_configuration
|
---|