[Mac]shell文件中读取plist文件并实现shell中的数值计算

2018年01月14日 iOS 19条评论 阅读7589次

[Mac]shell文件中读取plist文件并实现shell中的数值计算

有篇文章在说明Mac下iOS工程自动打包的shell文件中有用到动态写iOS工程下的plist文件。

iOS工程下的Info.plist文件中有个CFBundleVersion的键,该键对应的值一般认为是内部维护的版本号,这个内部是相对于CFBundleShortVersionString的外部给用户看的版本号而说的。

关于CFBundleVersion应该如何设置,方案有很多,有些项目使用VCS(版本控制系统)中本次提交的版本号,有些项目使用日期,有些从1开始每次累计。

个人习惯,一般都是用从1开始累加的方式给CFBundleVersion设置值。鉴于此场景,shell中就必须要有读取上次plist中CFBundleVersion值并加1后跟新plist文件。

三步走:1、读取上次的CFBundleVersion;2、CFBundleVersion加1;3、给CFBundleVersion写入新加1后的值

1、读取上次的CFBundleVersion

plist操作还是用PlistBuddy, 位置在/usr/libexec/PlistBuddy。
读属性值是用Print命令,单纯读出来在终端打印的话很简单,

/usr/libexec/PlistBuddy -c "Print CFBundleVersion" JILENIAO/Infp.plist


但要赋值给变量,就要稍微加工一下了。

BUILD_CODE=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" JILENIAO/Infp.plist)


这样再echo $BUILD_CODE 就能输出plist文件中的内部版本号了。

2、CFBundleVersion加1
Mac下shell中的计算和其他语言稍有不同。加减乘除的话写+-*/是会被当做为字符串的,想让shell知道你是个表达式计算的话,需要expr处理。

BUILD_CODE=`expr $BUILD_CODE + 1`

注意:expr 中运算符前后必须要有一个空格,我最初忽略掉空格, 结果是死活不出来想要的加法结果。

3、给CFBundleVersion写入新加1后的值

这个就简单了,一个PlistBuddy的Set命令搞定

/usr/libexec/PlistBuddy -c "Set CFBundleVersion $BUILD_CODE" JILENIAO/Infp.plist


分享本次更新后的自动编译打包ipa的shell文件。



#!/bin/bash
#Author Jileniao.Net
SCHEMENAME='JILENIAO'
DATE=`date +%Y%m%d_%H%M`
SOURCEPATH=$( cd "$( dirname $0 )" && pwd)
IPAPATH=$SOURCEPATH
DISNAME=$SCHEMENAME"_"$DATE
ARCHNAME=$DISNAME.xcarchive
IPANAME=$DISNAME
ExportOptions='ExportOptions.plist'
INFOPLIST=$SCHEMENAME/Info.plist
BUNDLE_ID='net.jileniao.iosblog'
DISPLAY_NAME='极乐鸟'
VERSION_NAME='1.0.5'
#BUILD_CODE='153'
PROVISION_PROFILE='jileniao-dis'
# 测试版APP
if [ -n "$1" ]; then
  # extra parameter 1
fi
rm -rf ./build
rm main.jsbundle
rm main.jsbundle.meta
rm -rf ./Build
rm -rf ./ModuleCache
rm -rf ./Logs
xcodebuild clean
CURR=`pwd`
cd .. && react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios/
cd $CURR
# 先读取之前的BUILD_CODE,加1得到新的BUILD_CODE
BUILD_CODE=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $INFOPLIST)
BUILD_CODE=`expr $BUILD_CODE + 1`
# 设置编译参数
/usr/libexec/PlistBuddy -c "Set CFBundleDisplayName $DISPLAY_NAME" $INFOPLIST
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $VERSION_NAME" $INFOPLIST
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $BUILD_CODE" $INFOPLIST
/usr/libexec/PlistBuddy -c "Set CFBundleIdentifier $BUNDLE_ID" $INFOPLIST
/usr/libexec/PlistBuddy -c "Delete provisioningProfiles" $ExportOptions
/usr/libexec/PlistBuddy -c "Add provisioningProfiles dict" $ExportOptions
/usr/libexec/PlistBuddy -c "Add provisioningProfiles:$BUNDLE_ID string $PROVISION_PROFILE" $ExportOptions
# 构建
xcodebuild archive \
 -project JILENIAO.xcodeproj \
 -scheme $SCHEMENAME \
 -configuration Release \
 -archivePath $ARCHNAME \
 clean \
 build \
 -derivedDataPath ./
if [ -e $ARCHNAME ]; then
  echo "xcodebuild archive Successful"
else
  echo "xcodebuild archive Failed"
  exit 1
fi
# 导出ipa
xcodebuild -exportArchive \
 -archivePath $ARCHNAME \
 -exportPath $IPANAME \
 -exportOptionsPlist $ExportOptions
if [ -e $IPANAME ]; then
  echo "Export ipa Successful"
  open $IPAPATH
else
  echo "Export ipa Failed"
  exit 1
fi
#删除临时文件
rm -rf $ARCHNAME
rm -rf ./Build
rm -rf ./ModuleCache
rm -rf ./Logs



分享本文至:

WRITTEN BY

avatar
本文标签:shellmacPlistBuddy
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

19 条评论

  1. <a href="http://www.lvnailbar.com/aj-green-youth-jersey-nfli">aj green youth jersey</a> <a href="http://www.eisenhards.com/nike-kd-8-rojo-azul-zapatosh">nike kd 8 rojo azul</a> <a href="http://www.martinmakeup.com/air-max-90-negro-azul-zapatosk">air max 90 negro azul</a> <a href="http://www.dgrabovsky.com/the-north-face-girls-apex-elevation-jacket-northfaceh">the north face girls apex elevation jacket</a> <a href="http://www.madeinmyindia.com/adidas-originals-gazelle-trainers-in-rosa-schuhek">adidas originals gazelle trainers in rosa</a> <a href="http://www.manglammovers.com/nike-jordan-eclipse-r%C3%B8d-and-sort-skoi">nike jordan eclipse r酶d and sort</a>
    chocopictures http://www.chocopictures.com/

  2. <a href="http://www.chicksgolftoo.com/nike-roshe-jaune-and-noir-chaussuresl">nike roshe jaune and noir</a> <a href="http://www.alatteandapen.com/adidas-boost-solar-jaune-chaussuresl">adidas boost solar jaune</a> <a href="http://www.ugczapp.com/adidas-gazelle-gold-schwarz-schuhej">adidas gazelle gold schwarz</a> <a href="http://www.reijutu.com/frau-nike-air-max-2019-off-wei%C3%9F-triple-wei%C3%9F-schuhei">frau nike air max 2019 off wei脽 triple wei脽</a> <a href="http://www.promoldgauer.com/nike-air-presto-breathe-hvit-svart-obuvj">nike air presto breathe hvit svart</a> <a href="http://www.growemwell.com/adidas-originals-climacool-nero-scarpel">adidas originals climacool nero</a>
    networkqoffer http://www.networkqoffer.com/

  3. <a href="http://www.adanastarpen.com/hombres-asics-gel-lyte-5-amarillo-zapatosk">hombres asics gel lyte 5 amarillo</a> <a href="http://www.actconfident.com/coach-legacy-wristlet-coachh">coach legacy wristlet</a> <a href="http://www.erzurumihl.com/ua-micro-g-torch-blue-green-shoesj">ua micro g torch blue green</a> <a href="http://www.candctowingil.com/kvinders-nike-kd-8-appelsin-gr%C3%B8n-skoq">kvinders nike kd 8 appelsin gr酶n</a> <a href="http://www.onlysidekick.com/femmes-asics-gel-noosa-tri-9-gris-jaune-chaussuresl">femmes asics gel noosa tri 9 gris jaune</a> <a href="http://www.rmmassage.com/femmes-nike-lebron-12-noir-jaune-chaussuresq">femmes nike lebron 12 noir jaune</a>
    tmzred http://www.tmzred.com/

  4. <a href="http://www.spiritriver.net/air-jordan-cp3-ix-rosa-grigio-kurpesd">air jordan cp3 ix rosa grigio</a> <a href="http://www.ssrichardmontgomery.net/jordan-13-rosa-gr%C3%A5-for-salg-schuhec">jordan 13 rosa gr氓 for salg</a> <a href="http://www.starninedata.net/lebron-13-mid-gris-butyg">lebron 13 mid gris</a> <a href="http://www.stephandjeff.net/blanco-nike-air-force-1-high-top-zapatillas-scarpec">blanco nike air force 1 high top zapatillas</a> <a href="http://www.stmnetworks.net/nike-flyknit-agility-hombres-blanco-chaussuresf">nike flyknit agility hombres blanco</a> <a href="http://www.stulynn.net/nike-roshe-run-rojo-sole-butya">nike roshe run rojo sole</a>
    villacafaggio http://www.villacafaggio.net/

  5. <a href="http://www.ambitionagent.com/ralph-lauren-tees-navy-brown-poloz">ralph lauren tees navy brown</a> <a href="http://www.brensonford.com/jordan-captain-america-jaune-or-scarpeb">jordan captain america jaune or</a> <a href="http://www.dutting.com/denver-broncos-terrell-davis-womens-orange-nike-30-nfl-t-shirt-backer-nfls">denver broncos terrell davis womens orange nike 30 nfl t shirt backer</a> <a href="http://www.erickasouza.com/kd-7-money-gr%C3%B8nn-years-scarpeg">kd 7 money gr酶nn years</a> <a href="http://www.flyboardbc.com/nike-free-run-2-fonctionnement-chaussures-obuvc">nike free run 2 fonctionnement chaussures</a> <a href="http://www.mommypads.com/dam%C3%A4nner-air-jordan-retro-5-lila-orange-scarpea">dam盲nner air jordan retro 5 lila orange</a>
    goeaglepointe http://www.goeaglepointe.com/

  6. <a href="http://www.daunchbeauty.com/air-jordan-melo-m11-s%C3%B8lv-gr%C3%A5-scarpeb">air jordan melo m11 s酶lv gr氓</a> <a href="http://www.farenyuk.com/youth-cam-newton-jersey-black-nfls">youth cam newton jersey black</a> <a href="http://www.howellsolar.com/hombres-nike-free-run-5.0-v4-azul-naranja-scarpef">hombres nike free run 5.0 v4 azul naranja</a> <a href="http://www.immoetvous.com/hommes-nike-shox-deliver-bleu-or-obuvc">hommes nike shox deliver bleu or</a> <a href="http://www.janetsher.com/kobe-9-low-r%C3%B8d-and-bl%C3%A5-urban-dictionary-scarpea">kobe 9 low r酶d and bl氓 urban dictionary</a> <a href="http://www.johngerretsen.com/nike-tanjun-gr%C3%B8nn-bl%C3%A5-schuheb">nike tanjun gr酶nn bl氓</a>
    fpbsmeeting http://www.fpbsmeeting.com/

  7. <a href="http://www.abartz.com/nike-kd-7-marr%C3%B3n-oro-obuvd">nike kd 7 marr贸n oro</a> <a href="http://www.howatshives.com/adidas-prossoator-neroout-acquistare-butyd">adidas prossoator neroout acquistare</a> <a href="http://www.codedtalk.com/nike-shox-deliver-herre-sko-designers-obuvc">nike shox deliver herre sko designers</a> <a href="http://www.bcrailroad.com/nike-air-max-1-hvit-medium-gr%C3%A5-total-oransje-kurpesf">nike air max 1 hvit medium gr氓 total oransje</a> <a href="http://www.glutenfreebay.com/kvinders-nike-shox-deliver-orange-r%C3%B8d-kurpesa">kvinders nike shox deliver orange r酶d</a> <a href="http://www.dexterbowl.com/nike-foamposite-hyper-rosado-chaussuresc">nike foamposite hyper rosado</a>
    evameade http://www.evameade.com/

  8. <a href="http://www.epackproject.com/reebok-realflex-bl%C3%A5-scarpec">reebok realflex bl氓</a> <a href="http://www.flashuse.com/nike-air-max-2016-print-bleu-schuhef">nike air max 2016 print bleu</a> <a href="http://www.airtestuser.com/nike-free-run-2-hombres-todas-negro-corriendo-zapatos-uk-scarpeb">nike free run 2 hombres todas negro corriendo zapatos uk</a> <a href="http://www.bajigour.com/jordan-3-schwarz-atomic-volt-schuhee">jordan 3 schwarz atomic volt</a> <a href="http://www.calaforracs.com/nike-air-pegasus-92-premium-hommes-chaussure-fit-butyf">nike air pegasus 92 premium hommes chaussure fit</a> <a href="http://www.clboaiyy.com/how-to-clean-bianca-nike-cortez-obuve">how to clean bianca nike cortez</a>
    hebinomichi http://www.hebinomichi.com/

  9. avatar getdropmedia

    <a href="http://www.advertiseguns.com/air-jordan-retro-13-s%C3%B8lv-royal-bl%C3%A5-butya">air jordan retro 13 s酶lv royal bl氓</a> <a href="http://www.bodhiboxers.com/nfl-nike-baltimore-ravens-48-patrick-onwuasor-green-salute-to-service-mens-pullover-hoodie-nflu">nfl nike baltimore ravens 48 patrick onwuasor green salute to service mens pullover hoodie</a> <a href="http://www.chateaudefous.com/nike-zoom-winflo-3-lilla-himmelen-bl%C3%A5-kurpesb">nike zoom winflo 3 lilla himmelen bl氓</a> <a href="http://www.prinslabs.com/nike-air-jordan-alpha-1-schwarz-varsity-rot-wei%C3%9F-schuhec">nike air jordan alpha 1 schwarz varsity rot wei脽</a> <a href="http://www.solarishelp.com/nike-kyrie-2-rosa-braun-schuheg">nike kyrie 2 rosa braun</a> <a href="http://www.tioneo.com/mennns-asics-gel-noosa-tri-10-s%C3%B8lv-gr%C3%A5-kurpesc">mennns asics gel noosa tri 10 s酶lv gr氓</a>
    getdropmedia http://www.getdropmedia.com/

  10. avatar kfpcbsi0

    <a href="http://www.27ekv1k5.com/nike-zoom-pegasus-34-oro-blu-schuhef">nike zoom pegasus 34 oro blu</a> <a href="http://www.6d70wyis.com/reebok-classic-negro-butye">reebok classic negro</a> <a href="http://www.n43uaulr.com/adidas-tubular-runner-weave-sort-guld-butya">adidas tubular runner weave sort guld</a> <a href="http://www.a7yegxzb.com/adidas-projoator-lz-negro-negro-obuvb">adidas projoator lz negro negro</a> <a href="http://www.ez7joz51.com/jordan-6-gr%C3%B8n-bl%C3%A5-scarped">jordan 6 gr酶n bl氓</a> <a href="http://www.z6lxz01g.com/nike-mercurial-vapor-viii-fg-salg-schuhef">nike mercurial vapor viii fg salg</a>
    kfpcbsi0 http://www.kfpcbsi0.com/

  11. avatar accademiadeilincei

    <a href="http://www.dreamybelize.net/air-max-90-og-infrarosso-schuhee">air max 90 og infrarosso</a> <a href="http://www.drspa.net/unisex-nike-roshe-run-blum%C3%A4nner-rot-gr%C3%BCn-kurpesc">unisex nike roshe run blum盲nner rot gr眉n</a> <a href="http://www.dumaworks.net/nike-zoom-kobe-venom%C3%A4nneron-4-basketballe-schuhe-herren-butyf">nike zoom kobe venom盲nneron 4 basketballe schuhe herren</a> <a href="http://www.dylanhassinger.net/nike-air-presto-triple-negro-hair-scarpee">nike air presto triple negro hair</a> <a href="http://www.emergexplanning.net/nike-kobe-11-flyknit-or-vert-schuhea">nike kobe 11 flyknit or vert</a> <a href="http://www.emtecsolution.net/adidas-nmd-runner-triple-schwarz-reflective-gloves-kurpesc">adidas nmd runner triple schwarz reflective gloves</a>
    accademiadeilincei http://www.accademiadeilincei.net/

  12. avatar chieao

    <a href="http://www.hardingmarcom.com/nfl-demetrius-harris-womens-red-84-kansas-city-chiefs-nike-backer-slim-fit-long-sleeve-t-shirt-nflr">nfl demetrius harris womens red 84 kansas city chiefs nike backer slim fit long sleeve t shirt</a> <a href="http://www.mezgitofis.com/nike-mens-daquan-jones-elite-white-road-jersey-tennessee-titans-nfl-90-vapor-untouchable-nflx">nike mens daquan jones elite white road jersey tennessee titans nfl 90 vapor untouchable</a> <a href="http://www.resekipman.com/nike-free-5.0-infant-toddler-ni%C3%B1os-zapato-schuheg">nike free 5.0 infant toddler ni帽os zapato</a> <a href="http://www.sncforu.com/nike-free-tr-focus-flyknit-kvinners-training-sko-scarpeg">nike free tr focus flyknit kvinners training sko</a> <a href="http://www.stalksdesign.com/air-jordan-28-grigio-argento-kurpesf">air jordan 28 grigio argento</a> <a href="http://www.thesignsledge.com/femminile-asics-gel-kayano-20-viola-bianca-schuhef">femminile asics gel kayano 20 viola bianca</a>
    chieao http://www.chieao.com/

  13. avatar k3htroya

    <a href="http://www.k3htroya.com/jordan-super-fly-2-rot-kurpese">jordan super fly 2 rot</a> <a href="http://www.y7dbpccn.com/adidas-springblade-grigio-arancia-kit-schuheg">adidas springblade grigio arancia kit</a> <a href="http://www.z9b51ckf.com/nike-air-max-noir-zalando-scarpef">nike air max noir zalando</a> <a href="http://www.vt310g2y.com/adidas-climacool-ride-v-grigio-rosa-kurpesa">adidas climacool ride v grigio rosa</a> <a href="http://www.dhvwolje.com/adidas-nitrocharge-footbtout-bleu-vert-kurpesd">adidas nitrocharge footbtout bleu vert</a> <a href="http://www.v870k5rd.com/roshe-run-base-gr%C3%A5-geranium-r%C3%B8d-fade-obuva">roshe run base gr氓 geranium r酶d fade</a>
    k3htroya http://www.k3htroya.com/

  14. avatar donareseguros

    <a href="http://www.drmilliecalko.com/hommes-ralph-lauren-sweaters-gris-v-neck-polow">hommes ralph lauren sweaters gris v neck</a> <a href="http://www.jishnuguha.com/air-jordan-retro-5-low-negro-p%C3%BArpura-butyf">air jordan retro 5 low negro p煤rpura</a> <a href="http://www.joehalvorson.com/maschio-ralph-lauren-shirt-polo-blu-oxford-in-regular-fit-poloz">maschio ralph lauren shirt polo blu oxford in regular fit</a> <a href="http://www.proximityhome.com/zx-flux-sort-and-gr%C3%B8n-chaussuresf">zx flux sort and gr酶n</a> <a href="http://www.samexllc.com/lebron-12-grigio-and-arancia-marmalade-scarpef">lebron 12 grigio and arancia marmalade</a> <a href="http://www.sandeneuhofer.com/nike-san-francisco-49ers-customized-black-2016-pro-bowl-mens-stitched-nfl-elite-jersey-nfls">nike san francisco 49ers customized black 2016 pro bowl mens stitched nfl elite jersey</a>
    donareseguros http://www.donareseguros.com/

  15. avatar canditatenext

    <a href="http://www.heslaatours.com/nfl-nike-new-york-jets-54-avery-williamson-ash-one-color-t-shirt-nflw">nfl nike new york jets 54 avery williamson ash one color t shirt</a> <a href="http://www.prostekrasna.com/chicago-bulls-michael-jordan-hoodie-new-adult-size-medium-other-nflv">chicago bulls michael jordan hoodie new adult size medium other</a> <a href="http://www.altharmony.com/mens-nike-free-flyknit-3.0-grey-pink-skog">mens nike free flyknit 3.0 grey pink</a> <a href="http://www.cosmicupcake.com/billig-new-balance-574-herre-r%C3%B8d-skob">billig new balance 574 herre r酶d</a> <a href="http://www.btmtecled.com/chicago-white-sox-floppy-hat-diy-hata">chicago white sox floppy hat diy</a> <a href="http://www.torcgunstore.com/nike-lunarglide-8-pink-red-runningf">nike lunarglide 8 pink red</a>
    canditatenext http://www.canditatenext.com/

  16. avatar 7445o36p

    <a href="http://www.h8yuex60.com/schwarz-leder-nike-air-max-junior-butya">schwarz leder nike air max junior</a> <a href="http://www.bedkl965.com/nike-lebron-gul-hvit-scarpee">nike lebron gul hvit</a> <a href="http://www.0fn25hbu.com/ua-curry-3-gr%C3%B8n-bl%C3%A5-butyf">ua curry 3 gr酶n bl氓</a> <a href="http://www.ag367vcp.com/herren-nike-zoom-pegasus-32-gold-rot-butyf">herren nike zoom pegasus 32 gold rot</a> <a href="http://www.286zdvwi.com/nike-hyperdunk-2016-low-guld-gr%C3%A5-schuhea">nike hyperdunk 2016 low guld gr氓</a> <a href="http://www.cnvgx2q2.com/billig-jordan-7-chaussuresa">billig jordan 7</a>
    7445o36p http://www.7445o36p.com/

  17. avatar virtualxbox

    <a href="http://www.kareokiparty.com/purple-blue-womens-adidas-superstar-shoes-sneakere">purple blue womens adidas superstar shoes</a> <a href="http://www.barinotomotiv.com/nike-free-run-5.0-kvinders-lyser%C3%B8d-footc">nike free run 5.0 kvinders lyser酶d</a> <a href="http://www.trustnetgroup.com/all-red-nike-air-max-2016-skox">all red nike air max 2016</a> <a href="http://www.jehleflowers.com/air-jordan-future-black-glow-sportsd">air jordan future black glow</a> <a href="http://www.blogdalata.com/coach-madison-black-coachr">coach madison black</a> <a href="http://www.eonkraftwerke.com/limited-t.j.-ward-jersey-denver-broncos-43-lights-out-grey-nfle">limited t.j. ward jersey denver broncos 43 lights out grey</a>
    virtualxbox http://www.virtualxbox.com/

  18. avatar cierreplus

    <a href="http://www.divasdelface.com/dallas-cowboys-jersey-in-london-nflb">dallas cowboys jersey in london</a> <a href="http://www.whitegayshop.com/nike-roshe-run-mens-black-leather-shoesc">nike roshe run mens black leather</a> <a href="http://www.beautyestyle.com/womens-nike-free-5.0-v4-cheetah-leopard-zebra-running-shoes-skog">womens nike free 5.0 v4 cheetah leopard zebra running shoes</a> <a href="http://www.safeonproject.com/nike-wmns-air-max-1-black-leopard-sportse">nike wmns air max 1 black leopard</a> <a href="http://www.gagnetoo.com/billig-nike-air-force-1-high-kvinders-gr%C3%A5-runningd">billig nike air force 1 high kvinders gr氓</a> <a href="http://www.epiuenergia.com/memphis-grizzlies-customized-white-jersey-nflf">memphis grizzlies customized white jersey</a>
    [url=http://www.cierreplus.com/]cierreplus[/url]

  19. avatar larrystoverjr

    <a href="http://www.jazzoutlaw.com/kvinders-sort-and-s%C3%B8lv-nike-shox-schuhed">kvinders sort and s酶lv nike shox</a> <a href="http://www.fifteenforty.com/nike-air-max-95-jacquard-verde-azul-chaussuresd">nike air max 95 jacquard verde azul</a> <a href="http://www.cagiad.com/kobe-8-gr%C3%A5-volt-for-salg-obuvf">kobe 8 gr氓 volt for salg</a> <a href="http://www.magicwristlet.com/adizero-f50-sort-and-orange-kurpese">adizero f50 sort and orange</a> <a href="http://www.fleksys.com/roshe-run-nike-negro-schuhed">roshe run nike negro</a> <a href="http://www.teamworkpress.com/femminile-asics-gel-quantum-360-blu-rosa-butyg">femminile asics gel quantum 360 blu rosa</a>
    larrystoverjr http://www.larrystoverjr.com/

欢迎留言




用户登录

sitemap