2 # Copyright 2015 Futurewei Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # A copy of the license is included with this distribution. If you did not
7 # recieve a copy you may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 which dpkg-architecture 2>&1 1>/dev/null
19 echo "Can't locate dpkg-architecture"
20 echo "try 'sudo apt-get install dpkg-dev"
23 KERNEL_VERSION=${KERNEL_VERSION-`uname -r`}
25 PACKAGE_ARCH=`dpkg-architecture -qDEB_BUILD_ARCH`
26 GIT_VERSION=`git ls-remote 2>/dev/null | awk '{print $2}' | sed 's/\// /g' | sort -n -k4| awk '/[0-9]+/{print $(NF-1)"-"$NF}' | tail -n -1`
27 PACKAGE_VERSION="1.0.$GIT_VERSION-${KERNEL_VERSION}"
30 PACKAGE_DEPENDS=linux-image-${KERNEL_VERSION}
32 rm -rf ${PACKAGE_NAME}-${PACKAGE_VERSION}
33 mkdir -p ${PACKAGE_NAME}-${PACKAGE_VERSION}/DEBIAN
34 # put this in with pktgen
35 mkdir -p ${PACKAGE_NAME}-${PACKAGE_VERSION}/lib/modules/${KERNEL_VERSION}/kernel/net/core/
36 cat >>${PACKAGE_NAME}-${PACKAGE_VERSION}/DEBIAN/control <<EOF
37 Package: ${PACKAGE_NAME}
38 Version: ${PACKAGE_VERSION}
41 Architecture: ${PACKAGE_ARCH}
42 Maintainer: eugene.snider@huawei.com
43 Depends: ${PACKAGE_DEPENDS}
44 Description: simple l2 fowarding driver
45 This package provides the l2fwd driver
47 cat >>${PACKAGE_NAME}-${PACKAGE_VERSION}/DEBIAN/preinst <<EOF
50 if [ upgrade != "$1" ] || dpkg --compare-versions "$2" lt ${PACKAGE_VERSION}; then
51 dpkg-divert --package ${PACKAGE_NAME} --add --rename \
52 --divert /lib/modules/${KERNEL_VERSION}/kernel/net/core/${MODULE_NAME}.ko.dist /lib/modules/${KERNEL_VERSION}/kernel/net/core/${MODULE_NAME}.ko
55 chmod 555 ${PACKAGE_NAME}-${PACKAGE_VERSION}/DEBIAN/preinst
56 cat >>${PACKAGE_NAME}-${PACKAGE_VERSION}/DEBIAN/postinst <<EOF
58 /sbin/depmod -a `uname -r`
60 chmod 555 ${PACKAGE_NAME}-${PACKAGE_VERSION}/DEBIAN/postinst
61 cat >>${PACKAGE_NAME}-${PACKAGE_VERSION}/DEBIAN/postrm <<EOF
64 if [ upgrade != "$1" ] || dpkg --compare-versions "$2" lt ${PACKAGE_VERSION}; then
65 dpkg-divert --package ${PACKAGE_NAME} --remove --rename \
66 --divert /lib/modules/${KERNEL_VERSION}/kernel/net/core/${MODULE_NAME}.ko.dist /lib/modules/${KERNEL_VERSION}/kernel/net/core/${MODULE_NAME}.ko
69 chmod 555 ${PACKAGE_NAME}-${PACKAGE_VERSION}/DEBIAN/postrm
70 cp -p ${MODULE_NAME}.ko ${PACKAGE_NAME}-${PACKAGE_VERSION}/lib/modules/${KERNEL_VERSION}/kernel/net/core/${MODULE_NAME}.ko
71 sudo dpkg-deb --build ${PACKAGE_NAME}-${PACKAGE_VERSION}
72 sudo rm -rf ${PACKAGE_NAME}-${PACKAGE_VERSION}