[Ubuntu][Shell]make_ubuntu_sd.sh注释解读
华为云博客字数受到限制,完整注释请参看https://blog.csdn.net/FL1623863129/article/details/103984869
# ########################Begin Executing######################################
# ************************Check args*******************************************
function main()
{
# 检查输入的参数合不合法,4个就是对的不是4个就是错的
if [[ $# -lt 4 ]];then
echo "Failed: Number of parameter illegal! Usage: $0 <dev fullname> <img path> <iso fullname> <mini filename>"
return 1;
fi
# 检查网卡IP和USB IP地址是不是有效的
# ***************check network and usb card ip**********************************
checkIps
if [ $? -ne 0 ];then
return 1
fi
# 检查SD卡
# ************************umount dev_name***************************************
checkSDCard
if [ $? -ne 0 ];then
return 1
fi
# ************************Extract ubuntufs**************************************
# output:squashfs-root/
#提取Ubunutu镜像里面的系统
ubuntufsExtract
if [ $? -ne 0 ];then
return 1
fi
# end
# 将/usr/bin/qemu-aarch64-static复制到/usr/bin/qemu-aarch64-static目录
# ************************Check architecture************************************
arch=$(uname -m)
if [[ ${arch} =~ "x86" ]];then
cp /usr/bin/qemu-aarch64-static ${LogPath}squashfs-root/usr/bin/
if [ $? -ne 0 ];then
echo "Failed: qemu-user-static or binfmt-support not found!"
return 1;
fi
chmod 755 ${LogPath}squashfs-root/usr/bin/qemu-aarch64-static
fi
# end
# 配置Ubuntu系统
# ************************Configure ubuntu**************************************
echo "Process: 1/4(Configure ubuntu filesystem)"
configUbuntu
if [ $? -ne 0 ];then
return 1
fi
# end
#格式化SD卡
# ************************Format SDcard*****************************************
echo "Process: 2/4(Format SDcard)"
formatSDcard
if [ $? -ne 0 ];then
return 1
fi
# end
# ************************Copy files to SD**************************************
# 卸载TMPDIR_SD_MOUNT分区并删除里面的所有文件
if [[ -d "${TMPDIR_SD_MOUNT}" ]];then
umount ${TMPDIR_SD_MOUNT} 2>/dev/null
rm -rf ${TMPDIR_SD_MOUNT}
fi
#创建TMPDIR_SD_MOUNT目录并挂载
mkdir ${TMPDIR_SD_MOUNT}
mount ${DEV_NAME}$p1 ${TMPDIR_SD_MOUNT} 2>/dev/null # updated by aman
# 卸载分区2,并删除分区2里面所有的文件
if [[ -d "${TMPDIR_SD2_MOUNT}" ]];then
umount ${TMPDIR_SD2_MOUNT} 2>/dev/null
rm -rf ${TMPDIR_SD2_MOUNT}
fi
#创建TMPDIR_SD_MOUNT2目录并挂载
mkdir ${TMPDIR_SD2_MOUNT}
mount ${DEV_NAME}$p2 ${TMPDIR_SD2_MOUNT} 2>/dev/null # updated by aman
# 卸载分区3,并删除分区3里面所有的文件
if [[ -d "${TMPDIR_SD3_MOUNT}" ]];then
umount ${TMPDIR_SD3_MOUNT} 2>/dev/null
rm -rf ${TMPDIR_SD3_MOUNT}
fi
#创建TMPDIR_SD_MOUNT3目录并挂载
mkdir ${TMPDIR_SD3_MOUNT}
mount ${DEV_NAME}$p3 ${TMPDIR_SD3_MOUNT} 2>/dev/null # updated by aman
echo "Process: 3/4(Copy filesystem and mini package to SDcard)"
# 复制文件到SD卡里面去,具体怎么复制请看这个函数
copyFilesToSDcard
if [ $? -ne 0 ];then
return 1
fi
# end
echo "Process: 4/4(Make sysroot)"
make_sysroot
umount ${TMPDIR_SD_MOUNT} 2>/dev/null
if [[ $? -ne 0 ]];then
echo "Failed: Umount ${TMPDIR_SD_MOUNT} to SDcard failed!"
return 1
fi
umount ${TMPDIR_SD2_MOUNT} 2>/dev/null
if [[ $? -ne 0 ]];then
echo "Failed: Umount ${TMPDIR_SD2_MOUNT} to SDcard failed!"
return 1
fi
umount ${TMPDIR_SD3_MOUNT} 2>/dev/null
if [[ $? -ne 0 ]];then
echo "Failed: Umount ${TMPDIR_SD3_MOUNT} to SDcard failed!"
return 1
fi
echo "Finished!"
return 0
}
#进入脚本我们应该从这里看代码,上面全部是封装的函数,用来调用的
main $* #执行main函数
ret=$? #获取执行的结果
#clean files
filesClean #清理缓存的文件
#失败就向make_ubuntu_sd.result写个字符串Failed
if [[ ret -ne 0 ]];then
echo "Failed" > ${LogPath}/make_ubuntu_sd.result
exit 1
fi
#成功就向make_ubuntu_sd.sh写个字符串Success
echo "Success" > ${LogPath}/make_ubuntu_sd.result
exit 0
# end
- 点赞
- 收藏
- 关注作者
评论(0)