10 echo -e "\n${0##*/}: $msg" >&$STDOUT
21 # in a given directory, find the first rpm matching given requirements
28 pushd "$dir" > /dev/null || \
29 fatal 1 "Unable to chdir to directory \"$dir\" in find_rpm()"
32 for file in $(ls *.rpm); do
33 if [ ! -f "$file" ]; then
38 # match is any valid ERE (i.e. given to egrep) match
39 if rpm -q --provides -p "$file" 2>&$STDOUT | egrep "$match" >&$STDOUT; then
47 fatal 1 "Unknown match type \"$match_type\" given to find_rpm()"
58 local pathtorpms=${2:-"$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH"}
60 local wanted_kernel="${lnxmaj}${lnxmin}-${lnxrel}${rpmfix}"
61 local kernel_rpms=$(find_linux_rpm "$prefix" "$pathtorpms")
62 # call a distro specific hook, if available
63 if type -p find_linux_rpms-$DISTROMAJ; then
65 if rpm=$(find_linux_rpms-$DISTROMAJ "$prefix" "$wanted_kernel" "$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/$DISTROMAJ/$TARGET_ARCH"}
91 local wanted_kernel="${lnxmaj}${lnxmin}-${lnxrel}${rpmfix}"
93 if [ -d "$pathtorpms" ]; then
95 for rpm in $(ls ${pathtorpms}/*.$(resolve_arch $TARGET_ARCH $PATCHLESS).rpm); do
96 if rpm -q --provides -p "$rpm" 2>&$STDOUT | grep -q "kernel${prefix} = $wanted_kernel" 2>&$STDOUT; then
103 mkdir -p "$pathtorpms"
106 # [ -f "$found_rpm" ] && break
108 if [ -z "$found_rpm" ]; then
109 # see if there is a distro specific way of getting the RPM
110 if type -p find_linux_rpm-$DISTROMAJ; then
111 if found_rpm=$(find_linux_rpm-$DISTROMAJ "$prefix" "$wanted_kernel" "$pathtorpms"); then
112 found_rpm="${pathtorpms}/$found_rpm"
125 # autodetect used Distro
126 autodetect_distro() {
131 if which lsb_release >/dev/null 2>&1; then
132 name="$(lsb_release -s -i)"
133 version="$(lsb_release -s -r)"
135 "EnterpriseEnterpriseServer")
138 "RedHatEnterpriseServer" | "ScientificSL" | "CentOS")
141 "SUSE LINUX" | "SUSE")
144 *.*) # $version already has patchlevel
147 PATCHLEVEL=$(sed -n -e 's/^PATCHLEVEL = //p' /etc/SuSE-release)
148 if [ "$PATCHLEVEL" -ne "0" ]; then
149 version="${version}.$PATCHLEVEL"
158 fatal 1 "I don't know what distro name $name and version $version is.\nEither update autodetect_distro() or use the --distro argument."
162 error "You really ought to install lsb_release for accurate distro identification"
163 # try some heuristics
164 if [ -f /etc/SuSE-release ]; then
166 version=$(sed -n -e 's/^VERSION = //p' /etc/SuSE-release)
167 PATCHLEVEL=$(sed -n -e 's/^PATCHLEVEL = //p' /etc/SuSE-release)
168 if [ "$PATCHLEVEL" -ne "0" ]; then
169 version="${version}.$PATCHLEVEL"
171 elif [ -f /etc/redhat-release ]; then
172 #name=$(head -1 /etc/redhat-release)
174 version=$(echo "$distroname" |
175 sed -e 's/^[^0-9.]*//g' | sed -e 's/[ ].*//')
177 if [ -z "$name" -o -z "$version" ]; then
178 fatal 1 "I don't know how to determine distro type/version.\nEither update autodetect_distro() or use the --distro argument."
182 echo ${name}-${version}
188 autodetect_target() {
193 rhel7*) target="3.10-rhel7";;
194 rhel8*) target="4.18-rhel8";;
195 sles11.4) target="$(uname -r | cut -d . -f 1,2)-sles11sp4";;
196 sles11.3) target="$(uname -r | cut -d . -f 1,2)-sles11sp3";;
197 sles11*) target="$(uname -r | cut -d . -f 1,2)-sles11";;
198 sles12.5) target="$(uname -r | cut -d . -f 1,2)-sles12sp5";;
199 sles12.4) target="$(uname -r | cut -d . -f 1,2)-sles12sp4";;
200 sles12.3) target="$(uname -r | cut -d . -f 1,2)-sles12sp3";;
201 sles12*) target="$(uname -r | cut -d . -f 1,2)-sles12";;
202 sles15.1) target="$(uname -r | cut -d . -f 1,2)-sles15sp1";;
203 sles15.2) target="$(uname -r | cut -d . -f 1,2)-sles15sp2";;
204 sles15.3) target="$(uname -r | cut -d . -f 1,2)-sles15sp3";;
205 fc18) target="3.x-fc18";;
206 *) fatal 1 "I don't know what distro $distro is.\nEither update autodetect_target() or use the --target argument.";;