sed -i 's/a/bb/g' file 将file中的a替换为bb 并输出log信息
sed -i '/;/d' file 删除以;开头的行
完善的ubuntuAnroid源码调试脚本
#!/bin/bash
source build/envsetup.sh > /dev/null
LOG_TAG="[Tuliyuan:CustomDebugScript]"
# 32 绿色
# 31 红色
# 33 棕色
# 34 蓝色
# 35 紫色
# 36 兰绿色
# 37 白色
function printMainLog()
{
local LOG_MAIN="\033[37m$1\033[0m"
echo -e "${LOG_TAG} ${LOG_MAIN}"
}
function printErrorLog()
{
local LOG_ERROR="\033[31m$1\033[0m"
echo -e "${LOG_TAG} ${LOG_ERROR}"
}
function printWarnLog()
{
local LOG_ERROR="\033[33m$1\033[0m"
echo -e "${LOG_TAG} ${LOG_ERROR}"
}
function printInfoLog()
{
local LOG_INFO="\033[36m$1\033[0m"
echo -e "${LOG_TAG} ${LOG_INFO}"
}
function printSuccessLog()
{
local LOG_SUCCESS="\033[32m$1\033[0m"
echo -e "${LOG_TAG} ${LOG_SUCCESS}"
}
function usage()
{
echo "USAGE: [-m module_name] [-a] [-c] [-o] [-p]"
echo "WHERE: -m = build module"
echo " -a = build android"
echo " -c = clean All build"
echo " -o = build otapackage"
echo " -p = pack img"
exit 1
}
PAR_BUILD_ANDROID=false
PAR_BUILD_CLEAN=false
PAR_BUILD_OTAPACKAGE=false
PAR_PACK_BIN=false
PAR_BUILD_MOUDLE=false
PAR_BUILD_MOUDLE_NAME=""
moduleType=""
PAR_BUILD_MOUDLE_APP=false
PAR_BUILD_MOUDLE_SO=false
PAR_BUILD_MOUDLE_JAR=false
LOCAL_DIR_NAME=`gettop`
local_company="visionmagic"
local_product_target=`get_build_var TARGET_PRODUCT`
local_android_version=`get_build_var PLATFORM_VERSION`
local_android_arch=`get_build_var TARGET_ARCH`
local_version_key=""
local_cpu_manufacture="mtk"
local_prop_custom_verison_num="ro.custom.version.release"
local_target_out="";
local_out_parition="system/"
local_out_target_priv="app/"
local_out_app_path="system/app"
do_main(){
if [ "${local_product_target}" = "aosp_arm" ]; then
printInfoLog "You need choose lunch combo first!! Using lunch xxx-userdebug To Complete Enviroment Build"
exit -1;
fi
#以full_开头的正则表达式匹配
if [[ "$local_product_target" =~ ^full_* ]]; then
#printInfoLog "This is Mtk Project"
local_product_target=`echo ${local_product_target} | sed 's/full_//g'`
fi
if [[ "$1" == "" ]]; then
usage
exit 1;
fi
local debug_module_path=""
while getopts "m:acop" OPT;
do
case $OPT in
m)
debug_module_path="$(pathmod $OPTARG)"
parse_moudle $OPTARG
PAR_BUILD_MOUDLE_NAME="$OPTARG"
printMainLog "Will Debug Module $OPTARG "
PAR_BUILD_MOUDLE=true
;;
a)
printMainLog "Will build android"
PAR_BUILD_ANDROID=true
;;
c)
printMainLog "Will clean All"
PAR_BUILD_CLEAN=true
;;
o)
printMainLog "Will build otapackage"
PAR_BUILD_OTAPACKAGE=true
;;
p)
printMainLog "Will build pack bin"
PAR_PACK_BIN=true
;;
?)
usage
;;
esac
done
if [ ! -d "out/target/product/${local_product_target}" ]; then
printErrorLog "There was no out dir!!!!You Need Compile Project First!"
exit -1;
fi
local_target_out="out/target/product/${local_product_target}"
if [ $PAR_BUILD_MOUDLE == true ]; then
printMainLog "will compile Module $2"
debug_module $2 $debug_module_path
return 0;
fi
if [ $PAR_BUILD_CLEAN == true ]; then
printMainLog "will clean project"
make clean
fi
if [ $PAR_BUILD_ANDROID == true ]; then
if [ -d "./device/rockchip" ]; then
if [ ! $PAR_BUILD_OTAPACKAGE == true ]; then
printMainLog "will make rockchip project without otapackage"
make installclean;./build.sh -Aup
fi
else
printMainLog "will make android"
make installclean;make -j8 2>&1 | tee build.log
fi
fi
if [ $PAR_BUILD_OTAPACKAGE == true ]; then
if [ -d "./device/rockchip" ]; then
printMainLog "will make rockchip android with otapackage"
./build.sh -Aoup
else
printMainLog "will make android with otapackage "
make -j8 otapackage 2>&1 | tee build_ota.log
fi
fi
if [ $PAR_PACK_BIN == true ]; then
if [ -d "./device/rockchip" ]; then
printMainLog "Rockchip command has already pack image into $pwd/rockdev"
else
versionNumber=`grep -r "$local_prop_custom_verison_num" out/target/product/${local_product_target}/vendor/build.prop | sed 's/'$local_prop_custom_verison_num='/''/g'`
printMainLog "$versionNumber"
croot
local binPath="$LOCAL_DIR_NAME/${local_product_target}_bin_$(date +%Y%m%d)"
if [ "$versionNumber" = "" ]; then
mkdir -p "$binPath"
cp -ra out/target/product/${local_product_target}/*.img $binPath
cp -ra out/target/product/${local_product_target}/*.bin $binPath
cp -ra out/target/product/${local_product_target}/*_Android_scatter.* $binPath
if [ $PAR_BUILD_OTAPACKAGE == true ]; then
cp -ra out/target/product/${local_product_target}/full_${local_product_target}-ota-*.zip $binPath/${versionNumber}_OTA.zip
cp -ra out/target/product/${local_product_target}/obj/PACKAGING/target_files_intermediates/full_${local_product_target}-target_files-*.zip $binPath/localUpdate.zip
fi
printSuccessLog "CopyFile Success!!!"
else
binPath="$LOCAL_DIR_NAME/${versionNumber}_bin"
mkdir -p "$binPath"
cp -ra out/target/product/${local_product_target}/*.img $binPath
cp -ra out/target/product/${local_product_target}/*.bin $binPath
cp -ra out/target/product/${local_product_target}/*_Android_scatter.* $binPath
if [ $PAR_BUILD_OTAPACKAGE == true ]; then
cp -ra out/target/product/${local_product_target}/full_${local_product_target}-ota-*.zip $binPath/${versionNumber}_OTA.zip
cp -ra out/target/product/${local_product_target}/obj/PACKAGING/target_files_intermediates/full_${local_product_target}-target_files-*.zip $binPath/${versionNumber}_FOTA.zip
fi
printSuccessLog "CopyFile Success!!!"
fi
fi
fi
}
function pathmod() {
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
return 1
fi
if [[ $# -ne 1 ]]; then
echo "usage: pathmod <module>" >&2
return 1
fi
if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
refreshmod || return 1
fi
local relpath=$(python -c "import json, os
module = '$1'
module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
if module not in module_info:
exit(1)
print(module_info[module]['path'][0])" 2>/dev/null)
if [ -z "$relpath" ]; then
echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
return 1
else
echo "$relpath"
fi
}
function refreshmod() {
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
return 1
fi
echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
# for the output of the next command
mkdir -p $ANDROID_PRODUCT_OUT || return 1
# Note, can't use absolute path because of the way make works.
m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
> $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
}
function parse_moudle(){
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
return 1
fi
if [[ $# -ne 1 ]]; then
echo "usage: pathmod <module>" >&2
return 1
fi
if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
refreshmod || return 1
fi
moduleType=$(python -c "import json, os
module = '$1'
module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
if module not in module_info:
exit(1)
print(module_info[module]['class'][0])" 2>/dev/null)
if [ "${moduleType}" == "APPS" ]; then
PAR_BUILD_MOUDLE_APP=true
printInfoLog "Compile Module $1 is Application *.apk "
elif [ "${moduleType}" == "SHARED_LIBRARIES" ]; then
PAR_BUILD_MOUDLE_SO=true
printInfoLog "Compile Module $1 is SharedLibraries *.so"
elif [ "${moduleType}" == "JAVA_LIBRARIES" ]; then
PAR_BUILD_MOUDLE_JAR=true
printInfoLog "Compile Module $1 is JavaLibraries *.jar "
else
printInfoLog "Compile Module $1 is ${moduleType}"
fi
}
function debug_module(){
local module_path=$2
local module_name=$1
croot
if [ $local_android_version -gt 8 ]; then
printInfoLog "Android Version is ${local_android_version}, Compile Command is : make ${module_name}"
make ${module_name}
else
printWarnLog "Android Version is ${local_android_version}, Compile Command is : mmm ${module_path}"
mmm ${module_path}
fi
if [ $? -eq 1 ]; then
printErrorLog "Compile Failed. Please Recheck Compile result"
return -1;
fi
adb root
if [ $? -eq 1 ]; then
printErrorLog "Adb root Failed. Please Recheck USB Device Connect State"
return 1;
fi
sleep 1s
adb remount
local outPutFilePath=$(python -c "import json, os
module = '${module_name}'
module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
if module not in module_info:
exit(1)
for val in module_info[module]['installed']:
print(val)" 2>/dev/null)
printInfoLog "\nNeed push following files: \n$outPutFilePath"
if [ "$outPutFilePath" == "" ];then
printErrorLog "No Installed Path, Maybe is a static library,Module Type is ${moduleType}"
exit 1;
fi
echo "$outPutFilePath" > tempFilePush.txt
while read eachline
do
#printMainLog "LINE: $eachline"
#裁剪box右侧的所有字符
target_file=${eachline#*$local_product_target}
printMainLog "push to ${target_file}"
adb push $eachline ${target_file}
done < tempFilePush.txt
rm -rf tempFilePush.txt
do_reboot
}
do_reboot(){
if read -t 3 -p $'We will reboot Android Device in 3 seconds, Press Enter Key to Stop Reboot? ' ret
then
if [ -z "$ret" ];then
printErrorLog "interput Reboot by youself!"
fi
else
echo -e "\n${LOG_TAG}\033[32m Android Device Rebooting ! \033[0m"
adb reboot
fi
}
#获取配置文件值
getProjectKey(){
local file=$1
local key=$2
if [ -f "${file}" ]; then
#local value=$(grep -v "^\s*#" ${file} | grep -w ${key} | tail -1 | sed 's#^[^=]*=\(.*\)$#\1#g' | sed 's#[[:space:]]##g')
local value=`grep -v "^\s*#" ${file} | grep -w ${key} | tail -1 | sed 's#^[^=]*=\(.*\)$#\1#g' | sed 's#[[:space:]]##g'`
fi
echo ${value}
}
do_main $1 $2