编辑用户自定义脚本
本章节介绍用户如何在制作OS阶段进行用户自定义软件包的预置。
您可以参考制卡工具包中携带的install_hook_demo.sh脚本,在生成的自定义脚本minirc_install_hook.sh中进行软件包预置及系统启动服务调用。
参数 |
说明 |
|---|---|
ROOT_PATH=$1 |
制作过程中根文件的系统路径,不可修改,用户可以此作为系统安装后的根目录。 |
BOOT_SH="${ROOT_PATH}/var/minirc_hook.sh" |
制作过程中系统启动预留钩子脚本名,不可修改。 |
function hook_head function hook_end |
系统启动预留钩子脚本起始及结尾代码,不可修改。 |
用户可对以下脚本中的粗体部分进行修改。
#!/bin/bash
#rootfs root path
ROOT_PATH=$1
#boot scripts, no need to modify
BOOT_SH="${ROOT_PATH}/var/minirc_hook.sh"
######minirc_hook.sh header and ending, no need to modify######
function hook_head()
{
echo "
#!/bin/bash
" >${BOOT_SH}
}
function hook_end()
{
echo "
exit 0
" >>${BOOT_SH}
}
###############################################################
########################user function##########################
function func_sample()
{
echo "start install sample lib"
#do copy
installAclLib
installAicpuKernels
}
###############################################################
# start
hook_head
func_sample
hook_end
针对添加用户自定义安装包场景,用户在脚本“func_sample()”函数中,需要做如下操作。
- 确认安装包格式。
- 如果安装包是压缩包格式,需要先解压安装包到预安装系统的指定目录下。
- 如果待安装文件是.run或.deb格式等不需要解压的文件,可直接拷贝文件到预安装系统的指定目录中。
预安装系统的指定目录:制卡时创建的目录,路径为${ROOT_PATH}。
- 添加安装命令到预安装系统的启动脚本中(${BOOT_SH},启动脚本在Atlas 200I A2 加速模块系统启动后会自动调用执行)。添加的命令可以是安装命令,也可以是启动用户服务的命令。
通用安装流程为:进入到解压目录,然后更改安装脚本权限,并执行安装脚本,最后删除解压目录。
使用样例
下面以添加安装TestCase.tar.gz包为例,介绍下如何修改install_hook_demo.sh脚本。新增内容如脚本中的粗体部分。
#!/bin/bash
#rootfs root path
ROOT_PATH=$1
#boot scripts, no need to modify
BOOT_SH="${ROOT_PATH}/var/minirc_hook.sh"
######minirc_hook.sh header and ending, no need to modify######
function hook_head()
{
echo "
#!/bin/bash
" >${BOOT_SH}
}
function hook_end()
{ echo "
exit 0
" >>${BOOT_SH} }
#user package name, you must change name
AICPU_KERNELS_PACKAGE=$(ls TestCase.tar.gz)
# using this as generateAclLibInstallShell()
function genAicpuKernInstShell()
{
echo "
cd /root/aicpu_kernels_device/
chmod 750 *.sh
chmod 750 scripts/*.sh
scripts/install.sh --run
rm -rf /root/aicpu_kernels_device
" >>${BOOT_SH}
}
# using this as installAclLib()
function installAicpuKernels()
{
tar zxf ${CUR_PATH}/${AICPU_KERNELS_PACKAGE} -C ${ROOT_PATH}/root/
genAicpuKernInstShell
}
###############################################################
########################user function##########################
function main()
{ echo "start install sample lib"
installAicpuKernels
}
###############################################################
# start
hook_head
main
hook_end
父主题: 二次开发场景