From 77f6bac7ec9ea6daee34f00d64159e16790bd38f Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 10 Jul 2014 12:29:59 +0000 Subject: [PATCH] scripts/rebuild-rhel-kernel-rpm: Move code for downloading a RHEL (clone) RPM into a separate file git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@5672 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scripts/rebuild-rhel-kernel-rpm | 104 +++++++++++++++----------------- scripts/rhel-rpm-functions | 98 ++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 54 deletions(-) create mode 100644 scripts/rhel-rpm-functions diff --git a/scripts/rebuild-rhel-kernel-rpm b/scripts/rebuild-rhel-kernel-rpm index 88c93d16d..e34321fe3 100755 --- a/scripts/rebuild-rhel-kernel-rpm +++ b/scripts/rebuild-rhel-kernel-rpm @@ -36,63 +36,47 @@ # ############################################################################ -scst_dir="$(dirname "$(dirname "$0")")" -if [ ${scst_dir:0:1} != "/" ]; then - scst_dir="$PWD/${scst_dir}" +scriptdir="$(dirname "$0")" +if [ "${scriptdir:0:1}" != "/" ]; then + scriptdir="$PWD/${scriptdir}" fi +source "${scriptdir}/rhel-rpm-functions" +scst_dir="$(dirname "$scriptdir")" downloaddir=$HOME/software/downloads rpmbuild_dir=$HOME/rpmbuild -if [ "$1" = "" ]; then - if echo "$(uname -r)" | grep -q uek; then + +if echo "$(uname -r)" | grep -q uek; then kernel="kernel-uek-$(uname -r)" - else - kernel="kernel-$(uname -r)" - fi else - kernel="$1" + kernel="kernel-$(uname -r)" fi + +releasever="$(sed -n -e 's/^.* release \([0-9.]*\).*$/\1/p' /etc/issue)" + +distro="$(sed -n -e 's/^\(.*\) release .*$/\1/p' /etc/issue)" + +install_prerequisites=true + +type /usr/bin/getopt >/dev/null || exit 1 +options="$(/usr/bin/getopt d:ik:r: "$@")" || { usage; exit 1; } +set -- $options +while [ "$1" != "${1#-}" ]; do + case "$1" in + '-d') distro="$2"; shift; shift;; + '-i') install_prerequisites="false"; shift;; + '-k') kernel="$2"; shift; shift;; + '-r') releasever="$2"; shift; shift;; + '--') shift; break;; + *) usage; exit 1;; + esac +done + arch="$(uname -m)" kernel="${kernel%.${arch}}" kernel_src_rpm="${kernel}.src.rpm" kver="${kernel#kernel-}" -distro="$(sed -n -e 's/^\(.*\) release .*$/\1/p' /etc/issue)" -if [ -n "$2" ]; then - releasever="$2" -else - releasever="$(sed -n -e 's/^.* release \([0-9.]*\).*$/\1/p' /etc/issue)" -fi -releasevermajor="$(echo $releasever | cut -f1 -d.)" -releaseverminor="$(echo $releasever | cut -f2 -d.)" -case "$distro" in - "CentOS"*) - case $releasever in - 5.*|6.[01]) - srpm_url=("http://vault.centos.org/${releasever}/os/SRPMS" "http://vault.centos.org/${releasever}/updates/SRPMS");; - *) - srpm_url=("http://vault.centos.org/${releasever}/os/Source/SPackages" "http://vault.centos.org/${releasever}/updates/Source/SPackages");; - esac - ;; - "Red Hat Enterprise Linux"*) - srpm_url=("http://ftp.redhat.com/pub/redhat/linux/enterprise/${releasevermajor}Server/en/os/SRPMS") - ;; - "Oracle Linux Server") - srpm_url=("http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/${releaseverminor}/base/x86_64/getPackageSource" "http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/latest/x86_64/getPackageSource" "http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/UEK/latest/x86_64/getPackageSource") - ;; - "Scientific Linux") - if [ "$releasevermajor" = 6 ]; then - srpm_url=("http://ftp.scientificlinux.org/linux/scientific/$releasever/SRPMS/vendor") - else - srpm_url=("http://ftp.scientificlinux.org/linux/scientific/$releasevermajor$releaseverminor/SRPMS/vendor") - fi - ;; - "Fedora") - srpm_url="http://ftp.redhat.com/redhat/rhel/rc/7/Server/source/tree/Packages" - ;; - *) - echo "Unknown type of distribution: $distro" - exit 1 - ;; -esac + +srpm_urls="$(get_srpm_urls $distro $releasever $arch)" || exit $? function log { echo @@ -137,7 +121,9 @@ fi log "Installing prerequisites" -sudo yum install -y -q asciidoc binutils-devel elfutils-libelf-devel hmaccalc ncurses-devel newt-devel patchutils 'perl(ExtUtils::Embed)' python-devel redhat-rpm-config rpmdevtools rng-tools rpm-build unifdef xmlto yum-utils zlib-devel +if $install_prerequisites; then + sudo yum install -y -q asciidoc binutils-devel elfutils-libelf-devel hmaccalc ncurses-devel newt-devel patchutils 'perl(ExtUtils::Embed)' python-devel redhat-rpm-config rpmdevtools rng-tools rpm-build unifdef xmlto yum-utils zlib-devel +fi rc=$?; if [ $rc != 0 ]; then exit $rc; fi @@ -150,7 +136,7 @@ log "Installing, unpacking and preparing kernel source files" mkdir -p ${downloaddir} if [ ! -e ${downloaddir}/${kernel_src_rpm} ]; then cd ${downloaddir} - for dir in ${srpm_url[@]} + for dir in ${srpm_urls} do url="$dir/${kernel_src_rpm}" echo "Trying $url ..." @@ -166,7 +152,9 @@ fi log "Installing kernel build prerequisites" -sudo yum-builddep -q -y ${downloaddir}/${kernel_src_rpm} +if $install_prerequisites; then + sudo yum-builddep -q -y ${downloaddir}/${kernel_src_rpm} +fi log "Installing kernel sources in ${rpmbuild_dir}" @@ -186,10 +174,18 @@ log "Copying SCST patches to the SOURCES directory" cd ${rpmbuild_dir}/SOURCES copy_patch $scst_dir/scst/kernel/rhel/scst_exec_req_fifo-${kver}.patch scst_exec_req_fifo.patch -f="$scst_dir/iscsi-scst/kernel/patches/rhel/put_page_callback-${kver}.patch" -if [ -e "$f" ]; then - copy_patch "$f" put_page_callback.patch -fi +v="${kver}" +while [ "${v/.*}" != "$v" ]; do + f="$scst_dir/iscsi-scst/kernel/patches/rhel/put_page_callback-${v}.patch" + if [ -e "$f" ]; then + copy_patch "$f" put_page_callback.patch + break + fi + while [ "${v%[0-9a-z]}" != "$v" ]; do + v="${v%[0-9a-z]}" + done + v="${v%.}" +done log "Adding SCST patches in kernel.spec" diff --git a/scripts/rhel-rpm-functions b/scripts/rhel-rpm-functions new file mode 100644 index 000000000..285236d82 --- /dev/null +++ b/scripts/rhel-rpm-functions @@ -0,0 +1,98 @@ +# -*- mode: shell-script -*- +# Shell functions for downloading and extracting a RHEL or RHEL clone RPM + +# Arguments: +# $1: Linux distribution name +# $2: Linux distribution version (major.minor) +# $3: architecture +function get_srpm_urls() { + local arch distro releasever releasevermajor releaseverminor + + distro="$1" + releasever="$2" + arch="$3" + IFS=. + set -- "$2" + unset IFS + releasevermajor="$1" + releaseverminor="$2" + + case "$distro" in + "CentOS"*) + case $releasever in + 5.*|6.[01]) + echo "http://vault.centos.org/${releasever}/os/SRPMS http://vault.centos.org/${releasever}/updates/SRPMS";; + 6.*) + echo "http://vault.centos.org/${releasever}/os/Source/SPackages http://vault.centos.org/${releasever}/updates/Source/SPackages";; + esac + ;; + "Red Hat Enterprise Linux"*) + case $releasever in + [56].*) + echo "http://ftp.redhat.com/pub/redhat/linux/enterprise/${releasevermajor}Server/en/os/SRPMS http://ftp.redhat.com/redhat/rhel/rc/7/Server/source/tree/Packages";; + esac + ;; + "Oracle Linux Server") + echo "http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/${releaseverminor}/base/${arch}/getPackageSource http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/latest/${arch}/getPackageSource http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/UEK/latest/${arch}/getPackageSource" + ;; + "Scientific Linux") + case $releasever in + 5.*) + echo "http://ftp.scientificlinux.org/linux/scientific/$releasevermajor$releaseverminor/SRPMS/vendor";; + 6.*) + echo "http://ftp.scientificlinux.org/linux/scientific/$releasever/SRPMS/vendor";; + esac + ;; + *) + echo "Unknown type of distribution: $distro" >&2 + return 1 + ;; + esac +} + +# Arguments: +# $1: Linux distribution name +# $2: Linux distribution version (major.minor) +# $3: architecture +function get_rpm_urls() { + local arch distro releasever releasevermajor releaseverminor + + distro="$1" + releasever="$2" + arch="$3" + IFS=. + set -- "$2" + unset IFS + releasevermajor="$1" + releaseverminor="$2" + + case "$distro" in + "CentOS"*) + case $releasever in + 5.*) + echo "http://vault.centos.org/${releasever}/os/${arch}/CentOS http://vault.centos.org/${releasever}/updates/${arch}/RPMS";; + 6.[01]) + echo "http://vault.centos.org/${releasever}/os/${arch}/Packages http://vault.centos.org/${releasever}/updates/${arch}/Packages";; + 6.*) + echo "http://vault.centos.org/${releasever}/os/${arch}/Packages http://vault.centos.org/${releasever}/updates/${arch}/Packages";; + esac + ;; + "Red Hat Enterprise Linux"*) + echo "";; + "Oracle Linux Server") + echo "http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/${releaseverminor}/base/${arch}/getPackageSource http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/latest/${arch}/getPackageSource http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/UEK/latest/${arch}/getPackageSource" + ;; + "Scientific Linux") + case $releasever in + 5.*) + echo "http://ftp.scientificlinux.org/linux/scientific/$releasevermajor$releaseverminor/SRPMS/vendor";; + 6.*) + echo "http://ftp.scientificlinux.org/linux/scientific/$releasever/SRPMS/vendor";; + esac + ;; + *) + echo "Unknown distribution type: $distro" >&2 + return 1 + ;; + esac +}