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 wanted_kernel="${lnxmaj}${lnxmin}-${lnxrel}"
62 local kernel_rpms=$(find_linux_rpm "$prefix" "$pathtorpms")
63 # call a distro specific hook, if available
64 if type -p find_linux_rpms-$DISTRO; then
66 if rpm=$(find_linux_rpms-$DISTRO "$prefix" "$wanted_kernel" "$pathtorpms"); then
67 kernel_rpms="$kernel_rpms $rpm"
78 # a noop function which can be overridden by a distro method implementation
85 # XXX this needs to be re-written as a wrapper around find_rpm
86 # or just gotten rid of. :-)
89 local pathtorpms=${2:-"${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}/${TARGET_ARCH}"}
92 local wanted_kernel="${lnxmaj}${lnxmin}-${lnxrel}"
94 if [ -d "$pathtorpms" ]; then
96 for rpm in $(ls ${pathtorpms}/*.$(resolve_arch $TARGET_ARCH $PATCHLESS).rpm); do
97 if rpm -q --provides -p "$rpm" 2>&$STDOUT | grep -q "kernel${prefix} = $wanted_kernel" 2>&$STDOUT; then
104 mkdir -p "$pathtorpms"
107 # [ -f "$found_rpm" ] && break
109 if [ -z "$found_rpm" ]; then
110 # see if there is a distro specific way of getting the RPM
111 if type -p find_linux_rpm-$DISTRO; then
112 if found_rpm=$(find_linux_rpm-$DISTRO "$prefix" "$wanted_kernel" "$pathtorpms"); then
113 found_rpm="${pathtorpms}/$found_rpm"
126 # autodetect used Distro
127 autodetect_distro() {
132 if which lsb_release >/dev/null 2>&1; then
133 name="$(lsb_release -s -i)"
134 version="$(lsb_release -s -r)"
136 "EnterpriseEnterpriseServer")
138 version="${version%%.*}"
140 "RedHatEnterpriseServer" | "ScientificSL" | "CentOS")
142 version="${version%%.*}"
148 fatal 1 "I don't know what distro name $name and version $version is.\nEither update autodetect_distro() or use the --distro argument."
152 echo "You really ought to install lsb_release for accurate distro identification"
153 # try some heuristics
154 if [ -f /etc/SuSE-release ]; then
156 version=$(grep ^VERSION /etc/SuSE-release)
157 version=${version#*= }
158 elif [ -f /etc/redhat-release ]; then
159 #name=$(head -1 /etc/redhat-release)
161 version=$(echo "$distroname" |
162 sed -e 's/^[^0-9.]*//g' | sed -e 's/[ \.].*//')
164 if [ -z "$name" -o -z "$version" ]; then
165 fatal 1 "I don't know how to determine distro type/version.\nEither update autodetect_distro() or use the --distro argument."
169 echo ${name}${version}
175 autodetect_target() {
180 oel5) target="2.6-oel5";;
181 rhel5) target="2.6-rhel5";;
182 rhel6) target="2.6-rhel6";;
183 sles10) target="2.6-sles10";;
184 sles11) target="2.6-sles11";;
185 *) fatal 1 "I don't know what distro $distro is.\nEither update autodetect_target() or use the --target argument.";;