利用工作的闲余时间,写了2个月的shell脚本仅适用于MTK代码环境。主要是为了改变繁琐的工作量,并且外来FAE前来调试模块,可以不用再去陪着调试。脚本实现主要功能有:
(1)git拉取代码,编译好代码环境(user、userdebug、eng)
(2)快速获取环境驱动配置信息和打开模块配置文件
(3)单独编译各个代码部分和按顺序编译模块
(4)快速打开flash_tool工具,自动加root权限以及下载软件路径
(5)多进程打包下载软件
代码如下:
#!/bin/bash
#脚本功能:1、拉取代码,编译DEBUG版本 2、编译 3、版本打包 4、自动加root权限和软件路径,直接下载软件
#2016年11月2号开始写lyscript
#2017年1月6日cp、open功能
#2017年1月14日写好打包及脚本更新功能
#2017年1月20日写好判断平台功能
#2017年2月6日写好判断mtk6735平台功能
#2017年2月7号修改识别64编译环境删除libcameracusto.*文件判断问题的BUG
#2017年2月9号./mk debug mk u kernel 修改 ./mk debug mk u bootimage
#2017年2月14日,小BUG
#2017年2月21日,编写上传函数
#2017年3月13日,拉取代码以及编译USER、ENG、DEBUG
#2017年3月15,支持打开mak文件所在的文件夹路径
#2017年3月16,在单独编译kernel时,先删除obj/KERNEL_OBJ/driver/文件
#2017年3月17日修复不同的显示器显示终端尺寸提交的BUG问题及添加运行脚本编译的提示信息
#2017年3月18日凌晨1点增加编译停止,检索error信息功能;新增单独编译HAL层代码
#2017年3月30日在使用lyscript -t不会删除verified文件,主要兼容MMI使用
set -o pipefail
#主机名
HOSTNAME=$USER
#桌面
DESKTOP=/home/$HOSTNAME/Desktop
#运行脚本先最大化自动适应自己电脑的终端
resize -s 100 300 >>/home/$HOSTNAME/lyscript_log.txt
SIZE=`resize`
#echo $SIZE
LENGTH=`echo $SIZE | grep "^COLUMNS=" | awk -F"=" '{print $2}' | awk -F";" '{print $1}'`
WIDTH=`echo $SIZE | grep "LINES=" | awk -F"=" '{print $3}' | awk -F";" '{print $1}'`
#echo "l:$LENGTH k:$WIDTH"
resize -s $WIDTH $LENGTH >>/home/$HOSTNAME/lyscript_log.txt
#运行环境路径
ENV_DIR_PWD=`pwd`
#控制输出颜色
COLOR_G='\033[32;1m'
COLOR_R='\033[31;1m'
COLOR_B='\033[34;1m'
COLOR_E='\033[0m'
function ly_help(){
ly_v
echo -e "
选项: 使用方法 作用
lyscript 获取环境LCM、CAM、MODEM、平台等配置信息
-t lyscript -t 自动打开flahs_tool下载工具,并获取权限,自动填充环境下载路径
-h lyscript -h 脚本使用信息
-c lyscript -c lcm 复制项目配置的屏幕代码到桌面
lyscript -c cam 复制项目配置的摄像头代码到桌面
-o lyscript -o lcm 打开项目配置的摄像头代码(kernel和hal)
lyscript -o cam 打开项目配置的屏幕代码(kernel和lk)
lyscript -o mk 打开项目配置MAK文件
-b lyscript -b 打包压缩下载文件到桌面
lyscript -b cam 打包压缩摄像头代码和下载文件到桌面
lyscript -b lcm 打包压缩屏幕代码和下载文件到桌面
-p lyscript -p 下拉BASE代码
-u lyscpipt -u 更新lyscript版本
-n lyscript -n 重新编译环境
-s lyscript -s 打开FTP服务器:192.168.1.2
k lyscript k 编译kernel代码,先删除out下obj/KERNEL_OBJ/drivers/
pl lyscript pl 编译preloader代码
lk lyscript lk 编译lk代码
lcm lyscript lcm 编译lk代码和kernel代码
hal lyscript hal 仅编译hal代码,会先自动删除OUT下libcameracustom.*文件
cam lyscript cam 编译kernel代码和hal代码,会先自动删除OUT下libcameracustom.*文件
"
echo -e "${COLOR_B}******************************************************************************************************${COLOR_E}"
}
#方便更新版本
function ly_v(){
LYSCRIPT_VERSION=20170406
LYSCRIPT_CREATETIME="2016.11.02"
LYSCRIPT_NAME=lyscript
echo -e "${COLOR_B}********** Name:${LYSCRIPT_NAME} ********************* Version:${LYSCRIPT_VERSION} ********************* Date:${LYSCRIPT_CREATETIME} ***********${COLOR_E}"
}
#LCM代码路径(andriod 6.0)
export KERNEL_DIR=kernel-3.18
export LY_LK_LCM_DIR=vendor/mediatek/proprietary/bootable/bootloader/lk/dev/lcm
export LY_KERNEL_LCM_DIR=$KERNEL_DIR/drivers/misc/mediatek/lcm
#判断环境是否存在
if [ "$1" == "-p" ] || [ "$1" == "-h" ] || [ "$1" == "-v" ]; then
echo "mingling">>/home/$HOSTNAME/lyscript_log.txt
else
if [ ! -f "$ENV_DIR_PWD/resource/LyFeatures.mk" ]; then
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R}切换到正确的环境路径下${COLOR_E}"
exit 1
else
#环境
export MAKEFILE=$(cat $ENV_DIR_PWD/resource/LyFeatures.mk | grep "^LYCONFIG_CUSTOM_PRODUCT :=" | awk -F":=" '{print $2}')
export LCM=$(cat $ENV_DIR_PWD/resource/LyFeatures.mk | grep "^LYCONFIG_CUSTOM_KERNEL_LCM :=" | awk -F"\"" '{print $2}')
export IMAGESENSOR=$(cat $ENV_DIR_PWD/resource/LyFeatures.mk | grep "^LYCUSTOM_HAL_IMGSENSOR :=" | awk -F":=" '{print $2}')
export LENS=$(cat $ENV_DIR_PWD/resource/LyFeatures.mk | grep "^CUSTOM_HAL_LENS :=" | awk -F":=" '{print $2}')
export MODEM=$(cat $ENV_DIR_PWD/resource/LyFeatures.mk | grep "^CUSTOM_MODEM :=" | awk -F":=" '{print $2}')
export MTK_PLATFORM=$(cat $ENV_DIR_PWD/resource/LyFeatures.mk | grep "^LYCONFIG_MTK_PLATFORM :=" | awk -F":=" '{print $2}')
export BUILD=$(cat $ENV_DIR_PWD/resource/LyFeatures.mk | grep "^LYCONFIG_MTK_PLATFORM :=" | awk -F":=" '{print $2}')
#qu diao kong ge
MK=`echo ${MAKEFILE} | sed s/[[:space:]]//g`
ZB=`echo $MK | awk -F"." '{print $2}'`
if [ -d "${ENV_DIR_PWD}/out/target/product/" ]; then
cd ${ENV_DIR_PWD}/out/target/product/
OUT_MTK_MACH_TYPE=`ls -F | grep "/$" |grep "_" | grep "6" | awk -F"/" '{print $1}'`
PLATFORM=`echo ${OUT_MTK_MACH_TYPE} | awk -F"_" '{print $1}'`
export OUT=${ENV_DIR_PWD}/out/target/product/$OUT_MTK_MACH_TYPE
else
echo -e "${COLOR_R} Error:该环境未编译,无法使用该脚本!!!${COLOR_E}"
exit 1
fi
#2017.03.13识别环境编译类型
if [ -f "$OUT/system/build.prop" ]; then
export BB=$(cat $OUT/system/build.prop | grep "^ro.build.type=" | awk -F"=" '{print $2}')
if [ $BB == "userdebug" ]; then
COMPING=debug
elif [ $BB == "eng" ]; then
COMPING=eng
elif [ $BB == "user" ]; then
COMPING=release
#else
# echo -e "${COLOR_R} Error:未知环境编译类型"
fi
fi
case "$PLATFORM" in
#6580 已验证 ok
"long6580")
export CPU=MT6580
export MTK_MACH_TYPE=mt6580
export LY_HAL=vendor/mediatek/proprietary/custom/mt6580/hal
export LY_HAL_CAM_DIR=vendor/mediatek/proprietary/custom/mt6580/hal/imgsensor
export LY_KERNEL_CAM_DIR=${KERNEL_DIR}/drivers/misc/mediatek/imgsensor/src/mt6580
if [ -f "$OUT/MT6580_Android_scatter.txt" ]; then
export OUT_TXT=$OUT/MT6580_Android_scatter.txt
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R} MTK6580 环境未编译,脚本不支持${COLOR_E}"
export OUT_TXT=nothing
exit 1
fi
;;
#6735m 已验证 ok 20170120
"long6735m")
export CPU=MT6735M
export LY_HAL=vendor/mediatek/proprietary/custom/mt6735/hal
export LY_HAL_CAM_DIR=vendor/mediatek/proprietary/custom/mt6735/hal/D2/imgsensor
export LY_KERNEL_CAM_DIR=${KERNEL_DIR}/drivers/misc/mediatek/imgsensor/src/mt6735m
if [ -f "$OUT/MT6735M_Android_scatter.txt" ]; then
export OUT_TXT=$OUT/MT6735M_Android_scatter.txt
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R} MTK6735M 环境未编译,脚本不支持${COLOR_E}"
export OUT_TXT=nothing
exit 1
fi
;;
#6737m 已验证 ok 20170120
"long6737m")
export CPU=MT6737M
export LY_HAL=vendor/mediatek/proprietary/custom/mt6735/hal
export LY_HAL_CAM_DIR=vendor/mediatek/proprietary/custom/mt6735/hal/D2/imgsensor
export LY_KERNEL_CAM_DIR=${KERNEL_DIR}/drivers/misc/mediatek/imgsensor/src/mt6735m
if [ -f "$OUT/MT6737M_Android_scatter.txt" ]; then
export OUT_TXT=$OUT/MT6737M_Android_scatter.txt
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R} MTK6737M 环境未编译,脚本不支持${COLOR_E}"
export OUT_TXT=nothing
exit 1
fi
;;
#6753 已验证 ok
"wtk6753")
export CPU=MT6753
export LY_HAL=vendor/mediatek/proprietary/custom/mt6735/hal
export LY_HAL_CAM_DIR=vendor/mediatek/proprietary/custom/mt6735/hal/D1/imgsensor
export LY_KERNEL_CAM_DIR=${KERNEL_DIR}/drivers/misc/mediatek/imgsensor/src/mt6753
if [ -f "$OUT/MT6753_Android_scatter.txt" ]; then
export OUT_TXT=$OUT/MT6753_Android_scatter.txt
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R} MTK6753 环境未编译,脚本不支持${COLOR_E}"
export OUT_TXT=nothing
exit 1
fi
;;
#6750 已验证 ok
"wtk6750")
export CPU=MT6750
export LY_HAL=vendor/mediatek/proprietary/custom/mt6750/hal
export LY_HAL_CAM_DIR=vendor/mediatek/proprietary/custom/mt6750/hal/imgsensor
export LY_KERNEL_CAM_DIR=${KERNEL_DIR}/drivers/misc/mediatek/imgsensor/src/mt6750
if [ -f "$OUT/MT6750_Android_scatter.txt" ]; then
export OUT_TXT=$OUT/MT6750_Android_scatter.txt
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R} MTK6750 环境未编译,脚本不支持${COLOR_E}"
export OUT_TXT=nothing
exit 1
fi
;;
#6735 已验证 ok
"long6735")
export CPU=MT6735
export LY_HAL=vendor/mediatek/proprietary/custom/mt6735/hal
export LY_HAL_CAM_DIR=vendor/mediatek/proprietary/custom/mt6735/hal/D1/imgsensor
export LY_KERNEL_CAM_DIR=${KERNEL_DIR}/drivers/misc/mediatek/imgsensor/src/mt6735
if [ -f "$OUT/MT6735_Android_scatter.txt" ]; then
export OUT_TXT=$OUT/MT6735_Android_scatter.txt
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R} MTK6735 环境未编译,脚本不支持${COLOR_E}"
export OUT_TXT=nothing
exit 1
fi
;;
#6570
"long6570")
export CPU=MT6570
export LY_HAL=vendor/mediatek/proprietary/custom/mt6570/hal
export LY_HAL_CAM_DIR=vendor/mediatek/proprietary/custom/mt6570/hal/imgsensor
export LY_KERNEL_CAM_DIR=${KERNEL_DIR}/drivers/misc/mediatek/imgsensor/src/mt6570
if [ -f "$OUT/MT6570_Android_scatter.txt" ]; then
export OUT_TXT=$OUT/MT6570_Android_scatter.txt
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R} MTK6570 环境未编译,脚本不支持${COLOR_E}"
export OUT_TXT=nothing
exit 1
fi
;;
*)
echo -e "${COLOR_R} Error:此脚本不支持该平台${COLOR_E}"
exit 1
;;
esac
fi
fi
function ly_update(){
if [ -f "$DESKTOP/lyscript" ]; then
rm -rf $DESKTOP/lyscript
fi
ftp -n< open 192.168.1.2
user ubuntu .
binary
cd Driver_only/lyscript/script
lcd $DESKTOP
prompt
mget *
close
bye
!
expect /usr/bin/auto_script_update
ly_v
echo -e "
#脚本更新历史:
#脚本功能:1、拉取代码,编译DEBUG版本 2、编译 3、版本打包 4、自动加root权限和软件路径,直接下载软件
#脚本支持平台:MTK6580、MTK6737M、MTK6735、MTK6735M、MTK6750、MTK6753
#脚本支持系统版本:andriod 6.0
#2016年11月2号开始写lyscript
#2017年1月6日cp、open功能
#2017年1月14日写好打包及脚本更新功能
#2017年1月20日写好判断平台功能
#2017年2月6日写好判断mtk6735平台功能
#2017年2月7号修改识别64编译环境删除libcameracusto.*文件判断问题的BUG
#2017年2月9号./mk debug mk u kernel 修改 ./mk debug mk u bootimage
#2017年2月14日,小BUG
#2017年2月21日,编写上传函数
#2017年3月13日,拉取代码以及编译USER、ENG、DEBUG
#2017年3月15,支持打开mak文件所在的文件夹路径
#2017年3月16,在单独编译kernel时,先删除obj/KERNEL_OBJ/driver/文件
#2017年3月17日修复不同的显示器显示终端尺寸提交的BUG问题及添加运行脚本编译的提示信息
#2017年3月18日凌晨1点增加编译停止,检索error信息功能;新增单独编译HAL层代码
#2017年3月30日在使用lyscript -t不会删除verified文件,主要兼容MMI使用下载工具
#2017年4月1日增加编译preloader
#2017年4月6日增加脚本支持MTK6570环境
"
}
#打开flash_tool工具
function flash_tool(){
VERIFIED=`find ${OUT}/*verified*`;
if [ $? == 0 ]; then
echo -e "${COLOR_G}Note${COLOR_E}:${COLOR_R}Find verified files !!!${COLOR_E}"
mkdir $OUT/tmp/
mv ${OUT}/*verified.img $OUT/tmp/
mv ${OUT}/*verified.bin $OUT/tmp/
fi
if [ ! -f "/usr/bin/expect" ]; then
echo -e "${COLOR_R}please install: sudo apt-get install expect ${COLOR_E}"
exit 1
fi
if [ ! -f $OUT_TXT ]; then
echo "wei zhao dao xiazai wenjian"
fi
if [ $PLATFORM == "long6570" ]; then
{
echo -e "Open 6570 flash_tool"
local DESKDIR=/home/${HOSTNAME}/Desktop/SP_Flash_Tool_exe_Linux_v5.1652.00.100/
local HOMEDIR=/home/${HOSTNAME}/SP_Flash_Tool_exe_Linux_v5.1652.00.100/
}
else
{
echo -e "Open flash_tool"
local DESKDIR=/home/${HOSTNAME}/Desktop/SP_Flash_Tool_exe_Linux
local HOMEDIR=/home/${HOSTNAME}/SP_Flash_Tool_exe_Linux
}
fi
if [ -d "$DESKDIR" ]; then
result=$(cat $DESKDIR/history.ini | grep "lastDir=" | awk -F"=" '{print $1}')
echo -e "${COLOR_G}Open Download File${COLOR_E}:${COLOR_R}${OUT_TXT}${COLOR_E}"
sed -i -e "s|lastDir=.*|lastDir="$OUT_TXT"|g" $DESKDIR/history.ini
cd $DESKDIR
expect /usr/bin/auto_flash_tool
elif [ -d "$HOMEDIR" ]; then
result=$(cat $HOMEDIR/history.ini | grep "lastDir=" | awk -F"=" '{print $1}')
echo -e "${COLOR_G}Open Download File${COLOR_E}:${COLOR_R}${OUT_TXT}${COLOR_E}"
sed -i -e "s|lastDir=.*|lastDir="$OUT_TXT"|g" $HOMEDIR/history.ini
cd $HOMEDIR
expect /usr/bin/auto_flash_tool
else
echo -e "${COLOR_R}Error:没有发现下载工具${COLOR_E}"
fi
mv $OUT/tmp/* $OUT/
rm -rf $OUT/tmp
}
#利用终端拉取服务器代码(需要针对公司的配置,自行更改,不通用)
function lypullcode(){
#日期
today=`date +%F`
today=${today//-/}
#服务器BASE
BASE_6580_L=ALPS.MT6580.L1.MP6.V2.19
BASE_6580_M=ALPS.MT6580.M0.MP1.V2.34
BASE_6780_N=ALPS.MT6580.N0.MP2.V1
BASE_6735_M=ALPS.MT6735.M0.MP1.V2.39
#BASE_6735_L=ALPS.MT6735.L1.MP3.V2
BASE_6753_L=ALPS.MT6753.L1.MP3.V2.62
BASE_6753_M=ALPS.WT6753.M0.MP1.V2.39.1
BASE_6750_M=ALPS.WT6750.M0.MP7.V2.10
BASE_6737_M=ALPS.MT6737.M0.MP1.V2.115
BASE_6737_N=ALPS.MT6737.N0.MP1.V1.0.2
#换行Tab
LINE_TAB='\n\t'
DEVELOP=develop
echo -e "GIT库IP地址:$LINE_TAB${COLOR_G}1: 192.168.1.4\n\t2: 192.168.1.6${COLOR_E}"
read a
if [ $a -eq 1 ]
then IP=192.168.1.4
elif [ $a -eq 2 ]
then IP=192.168.1.6
else
echo "输入 ‘1’或者‘2',请重新运行脚本"
exit 1
fi
echo -e "${COLOR_B}SERVICE IP ADDRESS:${COLOR_E}${COLOR_R}$IP${COLOR_E}"
if [ $a -eq 1 ]
then
echo -e "\n选择 BASE:$LINE_TAB${COLOR_G}1: $BASE_6580_L.git\n\t2: $BASE_6580_M.git\n\t${COLOR_E}"
read b
case $b in
1) BASE=$BASE_6580_L ;;
2) BASE=$BASE_6580_M ;;
esac
elif [ $a -eq 2 ]
then
echo -e "\n选择 BASE:\n\t${COLOR_G}1: $BASE_6780_N.git\n\t2: $BASE_6735_M.git\n\t3: $BASE_6737_M.git\n\t4: $BASE_6753_L.git\n\t5: $BASE_6750_M.git\n\t6: $BASE_6753_M.git\n\t7: $BASE_6737_N.git${COLOR_E}"
read b
case $b in
1) BASE=$BASE_6780_N ;;
2) BASE=$BASE_6735_M ;;
3) BASE=$BASE_6737_M ;;
4) BASE=$BASE_6753_L ;;
5) BASE=$BASE_6750_M ;;
6) BASE=$BASE_6753_M ;;
7) BASE=$BASE_6737_N ;;
esac
else
echo "请输入正确的BASE选号"
exit 2
fi
#连接192.168.1.2下拉最新的BASE分支信息
if [ ! -d "/home/$HOSTNAME/work/.BASE_DEVELOP_INFO/" ]; then
mkdir /home/$HOSTNAME/work/.BASE_DEVELOP_INFO/
fi
ftp -n< open 192.168.1.2
user ubuntu .
binary
cd Driver_only/BASE_DEVELOP_INFO/
lcd /home/$HOSTNAME/work/.BASE_DEVELOP_INFO/
prompt
mget *
close
bye
!
echo -e "${COLOR_B}CHOICE BASE GIT:${COLOR_E}${COLOR_R}$BASE${COLOR_E}"
echo -e "\n选择$BASE下的分支名:"
#提取对应BASE分支信息
IFS_OLD=$IFS
IFS=:
n=0
m=0
for var in $(cat /home/$HOSTNAME/work/.BASE_DEVELOP_INFO/.$BASE.txt)
do
n=$(($n+1))
m=$(($m+1))
l=$(($m%4))
arr[${m}]=$var
printf " $COLOR_B %-40s $COLOR_E" $n:$var
# echo -e "\t${COLOR_G}$n: $var${COLOR_E}\c"
if [ $l -eq 0 ]
then echo -e "\t"
fi
done
echo " "
read c
DEVELOP=${arr[$c]}
echo -e "${COLOR_B}CHOIC BASE DEVELOP:${COLOR_E}$DEVELOP${COLOR_E}"
#编译类型:debug eng user
echo -e "\n选择debug或eng类型"
echo -e "\n选择编译类型:$LINE_TAB${COLOR_B}1: DEBUG \n\t2: ENG \n\t3: USER ${COLOR_E}"
read u
if [ $u -eq 1 ];
then BY=debug
elif [ $u -eq 2 ];
then BY=eng
elif [ $u -eq 3 ];
then BY=release
else
echo " ${COLOR_R}未知编译类型${COLOR_E}"
exit 1
fi
#输入MK编译名
echo -e "\n输入 .mul 编译名:"
read d
#MK=${arr[$d]}
MK=$d
echo -e "\n${COLOR_B}IP= $IP BASE= $BASE DEVELOP= $DEVELOP MAKEFILE= $MK COMPILING= $BY${COLOR_E}"
echo -e "${COLOR_R}>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CODE START>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>${COLOR_E}"
DIRNAME=$MK-$BY-$today
mkdir $DIRNAME && cd $DIRNAME
#获取BASE最新的分支信息到本地 base.txt 文件中
git clone git@$IP:$BASE && cd ./$BASE && git checkout $DEVELOP && git pull && git branch -a | grep remotes/origin/ | awk -F/ '{print $3}'|sed ':x;N;s/\n/:/;b x' >/home/$HOSTNAME/work/.BASE_DEVELOP_INFO/.$BASE.txt
#连接192.168.1.2上传最新的BASE分支信息
ftp -i -n < open 192.168.1.2
user ubuntu .
binary
cd Driver_only/BASE_DEVELOP_INFO/
lcd /home/$HOSTNAME/work/.BASE_DEVELOP_INFO/
prompt
put .$BASE.txt
close
bye
!
#echo "shangchuan ok" >>/home/$HOSTNAME/Desktop/3.txt
#编译部分
echo -e "${COLOR_G}>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>COMPILING START>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>${COLOR_E}"
./mk $BY $MK n
}
#环境配置信息
function config_info(){
echo -e "\n${COLOR_B}***********************************${COLOR_R}Compile Environment Configuration Information${COLOR_E}${COLOR_B}***********************************${COLOR_E}\n"
echo -e "${COLOR_G}PLATFORM:${COLOR_E}${COLOR_R} ${CPU}${COLOR_E}"
echo -e "${COLOR_G}COMPILING:${COLOR_E}${COLOR_R}${COMPING}${COLOR_E}"
echo -e "${COLOR_G}MAKEFILE:${COLOR_E}${COLOR_R}$MAKEFILE${COLOR_E}"
echo -e "${COLOR_G}LCM\t:${COLOR_E} ${COLOR_R}$LCM${COLOR_E}"
echo -e "${COLOR_G}CAMERA\t:${COLOR_E}${COLOR_R}$IMAGESENSOR${COLOR_E}"
echo -e "${COLOR_G}LENS\t:${COLOR_E}${COLOR_R}$LENS${COLOR_E}"
echo -e "${COLOR_G}MODEM\t:${COLOR_E}${COLOR_R}$MODEM${COLOR_E}"
echo -e "\n${COLOR_B}*******************************************************************************************************************${COLOR_E}"
}
function ly_open_mk(){
nautilus $ENV_DIR_PWD/resource/$ZB/
gedit $ENV_DIR_PWD/resource/$ZB/$MK.mak
}
function ly_open_lcm(){
echo -e "$COLOR_R*****************LCM List Information*****************$COLOR_E"
#提取对应BASE分支信息
n=0
m=0
for var in $LCM
do
arr[${m}]=$var
echo -e "\t ${COLOR_B}${n}:$var$COLOR_E"
n=$(($n+1))
m=$(($m+1))
done
echo -e "${COLOR_R}Please choice LCM number:${COLOR_E}"
read choice
[ -z "`echo $choice|sed -n '/^[0-9]$/p'`" ] && echo -e "$COLOR_R error :number 0-9$COLOR_E" && exit 1
[ $choice -gt $n ] && echo -e "$COLOR_R error:'${choice}'不存在的选项$COLOR_E" && exit 1
nautilus ${ENV_DIR_PWD}/${LY_KERNEL_LCM_DIR}/${arr[$choice]}/
nautilus ${ENV_DIR_PWD}/${LY_LK_LCM_DIR}/${arr[$choice]}/
}
function ly_open_cam(){
echo -e "$COLOR_R********************CAM List Information********************$COLOR_E"
#提取对应BASE分支信息
n=0
m=0
for var in $IMAGESENSOR
do
arr[${m}]=$var
echo -e "\t $COLOR_B$n:$var$COLOR_E"
n=$(($n+1))
m=$(($m+1))
done
echo -e "${COLOR_R}Please choice CAM number:${COLOR_E}"
read choice
[ -z "`echo $choice|sed -n '/^[0-9]$/p'`" ] && echo -e "$COLOR_R error :number 0-9$COLOR_E" && exit 1
[ $choice -gt $n ] && echo -e "$COLOR_R error:'${choice}'不存在的选项$COLOR_E" && exit 1
nautilus ${ENV_DIR_PWD}/${LY_KERNEL_CAM_DIR}/${arr[$choice]}/
nautilus ${ENV_DIR_PWD}/${LY_HAL_CAM_DIR}/${arr[$choice]}/
}
function ly_open(){
case $1 in
"lcm") ly_open_lcm ; return 0 ;;
"cam")
ly_open_cam ; return 0 ;;
"kcam")
dir=$LY_KERNEL_CAM_DIR
;;
*)
echo -e "$COLOR_R error:不存在的参数 $COLOR_E" && exit 1
;;
esac
nautilus $dir
}
function ly_cp_lcm(){
if [ -z $1 ]; then
#jian wenjianjia
local TIME=`date +%m%d_%H%M`
local name=${CPU}_${MK}_LCM_${TIME}
local dir=${DESKTOP}/${name}
else
dir=$1
fi
echo -e "$COLOR_R*******************LCM COPY List******************$COLOR_E"
#提取对应BASE分支信息
n=0
m=0
for var in $LCM
do
arr[${m}]=$var
echo -e "\t$COLOR_B$n:$var$COLOR_E"
n=$(($n+1))
m=$(($m+1))
done
echo -e "${COLOR_R}Please Choice LCM Number(,):${COLOR_E}"
read choice
OLDIFS=$IFS;IFS=', '
for j in $choice;do
[ -z "`echo $j|sed -n '/^[0-9]$/p'`" ] && echo -e "$COLOR_R error :number 0-9$COLOR_E" && exit 1
[ $j -gt $n ] && echo -e "$COLOR_R error:'${choice}'不存在的选项$COLOR_E" && exit 1
[ ! -d "$dir/kernel" ] && mkdir -p ${dir}/kernel
[ ! -d "$dir/lk" ] && mkdir -p ${dir}/lk
cp -rf ${ENV_DIR_PWD}/${LY_LK_LCM_DIR}/${arr[j]} $dir/lk
cp -rf ${ENV_DIR_PWD}/${LY_KERNEL_LCM_DIR}/${arr[j]} $dir/kernel
done
if [ -z $1 ] ;then
echo -e "${COLOR_G}Open File: $dir${COLOR_E}" && nautilus $dir
fi
IFS=$OLDIFS
}
# 复制cam源码
function ly_cp_cam(){
if [ -z $1 ]; then
#jian wenjianjia
local TIME=`date +%m%d_%H%M`
local name=${CPU}_${MK}_CAM_${TIME}
local dir=${DESKTOP}/${name}
else
dir=$1
fi
echo -e "$COLOR_R*******************CAM COPY List******************$COLOR_E"
#提取对应BASE分支信息
n=0
m=0
for var in $IMAGESENSOR
do
arr[${m}]=$var
echo -e "\t$COLOR_B$n:$var$COLOR_E"
n=$(($n+1))
m=$(($m+1))
done
echo -e "${COLOR_R}Please Choice CAM Number(,):${COLOR_E}"
read choice
OLDIFS=$IFS;IFS=', '
for j in $choice;do
[ -z "`echo $j|sed -n '/^[0-9]$/p'`" ] && echo -e "$COLOR_R error :number 0-9$COLOR_E" && exit 1
[ $j -gt $n ] && echo -e "$COLOR_R error:'${choice}'不存在的选项$COLOR_E" && exit 1
[ ! -d "$dir/kernel" ] && mkdir -p $dir/kernel
[ ! -d "$dir/hal" ] && mkdir -p $dir/hal
cp -rf ${ENV_DIR_PWD}/${LY_HAL_CAM_DIR}/${arr[j]} $dir/hal
cp -rf ${ENV_DIR_PWD}/${LY_KERNEL_CAM_DIR}/${arr[j]} $dir/kernel
done
if [ -z $1 ] ;then
echo -e "${COLOR_G}Open File: $dir${COLOR_E}" && nautilus $dir
fi
IFS=$OLDIFS
}
function ly_b() {
local TIME=`date +%m%d_%H%M`
if [ -z $1 ]; then
local name=${CPU}_${MK}_${TIME}
[ ! -d "${DESKTOP}/${name}" ] && mkdir ${DESKTOP}/${name}
elif [ $# -eq 1 ]; then
if [ "$1" == "lcm" ]; then
name=${CPU}_${MK}_LCM_${TIME}
mkdir -p ${DESKTOP}/${name}
ly_cp_lcm ${DESKTOP}/${name}
elif [ "$1" == "cam" ]; then
name=${CPU}_${MK}_CAM_${TIME}
mkdir -p ${DESKTOP}/${name}
ly_cp_cam ${DESKTOP}/${name}
else
echo “${1}”没有这个命令
fi
elif [ $# -eq 2 ]; then
echo
if [ "$1" == "cam" ] && [ "$2" != "lcm" ]; then
echo error:$1 $2
elif [ "$1" == "lcm" ] && [ "$2" != "cam" ]; then
echo error:$1 $2
fi
name=${CPU}_${MK}_LCM_CAM_${TIME}
mkdir -p ${DESKTOP}/${name}
ly_cp_lcm ${DESKTOP}/${name}
ly_cp_cam ${DESKTOP}/${name}
else
echo error -b 3个参数
exit 1
fi
#检索OUT目录下需要下载的.bin 文件
cd $OUT
download_file=`cat ${OUT}/*_Android_scatter.txt|grep -C 1 "is_download.*true"|grep file_name|cut -d ':' -f 2|sort|uniq`
download_file=`echo $download_file`
echo -e "$COLOR_B********************正在打包中********************$COLOR_E"
ly_tar_out ${DESKTOP}/${name}/${name}.tar.gz $download_file *_Android_scatter.txt
if [ $? == 0 ]; then
echo -e "\n${COLOR_B}**************************************************${COLOR_E}"
zenity --question --text "是否打开生成文件路径?\n${desktop}/${name}" --ok-label "打开" --cancel-label="取消" --title="打包完成" --width=400 --height=200 \
&& echo -e "\n${COLOR_G}打开文件路径:${COLOR_E}${COLOR_R}${DESKTOP}/${name}${COLOR_E}" \
&& echo -e "\n${COLOR_B}**************************************************${COLOR_E}" && nautilus ${DESKTOP}/${name}
else
rm -rf ${DESKTOP}/${name}
exit 1
fi
}
function ly_tar_out() {
set -o pipefail
if [ $# -lt 2 ]; then
echo "Error: argvment error : {file2|directory2} ..."
exit 1
fi
max=`du -c ${@#$1}|tail -1`
[ $? != 0 ] && rm -rf $tmpfifo && exit 1
max=`echo $max|cut -d ' ' -f 1`
#du -c 中间的空格不是ascii的,用echo可以转换为ascii的
tmpfifo=/tmp/tmpfifo_MT6580
#echo ${@#$1}
[ ! -e $tmpfifo ] && mkfifo $tmpfifo
(
trap "echo;exit 1" 10
while read line
do
if [ "tar:" == "`echo $line | cut -d ' ' -f 1`" ]; then
num=`echo $line|cut -d ' ' -f 2`
if [ -z `echo $num|grep "\<[0-9]*\>"` ]; then
echo "打包失败: ${line#* }"
rm -rf $tmpfifo;exit 1
fi
else
nowfile=$line
fi
((per=num*1000/max))
tput el
echo -ne "${COLOR_G}\r 当前打包进度:${COLOR_E}${COLOR_R}${per}%${COLOR_E} ${COLOR_G}打包文件:${COLOR_E}${COLOR_R}${nowfile}${COLOR_E}\r${COLOR_E}"
done<$tmpfifo
rm -rf $tmpfifo
tput el
echo -e "${COLOR_R}\r \n打包完成, $nowfile 目标文件:`du $1 -sh`${COLOR_E}"
)&
child_PID=$!
trap "kill -10 ${child_PID}" INT TERM
tar -zcvf $@ --checkpoint=1000 --checkpoint-action=echo="%u" --totals >$tmpfifo 2>$tmpfifo
return_value=$?
wait ${child_PID} || echo " 打包被终止"
#echo $? , $return_value
return ${return_value}
}
function ly_error_info(){
cd ${ENV_DIR_PWD}
echo -e "${COLOR_B}--------------------------------------------------------------$1 Error Info----------------------------------------------------------${COLOR_E}"
cat update.log | grep -C 5 --color=auto -n "error:"
echo -e "${COLOR_R}-------------------------------------------------------------------------------------------------------------------------------------${COLOR_E}"
}
function ly_clean_lcm(){
LY_OUT_LK=${OUT}/obj/BOOTLOADER_OBJ
#echo ${OUT_MTK_MACH_TYPE}
LY_OUT_LK_LCM=${LY_OUT_LK}/build-${OUT_MTK_MACH_TYPE}/dev/lcm/*
LY_OUT_KERNEL=${OUT}/obj/KERNEL_OBJ
LY_OUT_KERNEL_LCM=${LY_OUT_KERNEL}/drivers/misc/mediatek/lcm/*
echo -e "${COLOR_R}rm -rf $LY_OUT_LK_LCM${COLOR_E}"
rm -rf $LY_OUT_LK_LCM
echo -e "${COLOR_R}rm -rf $LY_OUT_KERNEL_LCM${COLOR_E}"
rm -rf $LY_OUT_KERNEL_LCM
}
function ly_clean_cam(){
LY_OUT_STATIC_LIBRARIES=${OUT}/obj/STATIC_LIBRARIES
LY_OUT_CAMERACUSTOM=${LY_OUT_STATIC_LIBRARIES}/libcameracustom.*
echo -e "${COLOR_R}rm -rf ${LY_OUT_CAMERACUSTOM}${COLOR_E}"
rm -rf ${LY_OUT_CAMERACUSTOM}
if [ -d "${OUT}/obj_arm/STATIC_LIBRARIES" ];then
echo -e "${COLOR_R}rm -rf ${OUT}/obj_arm/STATIC_LIBRARIES/libcameracustom.*${COLOR_E}"
rm -rf ${OUT}/obj_arm/STATIC_LIBRARIES/libcameracustom.*
fi
}
function ly_mk_pl()
{
cd ${ENV_DIR_PWD}
echo "qingkong" > update.log
cd ${ENV_DIR_PWD} && echo -e "Start Install Command:${COLOR_R}./mk $COMPING $MK u pl${COLOR_E}" && ./mk $COMPING $MK u pl
tail -n 3 update.log | grep "make completed successfully" >>/home/$HOSTNAME/lyscript_log.txt
if [ $? != 0 ]; then
ly_error_info PL
exit 1
fi
}
function ly_mk_lk()
{
cd ${ENV_DIR_PWD}
echo "qingkong" > update.log
cd ${ENV_DIR_PWD} && echo -e "Start Install Command:${COLOR_R}./mk $COMPING $MK u lk${COLOR_E}" && ./mk $COMPING $MK u lk
tail -n 3 update.log | grep "make completed successfully" >>/home/$HOSTNAME/lyscript_log.txt
if [ $? != 0 ]; then
ly_error_info LK
exit 1
fi
}
function ly_mk_k()
{
cd ${ENV_DIR_PWD}
rm -rf ${OUT}/obj/KERNEL_OBJ/drivers/* && echo -e "${COLOR_R}rm -rf ${OUT}/obj/KERNEL_OBJ/drivers/*${COLOR_E}"
echo "qingkong" > update.log
cd ${ENV_DIR_PWD} && echo -e "Start Install Command:${COLOR_R}./mk $COMPING $MK u bootimage ${COLOR_E}" && ./mk $COMPING $MK u bootimage
tail -n 3 update.log | grep "make completed successfully" >>/home/$HOSTNAME/lyscript_log.txt
if [ $? != 0 ]; then
ly_error_info K
exit 1
fi
}
function ly_mk_remake()
{
#echo "qingkong" > compiling.log
cd ${ENV_DIR_PWD} && echo -e "Start Install Command:${COLOR_R} ./mk $COMPING $MK n ${COLOR_E}" && ./mk $COMPING $MK n
# tail -n 3 compiling.log | grep "make completed successfully" >>/home/$HOSTNAME/lyscript_log.txt
#if [ $? != 0 ]; then
#ly_error_info ReMake
#exit 1
#fi
}
function ly_mk_lcm(){
ly_clean_lcm
ly_mk_lk
ly_mk_k
}
function ly_mk_hal(){
ly_clean_cam
cd ${ENV_DIR_PWD}
echo "qingkong" > update.log
echo -e "Start Install Command:${COLOR_R} ./mk $COMPING $MK m $LY_HAL ${COLOR_E}" && ./mk $COMPING $MK m $LY_HAL 2>&1 | tee update.log
tail -n 3 update.log | grep "make completed successfully" >>/home/$HOSTNAME/lyscript_log.txt
if [ $? == 0 ]; then
cd ${ENV_DIR_PWD} && echo -e "Start Install Command:${COLOR_R} ./mk $COMPING $MK u snod ${COLOR_E}" && ./mk $COMPING $MK u snod
else
ly_error_info Hal
exit 1
fi
}
function ly_mk_cam(){
ly_mk_k
ly_mk_hal
}
ly_shangchuan(){
DAY=`date +%m`
nautilus ftp://192.168.1.2/Driver_only/software/$DAY
}
if [ $# -eq 0 ]; then
config_info
exit 0
elif [ $# -eq 1 ]; then
case "$1" in
"-v"|"-version")
ly_v
exit 0
;;
"-s"|"-S")
ly_shangchuan
exit 0
;;
"-h"|"--help"|"-H")
ly_help
exit 0
;;
"-t"|"-T")
flash_tool
exit 0
;;
"-b"|"-B")
ly_b
exit 0
;;
"-o"|"-c"|"-O"|"-C")
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R}“${1}” 缺少参数${COLOR_E}"
exit 1
;;
"-p"|"-P")
lypullcode
exit 0
;;
"-u")
if [ `hostname` != "lishaokai" ]; then
ly_update
echo -e "${COLOR_G} lyscript 已更新为最新版本${COLOR_E}"
else
echo "I AM MANGEMENT!!!"
fi
#exit 0
;;
"-new"|"-n")
ly_mk_remake
exit 0
;;
"lk")
ly_mk_lk
exit 0
;;
"k")
ly_mk_k
exit 0
;;
"lcm")
ly_mk_lcm
exit 0
;;
"hal")
ly_mk_hal
exit 0
;;
"cam")
ly_mk_cam
exit 0
;;
"pl")
ly_mk_pl
exit 0
;;
*)
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R}“${1}” 没有这个参数${COLOR_E}"
exit 1
;;
esac
elif [ $# -eq 2 ]; then
if [ $2 == "lcm" ] || [ $2 == "cam" ] || [ $2 == "mk" ]; then
case "$1" in
"-b") ly_b $2 ;;
"-c") ly_cp_${2} ;;
"-o") ly_open_$2 ;;
*)
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R}没有这个参数${COLOR_E}"
exit 1
;;
esac
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R}参数错误${COLOR_E}"
exit 1
fi
elif [ $# -eq 3 ]; then
case "$1" in
"-b")
ly_b $2 $3
;;
"-c")
if [ "$2" == "lcm" ] && [ "$3" == "cam" ]; then
local c_TIME=`date +%m%d_%H%M`
local c_name=${CPU}_${MK}_LCM_CAM_${TIME}
local c_dir=${DESKTOP}/${name}
ly_cp_lcm $out_dir
ly_cp_cam $out_dir
else
echo -e "${COLOR_G}Error${COLOR_E}:${COLOR_R}参数错误 $2 $3${COLOR_E}"
exit 1
fi
;;
*)
echo "参数多"
exit 1
;;
esac
else
echo "参数过多"
exit 1
fi
如果你看完这篇博文,觉得对你有帮助,并且愿意付赞助费,那么我会更有动力写下去。