qla2x00t/extract-qla2xxx-orig: Use scripts/kernel-functions instead of duplicating it

git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/3.3.x@7589 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2018-11-01 04:42:26 +00:00
parent e3ca267824
commit 2c9b3a7d67

View File

@@ -1,84 +1,11 @@
#!/bin/bash
########################
# Function definitions #
########################
# First three components of the kernel version number.
function kernel_version {
echo "$1" | sed -n 's/^\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/p'
}
# Last component of the kernel version, or the empty string if $1 has only
# three components.
function patchlevel {
echo "$1" | sed -n 's/^\([0-9]*\.[0-9]*\.[0-9]*\)[.-]\(.*\)$/\2/p'
}
# Create a linux-$1 tree in the current directory, where $1 is a kernel
# version number with either three or four components.
function extract_kernel_tree {
local kver="$(kernel_version $1)"
local plevel="$(patchlevel $1)"
local tmpdir=kernel-tree-tmp-$$
rm -rf "linux-$1" "${tmpdir}"
mkdir "${tmpdir}" || return $?
(
cd "${tmpdir}" || return $?
tar xjf "${kernel_sources}/linux-${kver}.tar.bz2" || return $?
cd "linux-${kver}" || return $?
if [ "${plevel}" != "" ]; then
bzip2 -cd "${kernel_sources}/patch-$1.bz2" \
| patch -p1 -f -s || return $?
fi
cd ..
mv "linux-${kver}" "../linux-$1" || return $?
)
rmdir "${tmpdir}"
}
# Download the file from URL $1 and save it in the current directory.
function download_file {
if [ ! -e "$(basename "$1")" ]; then
if [ "${quiet_download}" = "false" ]; then
echo "Downloading $1 ..."
fi
if ! wget -q -nc "$1"; then
echo "Downloading $1 failed."
return 1
fi
fi
}
# Make sure the kernel tarball and patch file are present in directory
# ${kernel_sources}. Download any missing files from ${kernel_mirror}.
function download_kernel {
local kver="$(kernel_version $1)"
local plevel="$(patchlevel $1)"
mkdir -p "${kernel_sources}" || return $?
test -w "${kernel_sources}" || return $?
(
cd "${kernel_sources}" || return $?
download_file "${kernel_mirror}/linux-$(kernel_version $1).tar.bz2" \
|| return $?
if [ "${plevel}" != "" ]; then
download_file "${kernel_mirror}/patch-$1.bz2" || return $?
fi
)
}
source ../scripts/kernel-functions
#########################
# Argument verification #
#########################
# Where to store persistenly downloaded kernel tarballs and kernel patches.
kernel_sources="$HOME/software/downloads"
# URL for downloading kernel tarballs and kernel patches.
kernel_mirror="ftp://ftp.eu.kernel.org/pub/linux/kernel/v2.6"
kernel_version="$1"
if [ "$1" = "" ]; then
@@ -89,9 +16,9 @@ fi
mkdir -p qla2xxx-orig
cd qla2xxx-orig || exit $?
extract_kernel_tree "${kernel_version}"
touch linux-*/drivers/scsi/qla2xxx/*
touch "linux-${kernel_version}"/drivers/scsi/qla2xxx/*
rm -rf "${kernel_version}"
mkdir -p "${kernel_version}"
mv linux-*/drivers/scsi/qla2xxx/* "${kernel_version}"
rm -rf linux-*
mv "linux-${kernel_version}"/drivers/scsi/qla2xxx/* "${kernel_version}"
rm -rf "linux-${kernel_version}"
cd ..