[877cc6a] | 1 | # $Id$
|
---|
| 2 |
|
---|
| 3 | check_version() {
|
---|
| 4 | : <<inline_doc
|
---|
[045b2dc] | 5 | Tests for a minimum version level. Compares to version numbers and forces an
|
---|
[877cc6a] | 6 | exit if minimum level not met.
|
---|
| 7 | NOTE: This test will fail on versions containing alpha chars. ie. jpeg 6b
|
---|
[045b2dc] | 8 |
|
---|
[877cc6a] | 9 | usage: check_version "2.6.2" "`uname -r`" "KERNEL"
|
---|
| 10 | check_version "3.0" "$BASH_VERSION" "BASH"
|
---|
| 11 | check_version "3.0" "`gcc -dumpversion`" "GCC"
|
---|
| 12 |
|
---|
| 13 | input vars: $1=min acceptable version
|
---|
| 14 | $2=version to check
|
---|
| 15 | $3=app name
|
---|
| 16 | externals: --
|
---|
| 17 | modifies: --
|
---|
| 18 | returns: nothing
|
---|
| 19 | on error: write text to console and dies
|
---|
| 20 | on success: write text to console and returns
|
---|
| 21 | inline_doc
|
---|
| 22 |
|
---|
| 23 | declare -i major minor revision change
|
---|
| 24 | declare -i ref_major ref_minor ref_revision ref_change
|
---|
[1825286] | 25 | declare -r spaceSTR=" "
|
---|
[877cc6a] | 26 |
|
---|
[7072e1f] | 27 | shopt -s extglob #needed for ${x##*(0)} below
|
---|
| 28 |
|
---|
[877cc6a] | 29 | ref_version=$1
|
---|
| 30 | tst_version=$2
|
---|
| 31 | TXT=$3
|
---|
| 32 |
|
---|
| 33 | # This saves us the save/restore hassle of the system IFS value
|
---|
| 34 | local IFS
|
---|
| 35 |
|
---|
| 36 | write_error_and_die() {
|
---|
[dda2496] | 37 | echo -e "\n\t\t$TXT is missing or version -->${tst_version}<-- is too old.
|
---|
[877cc6a] | 38 | This script requires ${ref_version} or greater\n"
|
---|
[cf829f0] | 39 | # Ask the user instead of bomb, to make happy that packages which version
|
---|
| 40 | # ouput don't follow our expectations
|
---|
[dda2496] | 41 | echo "If you are sure that you have installed a proper version of ${BOLD}$TXT${OFF}"
|
---|
[cf829f0] | 42 | echo "but jhalfs has failed to detect it, press 'c' and 'ENTER' keys to continue,"
|
---|
| 43 | echo -n "otherwise press 'ENTER' key to stop jhalfs. "
|
---|
| 44 | read ANSWER
|
---|
| 45 | if [ x$ANSWER != "xc" ] ; then
|
---|
| 46 | echo "${nl_}Please, install a proper $TXT version.${nl_}"
|
---|
| 47 | exit 1
|
---|
| 48 | else
|
---|
| 49 | minor=$ref_minor
|
---|
| 50 | revision=$ref_revision
|
---|
| 51 | fi
|
---|
[877cc6a] | 52 | }
|
---|
| 53 |
|
---|
[045b2dc] | 54 | echo -ne "${TXT}${dotSTR:${#TXT}} ${L_arrow}${BOLD}${tst_version}${OFF}${R_arrow}"
|
---|
| 55 |
|
---|
| 56 | # echo -ne "$TXT:\t${L_arrow}${BOLD}${tst_version}${OFF}${R_arrow}"
|
---|
[90bfb42e] | 57 | IFS=".-(pab" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
|
---|
[7072e1f] | 58 | set -- $ref_version # set positional parameters to minimum ver values
|
---|
[877cc6a] | 59 | ref_major=$1; ref_minor=$2; ref_revision=$3
|
---|
| 60 | #
|
---|
[7072e1f] | 61 | set -- $tst_version # Set positional parameters to test version values
|
---|
| 62 | # Values beginning with zero are taken as octal, so that for example
|
---|
| 63 | # 2.07.08 gives an error because 08 cannot be octal. The ## stuff supresses
|
---|
[0cc9d4e] | 64 | # leading zero's
|
---|
[7072e1f] | 65 | major=${1##*(0)}; minor=${2##*(0)}; revision=${3##*(0)}
|
---|
[877cc6a] | 66 | #
|
---|
| 67 | # Compare against minimum acceptable version..
|
---|
[1825286] | 68 | (( major > ref_major )) &&
|
---|
| 69 | echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
|
---|
| 70 | return
|
---|
[877cc6a] | 71 | (( major < ref_major )) && write_error_and_die
|
---|
| 72 | # major=ref_major
|
---|
| 73 | (( minor < ref_minor )) && write_error_and_die
|
---|
[1825286] | 74 | (( minor > ref_minor )) &&
|
---|
| 75 | echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
|
---|
| 76 | return
|
---|
[877cc6a] | 77 | # minor=ref_minor
|
---|
[1825286] | 78 | (( revision >= ref_revision )) &&
|
---|
| 79 | echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
|
---|
| 80 | return
|
---|
[877cc6a] | 81 |
|
---|
| 82 | # oops.. write error msg and die
|
---|
| 83 | write_error_and_die
|
---|
| 84 | }
|
---|
[045b2dc] | 85 | # local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
| 86 |
|
---|
| 87 | #----------------------------#
|
---|
| 88 | check_prerequisites() { #
|
---|
| 89 | #----------------------------#
|
---|
| 90 |
|
---|
[dda2496] | 91 | case $PROGNAME in
|
---|
| 92 | clfs | clfs2 | clfs3) HOSTREQS="BOOK/prologue/common/hostreqs.xml" ;;
|
---|
| 93 | *) HOSTREQS="prologue/hostreqs.xml" ;;
|
---|
| 94 | esac
|
---|
[27c5769] | 95 |
|
---|
| 96 | eval $(xsltproc $COMMON_DIR/hostreqs.xsl $BOOK/$HOSTREQS)
|
---|
[56e487e] | 97 | # Avoid translation of version strings
|
---|
| 98 | local LC_ALL=C
|
---|
| 99 | export LC_ALL
|
---|
| 100 |
|
---|
[045b2dc] | 101 | # LFS/HLFS/CLFS prerequisites
|
---|
[90bfb42e] | 102 | check_version "$MIN_Linux_VER" "`uname -r`" "KERNEL"
|
---|
[1825286] | 103 | check_version "$MIN_Bash_VER" "$BASH_VERSION" "BASH"
|
---|
[5e486cf] | 104 | if [ ! -z $MIN_GCC_VER ]; then
|
---|
| 105 | check_version "$MIN_GCC_VER" "`gcc -dumpversion`" "GCC"
|
---|
| 106 | check_version "$MIN_GCC_VER" "`g++ -dumpversion`" "G++"
|
---|
| 107 | elif [ ! -z $MIN_Gcc_VER ]; then
|
---|
| 108 | check_version "$MIN_Gcc_VER" "`gcc -dumpversion`" "GCC"
|
---|
| 109 | fi
|
---|
[1825286] | 110 | check_version "$MIN_Glibc_VER" "$(ldd --version | head -n1 | awk '{print $NF}')" "GLIBC"
|
---|
| 111 | check_version "$MIN_Binutils_VER" "$(ld --version | head -n1 | awk '{print $NF}')" "BINUTILS"
|
---|
| 112 | check_version "$MIN_Tar_VER" "$(tar --version | head -n1 | cut -d" " -f4)" "TAR"
|
---|
[a4af9217] | 113 | bzip2Ver="$(bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f8)"
|
---|
[1825286] | 114 | check_version "$MIN_Bzip2_VER" "${bzip2Ver%%,*}" "BZIP2"
|
---|
| 115 | check_version "$MIN_Bison_VER" "$(bison --version | head -n1 | cut -d" " -f4)" "BISON"
|
---|
| 116 | check_version "$MIN_Coreutils_VER" "$(chown --version | head -n1 | cut -d")" -f2)" "COREUTILS"
|
---|
| 117 | check_version "$MIN_Diffutils_VER" "$(diff --version | head -n1 | cut -d" " -f4)" "DIFF"
|
---|
| 118 | check_version "$MIN_Findutils_VER" "$(find --version | head -n1 | cut -d" " -f4)" "FIND"
|
---|
[8c48f24] | 119 | check_version "$MIN_Gawk_VER" "$(gawk --version | head -n1 | awk -F'[ ,]+' '{print $3}')" "GAWK"
|
---|
[1825286] | 120 | check_version "$MIN_Grep_VER" "$(grep --version | head -n1 | awk '{print $NF}')" "GREP"
|
---|
| 121 | check_version "$MIN_Gzip_VER" "$(gzip --version 2>&1 | head -n1 | cut -d" " -f2)" "GZIP"
|
---|
| 122 | check_version "$MIN_M4_VER" "$(m4 --version 2>&1 | head -n1 | awk '{print $NF}')" "M4"
|
---|
| 123 | check_version "$MIN_Make_VER" "$(make --version | head -n1 | cut -d " " -f3 | cut -c1-4)" "MAKE"
|
---|
| 124 | check_version "$MIN_Patch_VER" "$(patch --version | head -n1 | sed 's/.*patch //')" "PATCH"
|
---|
| 125 | check_version "$MIN_Perl_VER" "$(perl -V:version | cut -f2 -d\')" "PERL"
|
---|
| 126 | check_version "$MIN_Sed_VER" "$(sed --version | head -n1 | cut -d" " -f4)" "SED"
|
---|
| 127 | check_version "$MIN_Texinfo_VER" "$(makeinfo --version | head -n1 | awk '{ print$NF }')" "TEXINFO"
|
---|
| 128 | check_version "$MIN_Xz_VER" "$(xz --version | head -n1 | cut -d" " -f4)" "XZ"
|
---|
[dda2496] | 129 | }
|
---|
| 130 |
|
---|
| 131 | #----------------------------#
|
---|
| 132 | check_alfs_tools() { #
|
---|
| 133 | #----------------------------#
|
---|
| 134 | : << inline_doc
|
---|
| 135 | Those tools are needed for the proper operation of jhalfs
|
---|
| 136 | inline_doc
|
---|
| 137 |
|
---|
| 138 | # Avoid translation of version strings
|
---|
| 139 | local LC_ALL=C
|
---|
| 140 | export LC_ALL
|
---|
| 141 |
|
---|
[045b2dc] | 142 | # Check for minimum sudo version
|
---|
| 143 | SUDO_LOC="$(whereis -b sudo | cut -d" " -f2)"
|
---|
| 144 | if [ -x $SUDO_LOC ]; then
|
---|
| 145 | sudoVer="$(sudo -V | head -n1 | cut -d" " -f3)"
|
---|
[dda2496] | 146 | check_version "1.7.0" "${sudoVer}" "SUDO"
|
---|
[045b2dc] | 147 | else
|
---|
| 148 | echo "${nl_}\"${RED}sudo${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
|
---|
| 149 | exit 1
|
---|
| 150 | fi
|
---|
| 151 |
|
---|
[dda2496] | 152 | # Check for wget presence (using a dummy version)
|
---|
[960099f] | 153 | WGET_LOC="$(whereis -b wget | cut -d" " -f2)"
|
---|
| 154 | if [ -x $WGET_LOC ]; then
|
---|
| 155 | wgetVer="$(wget --version | head -n1 | cut -d" " -f3)"
|
---|
| 156 | check_version "1.0.0" "${wgetVer}" "WGET"
|
---|
| 157 | else
|
---|
| 158 | echo "${nl_}\"${RED}wget${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
|
---|
| 159 | exit 1
|
---|
| 160 | fi
|
---|
| 161 |
|
---|
[dda2496] | 162 | # Before checking libxml2 and libxslt version information, ensure tools
|
---|
| 163 | # needed from those packages are actually available. Avoids a small
|
---|
| 164 | # cosmetic bug of book version information not being retrieved if
|
---|
| 165 | # xmllint is unavailable, especially when on recent non-LFS hosts.
|
---|
[91d7db1] | 166 |
|
---|
| 167 | XMLLINT_LOC="$(whereis -b xmllint | cut -d" " -f2)"
|
---|
| 168 | XSLTPROC_LOC="$(whereis -b xsltproc | cut -d" " -f2)"
|
---|
| 169 |
|
---|
| 170 | if [ ! -x $XMLLINT_LOC ]; then
|
---|
| 171 | echo "${nl_}\"${RED}xmllint${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
|
---|
| 172 | exit 1
|
---|
| 173 | fi
|
---|
| 174 |
|
---|
| 175 | if [ -x $XSLTPROC_LOC ]; then
|
---|
| 176 |
|
---|
[dda2496] | 177 | # Check for minimum libxml2 and libxslt versions
|
---|
| 178 | xsltprocVer=$(xsltproc -V | head -n1 )
|
---|
| 179 | libxmlVer=$(echo $xsltprocVer | cut -d " " -f3)
|
---|
| 180 | libxsltVer=$(echo $xsltprocVer | cut -d " " -f5)
|
---|
[045b2dc] | 181 |
|
---|
[dda2496] | 182 | # Version numbers are packed strings not xx.yy.zz format.
|
---|
| 183 | check_version "2.06.20" "${libxmlVer:0:1}.${libxmlVer:1:2}.${libxmlVer:3:2}" "LIBXML2"
|
---|
| 184 | check_version "1.01.14" "${libxsltVer:0:1}.${libxsltVer:1:2}.${libxsltVer:3:2}" "LIBXSLT"
|
---|
[91d7db1] | 185 |
|
---|
| 186 | else
|
---|
| 187 | echo "${nl_}\"${RED}xsltproc${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
|
---|
| 188 | exit 1
|
---|
| 189 | fi
|
---|
[dda2496] | 190 | }
|
---|
[045b2dc] | 191 |
|
---|
[dda2496] | 192 | #----------------------------#
|
---|
| 193 | check_blfs_tools() { #
|
---|
| 194 | #----------------------------#
|
---|
| 195 | : << inline_doc
|
---|
| 196 | In addition to the tools needed for the LFS part, tidy and docbook-xml
|
---|
| 197 | are needed for installing the BLFS tools
|
---|
| 198 | inline_doc
|
---|
| 199 |
|
---|
| 200 | # Avoid translation of version strings
|
---|
| 201 | local LC_ALL=C
|
---|
| 202 | export LC_ALL
|
---|
| 203 |
|
---|
| 204 | tidyVer=$(tidy -V | cut -d " " -f9)
|
---|
| 205 | check_version "2004" "${tidyVer}" "TIDY"
|
---|
[045b2dc] | 206 |
|
---|
[dda2496] | 207 | # Minimal docbook-xml code for testing
|
---|
| 208 | XML_FILE="<?xml version='1.0' encoding='ISO-8859-1'?>
|
---|
[045b2dc] | 209 | <?xml-stylesheet type='text/xsl' href='http://docbook.sourceforge.net/release/xsl/1.69.1/xhtml/docbook.xsl'?>
|
---|
[16938b0] | 210 | <!DOCTYPE article PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN'
|
---|
| 211 | 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd'>
|
---|
[045b2dc] | 212 | <article>
|
---|
| 213 | <title>Test file</title>
|
---|
| 214 | <sect1>
|
---|
| 215 | <title>Some title</title>
|
---|
| 216 | <para>Some text</para>
|
---|
| 217 | </sect1>
|
---|
| 218 | </article>"
|
---|
| 219 |
|
---|
[dda2496] | 220 | if `echo $XML_FILE | xmllint -nonet -noout -postvalid - 2>/dev/null` ; then
|
---|
| 221 | check_version "4.5" "4.5" "DocBook XML DTD"
|
---|
| 222 | else
|
---|
| 223 | echo "Error: you need docbook for installing BLFS tools"
|
---|
| 224 | exit 2
|
---|
| 225 | fi
|
---|
[d4bbfe2] | 226 | }
|
---|