此软件包可安装驱动程序。
此案例研究展示以下技术:
使用 postinstall 脚本安装和装入驱动程序
使用 preremove 脚本卸载驱动程序
有关这些脚本的更多信息,请参见编写过程脚本。
创建 request 脚本。
request 脚本通过询问管理员并将答复指定给 $KERNDIR 参数,确定管理员希望将驱动程序对象安装到的位置。
该脚本以一个例程结束,以使两个参数(即,CLASSES 和 KERNDIR)对于安装环境和 postinstall 脚本可用。
创建 postinstall 脚本。
postinstall 脚本实际上执行驱动程序安装。该脚本在 buffer 和 buffer.conf 两个文件安装后执行。在此示例中显示的 postinstall 文件执行以下操作:
使用 add_drv 命令将驱动程序装入到系统。
使用 installf 命令为设备创建链接。
使用 installf -f 命令完成安装。
创建 preremove 脚本。
preremove 脚本使用 rem_drv 命令从系统卸载驱动程序,然后删除链接 /dev/buffer0。
PKG=bufdev NAME=Buffer Device CATEGORY=system BASEDIR=/ ARCH=INTEL VERSION=Software Issue #19 CLASSES=none |
要在安装时安装驱动程序,您必须在 prototype 文件中包括驱动程序的对象和配置文件。
在此示例中,驱动程序的可执行模块被命名为 buffer;add_drv 命令处理该文件。内核使用配置文件 buffer.conf 帮助配置驱动程序。
i pkginfo i request i postinstall i preremove f none $KERNDIR/buffer 444 root root f none $KERNDIR/buffer.conf 444 root root |
查看此示例中的 prototype 文件,请注意以下事项:
因为不需要对软件包对象进行特殊处理,所以您可以将其放置在 none 标准类中。在 pkginfo 文件中 CLASSES 参数被设置为 none。
buffer 和 buffer.conf 的路径名以变量 $KERNDIR 开头。此变量在 request 脚本中设置,允许管理员决定驱动程序文件的安装位置。缺省目录是 /kernel/drv。
postinstall 脚本(将执行驱动程序安装的脚本)有一个对应条目。
trap 'exit 3' 15 # determine where driver object should be placed; location # must be an absolute path name that is an existing directory KERNDIR=`ckpath -aoy -d /kernel/drv -p \ “Where do you want the driver object installed”` || exit $? # make parameters available to installation service, and # so to any other packaging scripts cat >$1 <<! CLASSES='$CLASSES' KERNDIR='$KERNDIR' ! exit 0 |
# KERNDIR parameter provided by `request' script err_code=1 # an error is considered fatal # Load the module into the system cd $KERNDIR add_drv -m '* 0666 root sys' buffer || exit $err_code # Create a /dev entry for the character node installf $PKGINST /dev/buffer0=/devices/eisa/buffer*:0 s installf -f $PKGINST |
err_code=1 # an error is considered fatal # Unload the driver rem_drv buffer || exit $err_code # remove /dev file removef $PKGINST /dev/buffer0 ; rm /dev/buffer0 removef -f $PKGINST |