===== npreal2.spec =====
# This is a spec file for the MOXA Linux Real TTY Driver
%define kernel 2.6.18-194.8.1.el5
%define _topdir /root/moxa-rpm
%define name npreal2
%define release 2.6.18_194.8.1.el5
%define version 1.16
%define buildroot %{_topdir}/%{name}-%{version}-root
%define NPPATH /usr/lib/npreal2
%define driverPath %{NPPATH}/driver
%define Moxa_config %{driverPath}/npreal2d.cf
%define MXLOADSVR %{driverPath}/mxloadsvr
BuildRoot: %{buildroot}
Summary: MOXA Linux Real TTY Driver
License: Unknown
Packager: Thomas Ubuntu Dahlmann
Name: %{name}
Version: %{version}
Release: %{release}
Source: %{name}-%{version}.tar.gz
Prefix: /usr
Group: System/Utilities
%description
The purpose of this driver is to map NPort serial port to host tty port. Using this driver, you can use NPort serial port as local tty port.
%prep
%setup -q
rm -rf %{buildroot}
mkdir -p %{buildroot}
%build
NPPATH="/usr/lib/npreal2"
driverPath="/usr/lib/npreal2/driver"
make SP1 PATH1=$(pwd)
%install
NowPath=$(pwd)
mkdir -p %{buildroot}/%{driverPath}
mkdir -p %{buildroot}/%{NPPATH}
mkdir -p %{buildroot}/lib/modules/%{kernel}/kernel/drivers/char/
mkdir -p %{buildroot}/lib/modules/%{kernel}/misc
mkdir -p %{buildroot}/etc
cp -f $NowPath/killp %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2d %{buildroot}/%{driverPath}
cp -f $NowPath/Makefile %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2d.c %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2.h %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2d.cf %{buildroot}/%{driverPath}/config
cp -f $NowPath/npreal2d.cf %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2.c %{buildroot}/%{driverPath}
cp -f $NowPath/mxaddsvr %{buildroot}/%{driverPath}
cp -f $NowPath/mxdelsvr %{buildroot}/%{driverPath}
cp -f $NowPath/mxcfmat %{buildroot}/%{driverPath}
cp -f $NowPath/mxloadsvr %{buildroot}/%{driverPath}
cp -f $NowPath/mxmknod %{buildroot}/%{driverPath}
cp -f $NowPath/mxrmnod %{buildroot}/%{driverPath}
cp -f $NowPath/mxuninst %{buildroot}/%{driverPath}
cp -f $NowPath/mxsetsec %{buildroot}/%{driverPath}
cp -f $NowPath/README.TXT %{buildroot}/%{NPPATH}
cp -f $NowPath/VERSION.TXT %{buildroot}/%{NPPATH}
cp -f $NowPath/kernel2.6.txt %{buildroot}/%{NPPATH}
cp -f $NowPath/npreal2.ko %{buildroot}/lib/modules/%{kernel}/kernel/drivers/char
cp -f $NowPath/npreal2.ko %{buildroot}/lib/modules/%{kernel}/misc
# Refresh modules
depmod -a
%post
if [ -f /usr/lib/npreal2/driver/npreal2d.cf ]
then
echo "Backup old config file.."
cp %{Moxa_config} /root/npreal2d.cf-$(date +%d%m%y-%H%M)
echo "OK!"
fi
%preun
cd %{driverPath}
for moxabox in $(cat %{driverPath}/npreal2d.cf | grep -v \# | egrep '^([0-9])'| awk '{print $2}'); do
./mxdelsvr $moxabox
done
%postun
cat /etc/rc.d/rc.local |grep -v "modprobe npreal2" > /tmp/rc.local
cat /tmp/rc.local > /etc/rc.d/rc.local
rm /tmp/rc.local
%files
%defattr(-,root,root)
/lib/modules/%{kernel}/kernel/drivers/char/npreal2.ko
/lib/modules/%{kernel}/misc/npreal2.ko
%{driverPath}/killp
%{driverPath}/npreal2d
%{driverPath}/Makefile
%{driverPath}/npreal2d.c
%{driverPath}/npreal2.h
%{driverPath}/npreal2d.cf
%{driverPath}/config
%{driverPath}/npreal2.c
%{driverPath}/mxaddsvr
%{driverPath}/mxdelsvr
%{driverPath}/mxcfmat
%{driverPath}/mxloadsvr
%{driverPath}/mxmknod
%{driverPath}/mxrmnod
%{driverPath}/mxuninst
%{driverPath}/mxsetsec
%{NPPATH}/README.TXT
%{NPPATH}/VERSION.TXT
%{NPPATH}/kernel2.6.txt
===== OLD npreal2.spec =====
# This is a spec file for the MOXA Linux Real TTY Driver
%define kernel 2.6.18-164.11.1.el5
%define _topdir /root/moxa-rpm
%define name npreal2
%define release 1
%define version 1.16
%define buildroot %{_topdir}/%{name}-%{version}-root
%define NPPATH /usr/lib/npreal2
%define driverPath /usr/lib/npreal2/driver
BuildRoot: %{buildroot}
Summary: MOXA Linux Real TTY Driver
License: Unknown
Packager: Thomas Ubuntu Dahlmann
Name: %{name}
Version: %{version}
Release: %{release}
Source: %{name}-%{version}.tar.gz
Prefix: /usr
Group: System/Utilities
%description
The purpose of this driver is to map NPort serial port to host tty port. Using this driver, you can use NPort serial port as local tty port.
%prep
%setup -q
rm -rf %{buildroot}
mkdir %{buildroot}
%build
NPPATH="/usr/lib/npreal2"
driverPath="/usr/lib/npreal2/driver"
make SP1 PATH1=$(pwd)
%install
NowPath=$(pwd)
mkdir -p %{buildroot}/%{driverPath}
mkdir -p %{buildroot}/%{NPPATH}
mkdir -p %{buildroot}/lib/modules/%{kernel}/kernel/drivers/char/
mkdir -p %{buildroot}/lib/modules/%{kernel}/misc
mkdir -p %{buildroot}/etc
cp -f $NowPath/killp %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2d %{buildroot}/%{driverPath}
cp -f $NowPath/Makefile %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2d.c %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2.h %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2d.cf %{buildroot}/%{driverPath}/config
cp -f $NowPath/npreal2d.cf %{buildroot}/%{driverPath}
cp -f $NowPath/npreal2.c %{buildroot}/%{driverPath}
cp -f $NowPath/mxaddsvr %{buildroot}/%{driverPath}
cp -f $NowPath/mxdelsvr %{buildroot}/%{driverPath}
cp -f $NowPath/mxcfmat %{buildroot}/%{driverPath}
cp -f $NowPath/mxloadsvr %{buildroot}/%{driverPath}
cp -f $NowPath/mxmknod %{buildroot}/%{driverPath}
cp -f $NowPath/mxrmnod %{buildroot}/%{driverPath}
cp -f $NowPath/mxuninst %{buildroot}/%{driverPath}
cp -f $NowPath/mxsetsec %{buildroot}/%{driverPath}
cp -f $NowPath/README.TXT %{buildroot}/%{NPPATH}
cp -f $NowPath/VERSION.TXT %{buildroot}/%{NPPATH}
cp -f $NowPath/kernel2.6.txt %{buildroot}/%{NPPATH}
cp -f $NowPath/npreal2.ko %{buildroot}/lib/modules/%{kernel}/kernel/drivers/char
cp -f $NowPath/npreal2.ko %{buildroot}/lib/modules/%{kernel}/misc
%post
function error_occured {
echo "
ERROR OCCURRED!!
The driver could not be loaded.
Your kernel version is: `uname -r`
This package is build for: %{kernel}
Last 10 lines from kernel output:
-------------------------------------
"
dmesg|tail -n 10
exit
}
if [ -f /usr/lib/npreal2/driver/npreal2d.cf ]
then
kill -9 `ps aux|grep npreal2d|awk '{print $2}'` > /dev/null 2>&1
lsmod | grep npreal2 | awk '$0 != "" {system("modprobe -r npreal2")}'
if [ $? -eq 0 ]
then
modprobe npreal2
depmod -a
else
error_occured
fi
if [ $? -eq 0 ]
then
echo "Driver loaded OK!"
exit 0
else
error_occured
fi
else
echo "
===============================================================================
Installation process is completed.
The driver files are installed in /usr/lib/npreal2/driver.
Now you can "cd /usr/lib/npreal2/driver" and run "./mxaddsvr" to add tty port.
===============================================================================
"
fi
%preun
cd %{driverPath}
for moxabox in $(cat %{driverPath}/npreal2d.cf | grep -v \# | egrep '^([0-9])'| awk '{print $2}'); do
./mxdelsvr $moxabox
done
%postun
cat /etc/rc.d/rc.local |grep -v "modprobe npreal2" > /tmp/rc.local
cat /tmp/rc.local > /etc/rc.d/rc.local
rm /tmp/rc.local
%files
%defattr(-,root,root)
/lib/modules/%{kernel}/kernel/drivers/char/npreal2.ko
/lib/modules/%{kernel}/misc/npreal2.ko
%{driverPath}/killp
%{driverPath}/npreal2d
%{driverPath}/Makefile
%{driverPath}/npreal2d.c
%{driverPath}/npreal2.h
%{driverPath}/npreal2d.cf
%{driverPath}/config
%{driverPath}/npreal2.c
%{driverPath}/mxaddsvr
%{driverPath}/mxdelsvr
%{driverPath}/mxcfmat
%{driverPath}/mxloadsvr
%{driverPath}/mxmknod
%{driverPath}/mxrmnod
%{driverPath}/mxuninst
%{driverPath}/mxsetsec
%{NPPATH}/README.TXT
%{NPPATH}/VERSION.TXT
%{NPPATH}/kernel2.6.txt