source: common/libs/func_check_version.sh@ 1fc36f5

ablfs-more legacy trunk
Last change on this file since 1fc36f5 was fd4a798, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Remove $Id$ comments, they are useless with git

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