source: common/libs/func_check_version.sh@ 106157fd

ablfs-more legacy trunk
Last change on this file since 106157fd was 72e9e68, checked in by Pierre Labastie <pierre@…>, 6 years ago

Fix a long standing bug in func_check_version.sh:
Using the non existent dotSTR variable caused a ragged output.
Use the spaceSTR variable rather

  • Property mode set to 100644
File size: 9.5 KB
RevLine 
[877cc6a]1# $Id$
2
3check_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
21inline_doc
22
23 declare -i major minor revision change
24 declare -i ref_major ref_minor ref_revision ref_change
[1cf621b]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() {
[6ed3dd7]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
[6ed3dd7]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
[72e9e68]54 echo -ne "${TXT}${spaceSTR:${#TXT}} ${L_arrow}${BOLD}${tst_version}${OFF}${R_arrow}"
[045b2dc]55
[b86876a]56 IFS=".-(pab" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
[7072e1f]57 set -- $ref_version # set positional parameters to minimum ver values
[877cc6a]58 ref_major=$1; ref_minor=$2; ref_revision=$3
59 #
[7072e1f]60 set -- $tst_version # Set positional parameters to test version values
61 # Values beginning with zero are taken as octal, so that for example
62 # 2.07.08 gives an error because 08 cannot be octal. The ## stuff supresses
[48acdd4]63 # leading zero's
[7072e1f]64 major=${1##*(0)}; minor=${2##*(0)}; revision=${3##*(0)}
[877cc6a]65 #
66 # Compare against minimum acceptable version..
[1cf621b]67 (( major > ref_major )) &&
68 echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
69 return
[877cc6a]70 (( major < ref_major )) && write_error_and_die
71 # major=ref_major
72 (( minor < ref_minor )) && write_error_and_die
[1cf621b]73 (( minor > ref_minor )) &&
74 echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
75 return
[877cc6a]76 # minor=ref_minor
[1cf621b]77 (( revision >= ref_revision )) &&
78 echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
79 return
[877cc6a]80
81 # oops.. write error msg and die
82 write_error_and_die
83}
[045b2dc]84
85#----------------------------#
86check_prerequisites() { #
87#----------------------------#
88
[061d54f]89 HOSTREQS=$(find $BOOK -name hostreqs.xml)
[92b7cb8]90
[061d54f]91 eval $(xsltproc $COMMON_DIR/hostreqs.xsl $HOSTREQS)
[56e487e]92 # Avoid translation of version strings
93 local LC_ALL=C
94 export LC_ALL
95
[045b2dc]96 # LFS/HLFS/CLFS prerequisites
[94744cd]97 if [ -n "$MIN_Linux_VER" ]; then
98 check_version "$MIN_Linux_VER" "`uname -r`" "KERNEL"
99 fi
100 if [ -n "$MIN_Bash_VER" ]; then
101 check_version "$MIN_Bash_VER" "$BASH_VERSION" "BASH"
102 fi
[0f92d7f]103 if [ ! -z $MIN_GCC_VER ]; then
[49ba78d]104 check_version "$MIN_GCC_VER" "`gcc -dumpfullversion -dumpversion`" "GCC"
105 check_version "$MIN_GCC_VER" "`g++ -dumpfullversion -dumpversion`" "G++"
[0f92d7f]106 elif [ ! -z $MIN_Gcc_VER ]; then
[49ba78d]107 check_version "$MIN_Gcc_VER" "`gcc -dumpfullversion -dumpversion`" "GCC"
[0f92d7f]108 fi
[94744cd]109 if [ -n "$MIN_Glibc_VER" ]; then
110 check_version "$MIN_Glibc_VER" "$(ldd --version | head -n1 | awk '{print $NF}')" "GLIBC"
111 fi
112 if [ -n "$MIN_Binutils_VER" ]; then
113 check_version "$MIN_Binutils_VER" "$(ld --version | head -n1 | awk '{print $NF}')" "BINUTILS"
114 fi
115 if [ -n "$MIN_Tar_VER" ]; then
116 check_version "$MIN_Tar_VER" "$(tar --version | head -n1 | cut -d" " -f4)" "TAR"
117 fi
118 if [ -n "$MIN_Bzip2_VER" ]; then
[a4af9217]119 bzip2Ver="$(bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f8)"
[94744cd]120 check_version "$MIN_Bzip2_VER" "${bzip2Ver%%,*}" "BZIP2"
121 fi
122 if [ -n "$MIN_Bison_VER" ]; then
123 check_version "$MIN_Bison_VER" "$(bison --version | head -n1 | cut -d" " -f4)" "BISON"
124 fi
125 if [ -n "$MIN_Coreutils_VER" ]; then
126 check_version "$MIN_Coreutils_VER" "$(chown --version | head -n1 | cut -d" " -f4)" "COREUTILS"
127 fi
128 if [ -n "$MIN_Diffutils_VER" ]; then
129 check_version "$MIN_Diffutils_VER" "$(diff --version | head -n1 | cut -d" " -f4)" "DIFF"
130 fi
131 if [ -n "$MIN_Findutils_VER" ]; then
132 check_version "$MIN_Findutils_VER" "$(find --version | head -n1 | cut -d" " -f4)" "FIND"
133 fi
134 if [ -n "$MIN_Gawk_VER" ]; then
135 check_version "$MIN_Gawk_VER" "$(gawk --version | head -n1 | awk -F'[ ,]+' '{print $3}')" "GAWK"
136 fi
137 if [ -n "$MIN_Grep_VER" ]; then
138 check_version "$MIN_Grep_VER" "$(grep --version | head -n1 | awk '{print $NF}')" "GREP"
139 fi
140 if [ -n "$MIN_Gzip_VER" ]; then
141 check_version "$MIN_Gzip_VER" "$(gzip --version 2>&1 | head -n1 | cut -d" " -f2)" "GZIP"
142 fi
143 if [ -n "$MIN_M4_VER" ]; then
144 check_version "$MIN_M4_VER" "$(m4 --version 2>&1 | head -n1 | awk '{print $NF}')" "M4"
145 fi
146 if [ -n "$MIN_Make_VER" ]; then
147 check_version "$MIN_Make_VER" "$(make --version | head -n1 | cut -d " " -f3 | cut -c1-4)" "MAKE"
148 fi
149 if [ -n "$MIN_Patch_VER" ]; then
150 check_version "$MIN_Patch_VER" "$(patch --version | head -n1 | sed 's/.*patch //')" "PATCH"
151 fi
152 if [ -n "$MIN_Perl_VER" ]; then
153 check_version "$MIN_Perl_VER" "$(perl -V:version | cut -f2 -d\')" "PERL"
154 fi
155 if [ -n "$MIN_Sed_VER" ]; then
156 check_version "$MIN_Sed_VER" "$(sed --version | head -n1 | cut -d" " -f4)" "SED"
157 fi
158 if [ -n "$MIN_Texinfo_VER" ]; then
159 check_version "$MIN_Texinfo_VER" "$(makeinfo --version | head -n1 | awk '{ print$NF }')" "TEXINFO"
160 fi
161 if [ -n "$MIN_Xz_VER" ]; then
162 check_version "$MIN_Xz_VER" "$(xz --version | head -n1 | cut -d" " -f4)" "XZ"
163 fi
[7a82194]164 if [ -n "$MIN_Python_VER" ]; then
[399058f]165 check_version "$MIN_Python_VER" "3.$(python3 -c"import sys; print(sys.version_info.minor,'.',sys.version_info.micro,sep='')")" "PYTHON"
[7a82194]166 fi
[6ed3dd7]167}
168
169#----------------------------#
170check_alfs_tools() { #
171#----------------------------#
172: << inline_doc
173Those tools are needed for the proper operation of jhalfs
174inline_doc
175
176 # Avoid translation of version strings
177 local LC_ALL=C
178 export LC_ALL
179
[045b2dc]180 # Check for minimum sudo version
181 SUDO_LOC="$(whereis -b sudo | cut -d" " -f2)"
182 if [ -x $SUDO_LOC ]; then
183 sudoVer="$(sudo -V | head -n1 | cut -d" " -f3)"
[6ed3dd7]184 check_version "1.7.0" "${sudoVer}" "SUDO"
[045b2dc]185 else
186 echo "${nl_}\"${RED}sudo${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
187 exit 1
188 fi
189
[6ed3dd7]190 # Check for wget presence (using a dummy version)
[4f700a9]191 WGET_LOC="$(whereis -b wget | cut -d" " -f2)"
192 if [ -x $WGET_LOC ]; then
193 wgetVer="$(wget --version | head -n1 | cut -d" " -f3)"
[2af991d]194 if echo "$wgetVer" | grep -q '^[[:digit:]]'; then
195 check_version "1.0.0" "${wgetVer}" "WGET"
196 else echo Wget detected, but no version found. Continuing anyway.
197 fi
[4f700a9]198 else
199 echo "${nl_}\"${RED}wget${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
200 exit 1
201 fi
202
[6ed3dd7]203 # Before checking libxml2 and libxslt version information, ensure tools
204 # needed from those packages are actually available. Avoids a small
205 # cosmetic bug of book version information not being retrieved if
206 # xmllint is unavailable, especially when on recent non-LFS hosts.
[f445e26]207
208 XMLLINT_LOC="$(whereis -b xmllint | cut -d" " -f2)"
209 XSLTPROC_LOC="$(whereis -b xsltproc | cut -d" " -f2)"
[2e1c1c3]210
[f445e26]211 if [ ! -x $XMLLINT_LOC ]; then
212 echo "${nl_}\"${RED}xmllint${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
213 exit 1
214 fi
215
216 if [ -x $XSLTPROC_LOC ]; then
217
[6ed3dd7]218 # Check for minimum libxml2 and libxslt versions
219 xsltprocVer=$(xsltproc -V | head -n1 )
220 libxmlVer=$(echo $xsltprocVer | cut -d " " -f3)
221 libxsltVer=$(echo $xsltprocVer | cut -d " " -f5)
[045b2dc]222
[6ed3dd7]223 # Version numbers are packed strings not xx.yy.zz format.
224 check_version "2.06.20" "${libxmlVer:0:1}.${libxmlVer:1:2}.${libxmlVer:3:2}" "LIBXML2"
225 check_version "1.01.14" "${libxsltVer:0:1}.${libxsltVer:1:2}.${libxsltVer:3:2}" "LIBXSLT"
[2e1c1c3]226
[f445e26]227 else
228 echo "${nl_}\"${RED}xsltproc${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
229 exit 1
230 fi
[6ed3dd7]231}
[045b2dc]232
[6ed3dd7]233#----------------------------#
234check_blfs_tools() { #
235#----------------------------#
236: << inline_doc
[78d4779]237In addition to the tools needed for the LFS part, docbook-xml
238is needed for installing the BLFS tools
[6ed3dd7]239inline_doc
240
241 # Avoid translation of version strings
242 local LC_ALL=C
243 export LC_ALL
244
245 # Minimal docbook-xml code for testing
246 XML_FILE="<?xml version='1.0' encoding='ISO-8859-1'?>
[045b2dc]247<?xml-stylesheet type='text/xsl' href='http://docbook.sourceforge.net/release/xsl/1.69.1/xhtml/docbook.xsl'?>
[16938b0]248<!DOCTYPE article PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN'
249 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd'>
[045b2dc]250<article>
251 <title>Test file</title>
252 <sect1>
253 <title>Some title</title>
254 <para>Some text</para>
255 </sect1>
256</article>"
257
[6ed3dd7]258 if `echo $XML_FILE | xmllint -nonet -noout -postvalid - 2>/dev/null` ; then
259 check_version "4.5" "4.5" "DocBook XML DTD"
260 else
[2270ffd]261 echo "Error: you need the Docbook XML DTD for installing BLFS tools"
[6ed3dd7]262 exit 2
263 fi
[d4bbfe2]264}
Note: See TracBrowser for help on using the repository browser.