Commit 211338ef authored by Konstantin Baev's avatar Konstantin Baev

- Remove kernel_src.list

- Remove distr_vendor - Code refactoring near finction.sh and buildmodule.sh - Add option 'testbuild' in rc-script and now able the command: service etercifs testbuild
parent 6c3ca180
...@@ -3,92 +3,41 @@ ...@@ -3,92 +3,41 @@
# Author: Vitaly Lipatov <lav@etersoft.ru> # Author: Vitaly Lipatov <lav@etersoft.ru>
# GNU Public License # GNU Public License
# modified: Konstantin Baev <kipruss@etersoft.ru>
# Build kernel module in installed system # Build kernel module in installed system
. ./functions.sh . ./functions.sh
MODULEFILENAME=etercifs.ko if [ $TESTBUILD -ne 1 ] ; then
[ -n "$KERNELVERSION" ] || KERNELVERSION=`uname -r` detect_host_kernel
KERNEL=`echo $KERNELVERSION | sed 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/'` echo
echo "Building for $KERNELVERSION Linux kernel (headers in $KERNSRC)"
get_src_dir || fatal "Distro $($DISTR_VENDOR -e) is not supported yet for kernel sources" compile_module
install_module
[ -n "`ls $ETERCIFS_SOURCES_LIST`" ] || fatal "Etercifs kernel module sources does not installed!"
KERNEL_SOURCE_ETERCIFS_LINK=`ls -1 $ETERCIFS_SOURCES_LIST | grep $KERNEL | sort -r | head -n 1`
KERNEL_SOURCE_ETERCIFS=`readlink -f $KERNEL_SOURCE_ETERCIFS_LINK`
[ "$KERNEL_SOURCE_ETERCIFS" ] || fatal "Etercifs kernel module sources for current kernel does not installed!"
tmpdir=
tmpdir="$(mktemp -dt "Etercifs.XXXXXXXX")"
# TODO: wonts independency of type archive
tar -xjf $KERNEL_SOURCE_ETERCIFS -C $tmpdir
trap exit_handler HUP PIPE INT QUIT TERM EXIT
FILENAME=`basename $KERNEL_SOURCE_ETERCIFS`
BUILDDIR=$tmpdir/${FILENAME%.tar.bz2}
# SMP build
[ -z "$RPM_BUILD_NCPUS" ] && RPM_BUILD_NCPUS=`/usr/bin/getconf _NPROCESSORS_ONLN`
[ "$RPM_BUILD_NCPUS" -gt 1 ] && MAKESMP="-j$RPM_BUILD_NCPUS" || MAKESMP=""
# source and destination directories can be inherited from the environment
if [ -z "$KERNSRC" ]; then
KERNSRC=/lib/modules/$KERNELVERSION/build
fi
if [ -z "$INSTALL_MOD_PATH" ]; then
INSTALL_MOD_PATH=/lib/modules/$KERNELVERSION/kernel/fs/cifs
fi
echo
echo "Build for $KERNELVERSION Linux kernel (headers in $KERNSRC)"
if [ ! -f $KERNSRC/include/linux/version.h ]; then
cat >&2 <<EOF
Error: no kernel headers found at $KERNSRC
Please install package
kernel-headers-modules-XXXX for ALT Linux
kernel-XXXX-devel for FCx / ASP Linux
dkms-linux-cifs for Mandriva 2008
linux-headers-XXXX for Debian / Ubuntu
kernel-source-XXXX for SuSe
kernel-source-XXXX for Slackware / MOPSLinux
or use KERNSRC variable to set correct location
Exiting...
EOF
exit 1
fi
# set GCC version if needed
if [ -f $KERNSRC/gcc_version.inc ] ; then
. $KERNSRC/gcc_version.inc
echo "We in $($DISTR_VENDOR -e), use GCC $GCC_VERSION"
export GCCNAME=gcc-$GCC_VERSION
export USEGCC="CC=$GCCNAME"
else else
export GCCNAME=gcc echo
fi echo "====================================================================="
echo "Check build etercifs module for all founded kernels"
if ! which $GCCNAME ; then BUILTLIST=
echo "GCC compiler have not found. Please install gcc package." for KERNSRC in `readlink /lib/modules/*/build` ; do
exit 1 echo "---------------------------------------------------------------------"
detect_kernel
if [ -z "$KERNELVERSION" ] ; then
echo "Can't detect kernel version in $KERNSRC"
else
echo "Build for $KERNSRC (detected as $KERNELVERSION)"
BUILTLIST="$BUILTLIST $KERNELVERSION"
compile_module
check_build_module
fi
done
echo "====================================================================="
echo "CIFS Linux kernel module built for follow kernels (marked as ---DONE):"
echo "---------------------------------------------------------------------"
for i in $BUILTLIST ; do echo " $i" ; done
echo "====================================================================="
fi fi
# Clean, build and check
rm -f $BUILDDIR/$MODULEFILENAME
make $USEGCC -C $KERNSRC here=$BUILDDIR SUBDIRS=$BUILDDIR clean
make $USEGCC -C $KERNSRC here=$BUILDDIR SUBDIRS=$BUILDDIR modules $MAKESMP
test -r "$BUILDDIR/$MODULEFILENAME" || { echo "can't locate built module $MODULEFILENAME, continue" ; exit 1 ; }
strip --strip-debug --discard-all $BUILDDIR/$MODULEFILENAME
echo "Copying built module to $INSTALL_MOD_PATH"
mkdir -p $INSTALL_MOD_PATH
install -m 644 -o root -g root $BUILDDIR/$MODULEFILENAME $INSTALL_MOD_PATH/ || exit 1
depmod -ae || exit 1
exit 0 exit 0
#!/bin/sh
# Author: Vitaly Lipatov <lav@etersoft.ru>
# 2007 (c) Etersoft
# 2007 Public domain
# Print the distro version
# Welcome to send updates!
# You can set ROOTDIR to your root dir
#ROOTDIR=
# TODO: /bin/lsb_release
# Check for DISTRO specific file in /etc
distro()
{
# fill global DISTROFILE
DISTROFILE="$ROOTDIR/etc/$1"
[ -f "$DISTROFILE" ]
}
# Has DISTRO file specified word?
has()
{
[ -n "$DISTROFILE" ] || exit 1
grep "$1" "$DISTROFILE" >/dev/null 2>&1
}
# Print DISTRIB_ID name in package manner
pkgvendor()
{
[ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return
[ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return
[ "$DISTRIB_ID" = "Mandriva" ] && echo "mdv" && return
echo "$DISTRIB_ID" | tr [A-Z] [a-z]
}
get_var()
{
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//"
}
# Set DISTRIB_ID
# default
DISTRIB_ID="Generic"
DISTRIB_RELEASE=""
if distro lsb-release ; then
DISTRIB_ID=`cat $DISTROFILE | get_var DISTRIB_ID`
DISTRIB_RELEASE=`cat $DISTROFILE | get_var DISTRIB_RELEASE`
fi
# ALT Linux based
if distro altlinux-release ; then
DISTRIB_ID="ALTLinux"
if has Strawberry ; then DISTRIB_RELEASE="2.3"
elif has Citron ; then DISTRIB_RELEASE="2.4"
elif has 20050723 ; then DISTRIB_RELEASE="3.0"
elif has Ajuga ; then DISTRIB_RELEASE="4.0"
elif has 20070810 ; then DISTRIB_RELEASE="4.0"
elif has Walnut ; then DISTRIB_RELEASE="4.0"
elif has Desktop ; then DISTRIB_RELEASE="4.0"
elif has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
fi
elif [ `uname` = "FreeBSD" ] ; then
DISTRIB_ID="FreeBSD"
if uname -a | grep 6.0-RELEASE >/dev/null ; then
DISTRIB_RELEASE=6.0
elif uname -a | grep 6.1-RELEASE >/dev/null ; then
DISTRIB_RELEASE=6.1
elif uname -a | grep 6.2-RELEASE >/dev/null ; then
DISTRIB_RELEASE=6.2
elif uname -a | grep 6.3-RELEASE >/dev/null ; then
DISTRIB_RELEASE=6.3
elif uname -a | grep 7.0-RELEASE >/dev/null ; then
DISTRIB_RELEASE=7.0
elif uname -a | grep 7.1-RELEASE >/dev/null ; then
DISTRIB_RELEASE=7.1
fi
elif distro gentoo-release ; then
DISTRIB_ID="Gentoo"
readlink $ROOTDIR/etc/make.profile | grep 2006.1 >/dev/null 2>&1 && DISTRIB_RELEASE="2006.1"
readlink $ROOTDIR/etc/make.profile | grep 2006.2 >/dev/null 2>&1 && DISTRIB_RELEASE="2006.2"
readlink $ROOTDIR/etc/make.profile | grep 2007.1 >/dev/null 2>&1 && DISTRIB_RELEASE="2007.1"
readlink $ROOTDIR/etc/make.profile | grep 2007.2 >/dev/null 2>&1 && DISTRIB_RELEASE="2007.2"
readlink $ROOTDIR/etc/make.profile | grep 2008.1 >/dev/null 2>&1 && DISTRIB_RELEASE="2008.1"
# Slackware based
elif distro mopslinux-version ; then
DISTRIB_ID="MOPSLinux"
if has 4.0 ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0"
elif has 5.1 ; then DISTRIB_RELEASE="5.1"
elif has 6.0 ; then DISTRIB_RELEASE="6.0"
elif has 6.1 ; then DISTRIB_RELEASE="6.1"
fi
elif distro slackware-version ; then
DISTRIB_ID="Slackware"
if has 10.2 ; then DISTRIB_RELEASE="10.2"
elif has 11 ; then DISTRIB_RELEASE="11"
elif has 11.1 ; then DISTRIB_RELEASE="11.1"
elif has 12 ; then DISTRIB_RELEASE="12"
fi
elif distro arch-release ; then
DISTRIB_ID="ArchLinux"
DISTRIB_RELEASE="2007"
# for Ubuntu use standard LSB info
elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB version
true
# Debian based
elif distro debian_version ; then
DISTRIB_ID="Debian"
DISTRIB_RELEASE=`cat $DISTROFILE`
# Mandriva based
elif distro pclinuxos-release ; then
DISTRIB_ID="PCLinux"
if has "2007" ; then DISTRIB_RELEASE="2007"
elif has "2008" ; then DISTRIB_RELEASE="2008"
fi
elif distro mandriva-release || distro mandrake-release ; then
DISTRIB_ID="Mandriva"
if has 2005 ; then DISTRIB_RELEASE="2005"
elif has 2006 ; then DISTRIB_RELEASE="2006"
elif has 2007 ; then DISTRIB_RELEASE="2007"
elif has 2008 ; then DISTRIB_RELEASE="2008"
fi
# make old as generic
#elif distro mandrake-release ; then
# DISTRIB_ID="Mandriva"
# Fedora based
elif distro linux-xp-release || distro lxp-release; then
DISTRIB_ID="LinuxXP"
if has "Attack of the Clones" ; then DISTRIB_RELEASE="2006"
elif has "2007" ; then DISTRIB_RELEASE="2007"
elif has "2008" ; then DISTRIB_RELEASE="2008"
fi
elif distro asplinux-release ; then
DISTRIB_ID="ASPLinux"
if has Karelia ; then DISTRIB_RELEASE="10"
elif has Seliger ; then DISTRIB_RELEASE="11"
elif has "11.1" ; then DISTRIB_RELEASE="11.1"
elif has Ladoga ; then DISTRIB_RELEASE="11.2"
elif has "11.2" ; then DISTRIB_RELEASE="11.2"
elif has "12" ; then DISTRIB_RELEASE="12"
fi
elif distro MCBC-release ; then
DISTRIB_ID="MCBC"
if has 3.0 ; then DISTRIB_RELEASE="3.0"
elif has 3.1 ; then DISTRIB_RELEASE="3.1"
fi
elif distro fedora-release ; then
DISTRIB_ID="Fedora"
if has Stentz ; then DISTRIB_RELEASE="4"
elif has Bordeaux ; then DISTRIB_RELEASE="5"
elif has Zod ; then DISTRIB_RELEASE="6"
elif has Moonshine ; then DISTRIB_RELEASE="7"
elif has Werewolf ; then DISTRIB_RELEASE="8"
elif has Sulphur ; then DISTRIB_RELEASE="9"
fi
elif distro redhat-release ; then
DISTRIB_ID="RHEL"
if has CentOS ; then
DISTRIB_ID="CentOS"
if has "release 4" ; then DISTRIB_RELEASE="4"
elif has "release 5" ; then DISTRIB_RELEASE="5"
fi
elif has Beryllium ; then
DISTRIB_ID="Scientific"
DISTRIB_RELEASE="4.1"
elif has Shrike ; then
DISTRIB_ID="RedHat"
DISTRIB_RELEASE="9"
elif has Taroon ; then DISTRIB_RELEASE="3"
elif has "release 4" ; then DISTRIB_RELEASE="4"
elif has "release 5" ; then DISTRIB_RELEASE="5"
fi
# SUSE based
elif distro SuSe-release || distro SuSE-release ; then
DISTRIB_ID="SUSE"
if has "Desktop 9" ; then
DISTRIB_ID="NLD"
DISTRIB_RELEASE="9"
elif has "10.1" ; then DISTRIB_RELEASE="10.1"
elif has "10.2" ; then DISTRIB_RELEASE="10.2"
elif has "10.3" ; then DISTRIB_RELEASE="10.3"
elif has "10.4" ; then DISTRIB_RELEASE="10.4"
elif has "10" ; then DISTRIB_RELEASE="10"
elif has "11.1" ; then DISTRIB_RELEASE="11.1"
elif has "11" ; then DISTRIB_RELEASE="11"
fi
# try use standart LSB info
elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB
true
fi
case $1 in
-p)
# overrider DISTRIB_ID
test -n "$2" && DISTRIB_ID="$2"
case `pkgvendor` in
freebsd) echo "pkg" ;;
slackware|mopslinux) echo "tgz" ;;
archlinux) echo "tar.gz" ;;
gentoo) echo "tbz2" ;;
debian|ubuntu) echo "deb" ;;
alt|asplinux|suse|madriva|mandrake|pclinux)
echo "rpm" ;;
fedora|redhat|scientific|centos|rhel)
echo "rpm" ;;
*) echo "rpm" ;;
esac
exit 0
;;
-h)
echo "-p print type of packaging system"
echo "-d print distro name"
echo "-v print version of distro"
echo "-e print full name of distro (with version)"
echo "-s print name of distro for build system"
echo "-h this help"
exit 0
;;
-d)
echo $DISTRIB_ID
;;
-v)
echo $DISTRIB_RELEASE
;;
-s)
pkgvendor
exit 0
;;
*)
[ -n "$DISTRIB_RELEASE" ] && echo $DISTRIB_ID/$DISTRIB_RELEASE || echo $DISTRIB_ID
;;
esac
...@@ -3,41 +3,171 @@ ...@@ -3,41 +3,171 @@
# Author: Vitaly Lipatov <lav@etersoft.ru> # Author: Vitaly Lipatov <lav@etersoft.ru>
# GNU Public License # GNU Public License
# modified: Konstantin Baev <kipruss@etersoft.ru>
# Build kernel modules for all kernel and all platforms # Build kernel modules for all kernel and all platforms
MODULEFILENAME=etercifs.ko
[ -n "$TESTBUILD" ] || TESTBUILD=0
fatal() fatal()
{ {
echo $@ echo $@
exit 1 exit 1
} }
DISTR_VENDOR=@DATADIR@/distr_vendor exit_handler()
{
local rc=$?
trap - EXIT
[ -z "$tmpdir" ] || rm -rf -- "$tmpdir"
exit $rc
}
test -x $DISTR_VENDOR || fatal "Can't find distr_vendor" detect_etercifs_sources()
{
[ -n "$ETERCIFS_SOURCES_LIST" ] || ETERCIFS_SOURCES_LIST=@DATADIR@/sources/kernel-source-etercifs*
[ -n "`ls $ETERCIFS_SOURCES_LIST`" ] || fatal "Etercifs kernel module sources does not installed!"
KERNEL_SOURCE_ETERCIFS_LINK=`ls -1 $ETERCIFS_SOURCES_LIST | grep $KERNEL | sort -r | head -n 1`
KERNEL_SOURCE_ETERCIFS=`readlink -f $KERNEL_SOURCE_ETERCIFS_LINK`
[ "$KERNEL_SOURCE_ETERCIFS" ] || fatal "Etercifs kernel module sources for current kernel does not installed!"
}
create_builddir()
{
tmpdir=
tmpdir="$(mktemp -dt "Etercifs.XXXXXXXX")"
ETERCIFS_SOURCES_LIST=@DATADIR@/sources/kernel-source-etercifs* tar -xjf $KERNEL_SOURCE_ETERCIFS -C $tmpdir
trap exit_handler HUP PIPE INT QUIT TERM EXIT
FILENAME=`basename $KERNEL_SOURCE_ETERCIFS`
BUILDDIR=$tmpdir/${FILENAME%.tar.bz2}
}
get_sd() kernel_release()
{ {
BASE_KERNEL_SOURCES_DIR= KERNEL=`echo $KERNELVERSION | sed 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/'`
BASE_KERNEL_SOURCES_DIR=`grep -i $1 kernel_src.list | head -n1 | cut -d" " -f 2 2>/dev/null`
} }
get_src_dir() # Heuristic
detect_kernel()
{ {
get_sd `$DISTR_VENDOR -e` # Detect kernel version
[ -z "$BASE_KERNEL_SOURCES_DIR" ] && get_sd `$DISTR_VENDOR -d` if [ -f $KERNSRC/.kernelrelease ] ; then
[ -z "$BASE_KERNEL_SOURCES_DIR" ] && { echo "Unknown `$DISTR_VENDOR -d`, use Generic for kernel sources" ; get_sd Generic ; } KERNELVERSION=`head -n 1 $KERNSRC/.kernelrelease`
[ -z "$BASE_KERNEL_SOURCES_DIR" ] && return 1 elif [ -f $KERNSRC/include/config/kernel.release ] ; then
return 0 KERNELVERSION=`head -n 1 $KERNSRC/include/config/kernel.release`
elif [ -f $KERNSRC/include/linux/version.h ] ; then
KERNELVERSION=`head -n 1 $KERNSRC/include/linux/version.h | grep UTS_RELEASE | cut -d" " -f 3 | sed -e 's|"||g'`
fi
if [ -z "$KERNELVERSION" ] ; then
head -n 5 $KERNSRC/Makefile | sed -e "s| ||g" >get_version
. ./get_version
KERNELVERSION=$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION
# Hack for strange SUSE 10.2
if [ -z "$EXTRAVERSION" ] ; then
KERNELVERSION=`grep KERNELSRC $KERNSRC/Makefile | head -n 1 | sed -e "s|.*linux-||g"`
[ -n "$KERNELVERSION" ] && KERNELVERSION=$KERNELVERSION-`basename $KERNSRC`
fi
fi
kernel_release
} }
exit_handler() detect_host_kernel()
{ {
local rc=$? [ -n "$KERNELVERSION" ] || KERNELVERSION=`uname -r`
trap - EXIT kernel_release
[ -z "$tmpdir" ] || rm -rf -- "$tmpdir"
exit $rc if [ -z "$KERNSRC" ]; then
KERNSRC=/lib/modules/$KERNELVERSION/build
fi
}
check_headers()
{
if [ ! -f $KERNSRC/include/linux/version.h ]; then
cat >&2 <<EOF
Error: no kernel headers found at $KERNSRC
Please install package
kernel-headers-modules-XXXX for ALT Linux
kernel-XXXX-devel for FCx / ASP Linux
dkms-linux-cifs for Mandriva 2008
linux-headers-XXXX for Debian / Ubuntu
kernel-source-XXXX for SuSe
kernel-source-XXXX for Slackware / MOPSLinux
or use KERNSRC variable to set correct location
Exiting...
EOF
exit 1
fi
}
set_gcc()
{
if [ -f $KERNSRC/gcc_version.inc ] ; then
. $KERNSRC/gcc_version.inc
if [ $TESTBUILD -ne 1 ] ; then
echo "Use GCC $GCC_VERSION"
fi
export GCCNAME=gcc-$GCC_VERSION
export USEGCC="CC=$GCCNAME"
else
export GCCNAME=gcc
fi
[ $TESTBUILD -eq 1 ] || echo `which $GCCNAME`
if ! which $GCCNAME &>/dev/null ; then
echo "GCC compiler have not found. Please install gcc package."
exit 1
fi
}
compile_module()
{
detect_etercifs_sources
create_builddir
check_headers
set_gcc
# SMP build
[ -z "$RPM_BUILD_NCPUS" ] && RPM_BUILD_NCPUS=`/usr/bin/getconf _NPROCESSORS_ONLN`
[ "$RPM_BUILD_NCPUS" -gt 1 ] && MAKESMP="-j$RPM_BUILD_NCPUS" || MAKESMP=""
# Clean, build and check
#rm -f $BUILDDIR/$MODULEFILENAME
if [ $TESTBUILD -eq 1 ] ; then
make $USEGCC -C $KERNSRC here=$BUILDDIR SUBDIRS=$BUILDDIR clean &>/dev/null
make $USEGCC -C $KERNSRC here=$BUILDDIR SUBDIRS=$BUILDDIR modules $MAKESMP &>/dev/null
else
make $USEGCC -C $KERNSRC here=$BUILDDIR SUBDIRS=$BUILDDIR clean
make $USEGCC -C $KERNSRC here=$BUILDDIR SUBDIRS=$BUILDDIR modules $MAKESMP
fi
}
install_module()
{
if [ -z "$INSTALL_MOD_PATH" ]; then
INSTALL_MOD_PATH=/lib/modules/$KERNELVERSION/kernel/fs/cifs
fi
test -r "$BUILDDIR/$MODULEFILENAME" || { echo "can't locate built module $MODULEFILENAME" ; exit 1 ; }
strip --strip-debug --discard-all $BUILDDIR/$MODULEFILENAME
echo "Copying built module to $INSTALL_MOD_PATH"
mkdir -p $INSTALL_MOD_PATH
install -m 644 -o root -g root $BUILDDIR/$MODULEFILENAME $INSTALL_MOD_PATH/ || exit 1
depmod -ae || exit 1
}
check_build_module()
{
if [ -r "$BUILDDIR/$MODULEFILENAME" ] ; then
echo "$KERNELVERSION - OK"
BUILTLIST="$BUILTLIST---DONE"
else
echo "can't locate built module $MODULEFILENAME"
echo "$KERNELVERSION - FAIL"
fi
} }
#/lib/modules/$(shell uname -r)/build
Generic /usr/src/*
ALTLinux /usr/src/*
ASPLinux /usr/src/kernels/*
ASPLinux/10 /lib/modules/*/build
RedHat /usr/src/kernels/*
RHEL /usr/src/kernels/*
CentOS /usr/src/kernels/*
LinuxXP /usr/src/kernels/*
Scientific /usr/src/kernels/*
FedoraCore /usr/src/kernels/*
Debian /usr/src/*
Ubuntu /usr/src/*
SUSE /usr/src/linux-*/*/*
NLD /usr/src/linux-*/*/*
MOPSLinux /usr/src/*
Slackware /usr/src/*
Mandriva /usr/src/*
Gentoo /usr/src/*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment