9 [ -n "$msg" ] && echo -e "\n${0##*/}: $msg" >&$STDOUT
22 # in a given directory, find the first rpm matching given requirements
29 pushd "$dir" > /dev/null || \
30 fatal 1 "Unable to chdir to directory \"$dir\" in find_rpm()"
33 for file in $(ls *.rpm); do
34 if [ ! -f "$file" ]; then
39 # match is any valid ERE (i.e. given to egrep) match
40 if rpm -q --provides -p "$file" 2>&$STDOUT | egrep "$match" >&$STDOUT; then
48 fatal 1 "Unknown match type \"$match_type\" given to find_rpm()"
59 local pathtorpms=${2:-"${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}/${TARGET_ARCH}"}
61 local kernel_rpms=$(find_linux_rpm "$prefix" "$pathtorpms")
62 # call a distro specific hook, if available
63 if type -p find_linux_rpms-$DISTRO; then
65 if rpm=$(find_linux_rpms-$DISTRO "$prefix" "$pathtorpms"); then
66 kernel_rpms="$kernel_rpms $rpm"
77 # a noop function which can be overridden by a distro method implementation
84 # XXX this needs to be re-written as a wrapper around find_rpm
85 # or just gotten rid of. :-)
88 local pathtorpms=${2:-"${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}/${TARGET_ARCH}"}
90 [ -d $pathtorpms ] || return 255
92 local kernelbinaryrpm rpmfile
93 local wanted_kernel="${lnxmaj}${lnxmin}-${lnxrel}"
96 local found_rpm="" rpm
97 for rpm in $(ls ${pathtorpms}/*.$(resolve_arch $TARGET_ARCH $PATCHLESS).rpm); do
98 if rpm -q --provides -p "$rpm" 2>&$STDOUT | grep -q "kernel${prefix} = $wanted_kernel" 2>&$STDOUT; then
105 # [ -f "$found_rpm" ] && break
113 # autodetect used Distro
114 autodetect_distro() {
119 if which lsb_release >/dev/null 2>&1; then
120 name="$(lsb_release -s -i)"
121 version="$(lsb_release -s -r)"
123 "EnterpriseEnterpriseServer")
125 version="${version%%.*}"
127 "RedHatEnterpriseServer" | "ScientificSL")
129 version="${version%%.*}"
135 fatal 1 "I don't know what distro name $name and version $version is.\nEither update autodetect_distro() or use the --distro argument."
139 echo "You really ought to install lsb_release for accurate distro identification"
140 # try some heuristics
141 if [ -f /etc/SuSE-release ]; then
143 version=$(grep ^VERSION /etc/SuSE-release)
144 version=${version#*= }
145 elif [ -f /etc/redhat-release ]; then
146 #name=$(head -1 /etc/redhat-release)
148 version=$(echo "$distroname" |
149 sed -e 's/^[^0-9.]*//g' | sed -e 's/[ \.].*//')
151 if [ -z "$name" -o -z "$version" ]; then
152 fatal 1 "I don't know how to determine distro type/version.\nEither update autodetect_distro() or use the --distro argument."
156 echo ${name}${version}
162 autodetect_target() {
167 oel5) target="2.6-oel5";;
168 rhel5) target="2.6-rhel5";;
169 sles10) target="2.6-sles10";;
170 sles11) target="2.6-sles11";;
171 *) fatal 1 "I don't know what distro $distro is.\nEither update autodetect_target() or use the --target argument.";;