Shell脚本解析ipa包及info.plist文件

2019-08-09  本文已影响0人  张聪_2048

一、脚本语句

具体脚本语句如下,里面有详细的代码注释,这里不再赘述

#!/bin/sh


# 使用方法
# sh disposeIpa.sh xxx.ipa

# 当前脚本的目录定义为基础目录
# basePath=$(dirname $0)
basePath=$(cd "$(dirname "$0")";pwd)
echo "基础目录地址 basePath : $basePath"

# ipa路径
ipaFilePath=${1}
if [ ! -f "$ipaFilePath" ]; then
    echo "未找到ipa包 $ipaFilePath"
    exit 2
fi


# 当前ipa解压路径
temIpaDirName="TempPayload"
temIpaDirPath="${basePath}/${temIpaDirName}"
echo "当前ipa解压路径 temIpaDirPath : $temIpaDirPath"

# 删除临时解包目录
if [ -d "$temIpaDirPath" ]; then
    echo "删除临时解包目录 rm ${temIpaDirPath}"
    rm -rf "${temIpaDirPath}"
fi

# 解包IPA
if [[ -f "$ipaFilePath" ]]; then
    echo "unzip $ipaFilePath begin ..."
    unzip "$ipaFilePath" -d "$temIpaDirPath"
fi 

# 定位到 *.app 目录及 info.plist
appDir="$temIpaDirPath/Payload/`ls "$temIpaDirPath/"Payload`"
lcmInfoPlist="${appDir}/Info.plist"
echo "info.plist文件路径 lcmInfoPlist : $lcmInfoPlist"

# 获取app的名称、版本号、build号
appName=`/usr/libexec/PlistBuddy -c "Print :CFBundleName" $lcmInfoPlist`
echo "appName : $appName"
appVersion=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" $lcmInfoPlist`
echo "appVersion : $appVersion"
appBuild=`/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" $lcmInfoPlist`
echo "appBuild : $appBuild"
appBundleId=`/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" $lcmInfoPlist`
echo "appBundleId : $appBundleId"

echo "恭喜操作成功!!!"

二、使用示例

将上述代码复制粘贴到 disposeIpa.sh 文件中,并执行脚本:sh disposeIpa.sh xxx.ipa

shell使用示范.png shell使用结果.png
上一篇下一篇

猜你喜欢

热点阅读