shell script : install pf_ring driver

前端之家收集整理的这篇文章主要介绍了shell script : install pf_ring driver前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前一步做了pf_ring的编译,在pf_ring.ko没安装之前,pf_ring自带的例子大部分是不生效的。
如果在开发机,在pf_ring编译完后,运行make install 可以安装pf_ring.ko.
但是考虑到部署时,是没有开发环境的,需要写一个脚本,将驱动部署好。
花了一上午时间弄了一个脚本,还挺好使的。

脚本下载点

pf_ring_case_v1.1.zip
* 加入了安装pf_ring.ko的脚本
* 修正了一个测试工程的Makefile,加入了共用头文件的包含路径

安装脚本 install_pf_ring_driver.sh

#!/bin/bash
# @file install_pf_ring_driver.sh

# ================================================================================
# ================================================================================
# run result
# ================================================================================
# ================================================================================
# ================================================================================
# install pf_ring driver,version = 1.0.0.1 build 2017-07-09 14:04
# ================================================================================
# bash file is :install_pf_ring_driver.sh
# pf_ring_ko_pathname = /home/lostspeed/dev/pf_ring_case_v1/pf_ring_lib/kernel/pf_ring.ko
# found /lib/modules/3.2.0-4-amd64/kernel/net/pf_ring
# found /home/lostspeed/dev/pf_ring_case_v1/pf_ring_lib/kernel/pf_ring.ko
# found /lib/modules/3.2.0-4-amd64/kernel/net/pf_ring/pf_ring.ko,delete it
# debian's driver path is /lib/modules/3.2.0-4-amd64/kernel/net/pf_ring
# copy file /home/lostspeed/dev/pf_ring_case_v1/pf_ring_lib/kernel/pf_ring.ko to /lib/modules/3.2.0-4-amd64/kernel/net/pf_ring/pf_ring.ko ...
# found /lib/modules/3.2.0-4-amd64/kernel/net/pf_ring/pf_ring.ko,copy ok
# update driver list,please wait a monment ...
# update driver list over!
# now,can use the app depend /lib/modules/3.2.0-4-amd64/kernel/net/pf_ring/pf_ring.ko :)
# exit code is : 0
# ================================================================================
# ================================================================================

# $0 is the name of the command
# $1 first parameter
# $2 second parameter
# $3 third parameter etc. etc
# $# total number of parameters
# $@ all the parameters will be listed

# run this shell script below:
# chmod 777 ./install_pf_ring_driver.sh
# bash ./install_pf_ring_driver.sh

# 在windows编写sh,空行不能是回车(\r\n),可以在Notepad++中将文件设置为unix格式,uft-8文本
# 设置 => 首选项 => 新建 => unix + uft-8

# 变量赋值左右值之间必须只用=连接在一起,不能有空格
SH_FILE_VERSION="version = 1.0.0.1 build 2017-07-09 14:04"
PROG_DEPMOD=/sbin/depmod
DEBIAN_DRIVER_DIR=3.2.0-4-amd64

#/lib/modules/3.2.0-4-amd64/kernel/net/pf_ring
PF_RING_DRV_INSTALL_DIR="/lib/modules/"
PF_RING_DRV_INSTALL_DIR+=$DEBIAN_DRIVER_DIR
PF_RING_DRV_INSTALL_DIR+="/kernel/net/pf_ring"

# 命令行参数个数不包括程序本身
cmd_argc=$#
pf_ring_ko_pathname=$1
pf_ring_ko_pathname_to_dst=""

# const error code
err_code_base=0
let "err_code_ok=$err_code_base+0"
let "err_code_cmd_param_cnt_is_invalid=$err_code_base-1"
let "err_code_ko_file_not_exist=$err_code_base-2"
let "err_code_ko_file_copy_filed=$err_code_base-3"

function sh_main {
    clear

    echo ================================================================================
    echo install pf_ring driver,$SH_FILE_VERSION
    echo ================================================================================

    echo bash file is :$0
    echo pf_ring_ko_pathname = $pf_ring_ko_pathname
    if [ $cmd_argc != 1 ]; then
        fn_help
        fn_quit $err_code_cmd_param_cnt_is_invalid
    fi

    if [ ! -d $PF_RING_DRV_INSTALL_DIR ]; then
        echo not found $PF_RING_DRV_INSTALL_DIR,create it
        mkdir $PF_RING_DRV_INSTALL_DIR
    else
        echo found $PF_RING_DRV_INSTALL_DIR
    fi

    if [ ! -f $pf_ring_ko_pathname ]; then
        echo not found $pf_ring_ko_pathname
        fn_quit $err_code_ko_file_not_exist
    else
        echo found $pf_ring_ko_pathname
    fi

# ${filename##*/} is x.ko 
    pf_ring_ko_pathname_to_dst=$PF_RING_DRV_INSTALL_DIR
    pf_ring_ko_pathname_to_dst+="/"
    pf_ring_ko_pathname_to_dst+=${pf_ring_ko_pathname##*/}

    if [ -f $pf_ring_ko_pathname_to_dst ]; then
        echo found $pf_ring_ko_pathname_to_dst,delete it
        rm $pf_ring_ko_pathname_to_dst
    fi

    echo "debian's driver path is $PF_RING_DRV_INSTALL_DIR"
    echo copy file $pf_ring_ko_pathname to $pf_ring_ko_pathname_to_dst ...
    cp $pf_ring_ko_pathname $PF_RING_DRV_INSTALL_DIR

    if [ -f $pf_ring_ko_pathname_to_dst ]; then
        echo found $pf_ring_ko_pathname_to_dst,copy ok
    else
        fn_quit $err_code_ko_file_copy_filed
    fi

    fn_update_driver_list $pf_ring_ko_pathname_to_dst
    fn_quit $err_code_ok
}

function fn_update_driver_list {
    echo update driver list,please wait a monment ...
    $PROG_DEPMOD $DEBIAN_DRIVER_DIR
    echo update driver list over!
    echo "now,can use the app depend $1 :)"
}

function fn_help {
    echo ================================================================================
    echo must give ONE parameter,this parameter is pf_ring\'s ko file echo e.g. bash install_pf_ring_driver.sh /home/lostspeed/dev/pf_ring_case_v1/pf_ring_lib/kernel/pf_ring.ko echo ================================================================================ } function fn_quit { echo exit code is : $1 exit $1 } sh_main "$@" 
原文链接:https://www.f2er.com/bash/392173.html

猜你在找的Bash相关文章