source: common/libs/func_check_version.sh@ de84c00

2.4 ablfs-more legacy new_features trunk
Last change on this file since de84c00 was 92b7cb8, checked in by Pierre Labastie <pierre@…>, 11 years ago

Allows to use git for downloading the CLFS book
Adds .lzma as a possible extension for a tarball in urls.xsl

  • Property mode set to 100644
File size: 8.9 KB
Line 
1# $Id$
2
3check_version() {
4: <<inline_doc
5 Tests for a minimum version level. Compares to version numbers and forces an
6 exit if minimum level not met.
7 NOTE: This test will fail on versions containing alpha chars. ie. jpeg 6b
8
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
25 declare -r spaceSTR=" "
26
27 shopt -s extglob #needed for ${x##*(0)} below
28
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() {
37 echo -e "\n\t\t$TXT version -->${tst_version}<-- is too old.
38 This script requires ${ref_version} or greater\n"
39 # Ask the user instead of bomb, to make happy that packages which version
40 # ouput don't follow our expectations
41 echo "If you are sure that you have instaled a proper version of ${BOLD}$TXT${OFF}"
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
52 }
53
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}"
57 IFS=".-(pa" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
58 set -- $ref_version # set positional parameters to minimum ver values
59 ref_major=$1; ref_minor=$2; ref_revision=$3
60 #
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
64 # leading zero's
65 major=${1##*(0)}; minor=${2##*(0)}; revision=${3##*(0)}
66 #
67 # Compare against minimum acceptable version..
68 (( major > ref_major )) &&
69 echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
70 return
71 (( major < ref_major )) && write_error_and_die
72 # major=ref_major
73 (( minor < ref_minor )) && write_error_and_die
74 (( minor > ref_minor )) &&
75 echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
76 return
77 # minor=ref_minor
78 (( revision >= ref_revision )) &&
79 echo " ${spaceSTR:${#tst_version}}${GREEN}OK${OFF} (Min version: ${ref_version})" &&
80 return
81
82 # oops.. write error msg and die
83 write_error_and_die
84}
85# local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
86
87#----------------------------#
88check_prerequisites() { #
89#----------------------------#
90
91 # Maybe we should check xsltproc first?
92 case $PROGNAME in
93 clfs | clfs2 | clfs3) HOSTREQS="BOOK/prologue/common/hostreqs.xml" ;;
94 *) HOSTREQS="prologue/hostreqs.xml" ;;
95 esac
96
97 eval $(xsltproc $COMMON_DIR/hostreqs.xsl $BOOK/$HOSTREQS)
98 # Avoid translation of version strings
99 local LC_ALL=C
100 export LC_ALL
101
102 # LFS/HLFS/CLFS prerequisites
103 check_version "$MIN_Kernel_VER" "`uname -r`" "KERNEL"
104 check_version "$MIN_Bash_VER" "$BASH_VERSION" "BASH"
105 if [ ! -z $MIN_GCC_VER ]; then
106 check_version "$MIN_GCC_VER" "`gcc -dumpversion`" "GCC"
107 check_version "$MIN_GCC_VER" "`g++ -dumpversion`" "G++"
108 elif [ ! -z $MIN_Gcc_VER ]; then
109 check_version "$MIN_Gcc_VER" "`gcc -dumpversion`" "GCC"
110 fi
111 check_version "$MIN_Glibc_VER" "$(ldd --version | head -n1 | awk '{print $NF}')" "GLIBC"
112 check_version "$MIN_Binutils_VER" "$(ld --version | head -n1 | awk '{print $NF}')" "BINUTILS"
113 check_version "$MIN_Tar_VER" "$(tar --version | head -n1 | cut -d" " -f4)" "TAR"
114 bzip2Ver="$(bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f8)"
115 check_version "$MIN_Bzip2_VER" "${bzip2Ver%%,*}" "BZIP2"
116 check_version "$MIN_Bison_VER" "$(bison --version | head -n1 | cut -d" " -f4)" "BISON"
117 check_version "$MIN_Coreutils_VER" "$(chown --version | head -n1 | cut -d")" -f2)" "COREUTILS"
118 check_version "$MIN_Diffutils_VER" "$(diff --version | head -n1 | cut -d" " -f4)" "DIFF"
119 check_version "$MIN_Findutils_VER" "$(find --version | head -n1 | cut -d" " -f4)" "FIND"
120 check_version "$MIN_Gawk_VER" "$(gawk --version | head -n1 | awk -F'[ ,]+' '{print $3}')" "GAWK"
121 check_version "$MIN_Grep_VER" "$(grep --version | head -n1 | awk '{print $NF}')" "GREP"
122 check_version "$MIN_Gzip_VER" "$(gzip --version 2>&1 | head -n1 | cut -d" " -f2)" "GZIP"
123 check_version "$MIN_M4_VER" "$(m4 --version 2>&1 | head -n1 | awk '{print $NF}')" "M4"
124 check_version "$MIN_Make_VER" "$(make --version | head -n1 | cut -d " " -f3 | cut -c1-4)" "MAKE"
125 check_version "$MIN_Patch_VER" "$(patch --version | head -n1 | sed 's/.*patch //')" "PATCH"
126 check_version "$MIN_Perl_VER" "$(perl -V:version | cut -f2 -d\')" "PERL"
127 check_version "$MIN_Sed_VER" "$(sed --version | head -n1 | cut -d" " -f4)" "SED"
128 check_version "$MIN_Texinfo_VER" "$(makeinfo --version | head -n1 | awk '{ print$NF }')" "TEXINFO"
129 check_version "$MIN_Xz_VER" "$(xz --version | head -n1 | cut -d" " -f4)" "XZ"
130 # Check for minimum sudo version
131 SUDO_LOC="$(whereis -b sudo | cut -d" " -f2)"
132 if [ -x $SUDO_LOC ]; then
133 sudoVer="$(sudo -V | head -n1 | cut -d" " -f3)"
134 check_version "1.7.0" "${sudoVer}" "SUDO"
135 else
136 echo "${nl_}\"${RED}sudo${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
137 exit 1
138 fi
139
140 # Check for minimum wget version
141 WGET_LOC="$(whereis -b wget | cut -d" " -f2)"
142 if [ -x $WGET_LOC ]; then
143 wgetVer="$(wget --version | head -n1 | cut -d" " -f3)"
144 check_version "1.0.0" "${wgetVer}" "WGET"
145 else
146 echo "${nl_}\"${RED}wget${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
147 exit 1
148 fi
149
150 # Before checking libmxl2 and libxslt version information, ensure tools needed from those
151 # packages are actually available. Avoids a small cosmetic bug of book version information
152 # not being retrieved if xmllint is unavailable, especially when on recent non-LFS hosts.
153
154 XMLLINT_LOC="$(whereis -b xmllint | cut -d" " -f2)"
155 XSLTPROC_LOC="$(whereis -b xsltproc | cut -d" " -f2)"
156 XML_NOTE_MSG="${nl_} ${BOLD} This can happen when running jhalfs on non-LFS hosts. ${OFF}"
157
158 if [ ! -x $XMLLINT_LOC ]; then
159 echo "${nl_}\"${RED}xmllint${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
160 echo ${XML_NOTE_MSG}
161 exit 1
162 fi
163
164 if [ -x $XSLTPROC_LOC ]; then
165
166 # Check for minimum libxml2 and libxslt versions
167 xsltprocVer=$(xsltproc -V | head -n1 )
168 libxmlVer=$(echo $xsltprocVer | cut -d " " -f3)
169 libxsltVer=$(echo $xsltprocVer | cut -d " " -f5)
170
171 # Version numbers are packed strings not xx.yy.zz format.
172 check_version "2.06.20" "${libxmlVer:0:1}.${libxmlVer:1:2}.${libxmlVer:3:2}" "LIBXML2"
173 check_version "1.01.14" "${libxsltVer:0:1}.${libxsltVer:1:2}.${libxsltVer:3:2}" "LIBXSLT"
174
175 else
176 echo "${nl_}\"${RED}xsltproc${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
177 echo ${XML_NOTE_MSG}
178 exit 1
179 fi
180 # The next versions checks are required only when BLFS_TOOL is set and
181 # this dependencies has not be selected for installation
182 if [[ "$BLFS_TOOL" = "y" ]] ; then
183
184 if [[ -z "$DEP_TIDY" ]] ; then
185 tidyVer=$(tidy -V | cut -d " " -f9)
186 check_version "2004" "${tidyVer}" "TIDY"
187 fi
188
189 # Check if the proper DocBook-XML-DTD and DocBook-XSL are correctly installed
190XML_FILE="<?xml version='1.0' encoding='ISO-8859-1'?>
191<?xml-stylesheet type='text/xsl' href='http://docbook.sourceforge.net/release/xsl/1.69.1/xhtml/docbook.xsl'?>
192<!DOCTYPE article PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN'
193 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd'>
194<article>
195 <title>Test file</title>
196 <sect1>
197 <title>Some title</title>
198 <para>Some text</para>
199 </sect1>
200</article>"
201
202 if [[ -z "$DEP_DBXML" ]] ; then
203 if `echo $XML_FILE | xmllint -noout -postvalid - 2>/dev/null` ; then
204 check_version "4.5" "4.5" "DocBook XML DTD"
205 else
206 echo "Warning: not found a working DocBook XML DTD 4.5 installation"
207 exit 2
208 fi
209 fi
210
211# if [[ -z "$DEP_DBXSL" ]] ; then
212# if `echo $XML_FILE | xsltproc --noout - 2>/dev/null` ; then
213# check_version "1.69.1" "1.69.1" "DocBook XSL"
214# else
215# echo "Warning: not found a working DocBook XSL 1.69.1 installation"
216# exit 2
217# fi
218# fi
219
220 fi # end BLFS_TOOL=Y
221
222}
Note: See TracBrowser for help on using the repository browser.