-
Notifications
You must be signed in to change notification settings - Fork 0
/
xcodebump.sh
1521 lines (1372 loc) · 42.5 KB
/
xcodebump.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# STEmacsModelines:
# -*- Shell-Unix-Generic -*-
#
# This script does the following:
# 1. Update the Xcode marketing version string (CFBundleShortVersionString) to
# the releaseVersion supplied.
# 2. Increment the Xcode build number (CFBundleVersion) to the bundleVersion
# supplied or increment an existing number.
# 3. Commit changes to git.
# 4. Generate a tag to identify the commit the release/build and tag the commit.
#
# Dependencies:
# - Gnu Grep is required to support PCRE regex. On OSX you will have to install
# this version of grep. Use homebrew. See instructions below.
#
# - Gnu Sed is required to support case insensitive match/replace. On OSX you
# will have to install this version sed. Use homebrew. See instructions below.
#
# Installation:
# - Copy this script and the xcodebump-example.cfg file into a directory at
# the root of your home folder:
# >mkdir ~/.xcodebump
# >cp xcodebump.sh ~/.xcodebump/xcodebump.sh
# >chmod 755 ~/.xcodebump/xcodebump.sh
# >cp xcodebump-example.cfg ~/.xcodebump/xcodebump-example.cfg
# >chmod 644 ~/.xcodebump/xcodebump-example.cfg
# >ln -s ~/.xcodebump/xcodebump.sh ~/bin/xcodebump
#
# Copyright (c) 2014-2016 Mark Eissler
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
PATH_GIT="/usr/bin/git"
PATH_CUT="/usr/bin/cut"
PATH_HEAD="/usr/bin/head"
PATH_FIND="/usr/bin/find"
PATH_CP="/bin/cp"
PATH_RM="/bin/rm"
PATH_TOUCH="/usr/bin/touch"
PATH_BASENAME="/usr/bin/basename"
# Install gnu grep via homebrew... (this will not symlink for you)
#
# >brew tap homebrew/dupes
# >brew install homebrew/dupes/grep
#
# This will install the new grep as "ggrep" to avoid any conflicts with the BSD
# version of grep native to OSX.
#
PATH_GREP="/usr/local/bin/ggrep"
# Install gnu sed via homebrew... (this will not symlink for you)
#
# >brew tap homebrew/dupes
# >brew install gnu-sed
#
# This will install the new sed as "gsed" to avoid any conflicts with the BSD
# version of sed native to OSX.
#
PATH_SED="/usr/local/bin/gsed"
###### NO SERVICABLE PARTS BELOW ######
VERSION=1.2.2
PROGNAME=`basename $0`
# Where are we?
#
PATH_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# standard config file location
PATH_CONFIG=".xcodebump.cfg"
PATH_CONFIG_EXAMPLE="${PATH_SCRIPT}/xcodebump-example.cfg"
PATH_PLIST_BUDDY="/usr/libexec/PlistBuddy"
# reset internal vars (do not touch these here)
DEBUG=0
ADDCONFIG=0
FORCEEXEC=0
FETCHINFO=0
GETOPT_OLD=0
TARGETNAME=""
TAG_PREFIX="build"
EMPTYPREFIX=0
MAKERELEASE=0
BUILDNUM=-1
BUILDNUM_START=1
BUILDVER=-1
BUILDVER_START="1.0.0"
PATH_PLIST=""
# standard BSD sed is called by cleanString(); we will find this
PATH_STD_SED=""
# podspec support
PATH_PODSPEC=""
PODSPEC_URL=""
PODSPEC_BRANCH_REL="master"
PODSPEC_BRANCH_DEV="develop"
UPDATEPODSPEC=0
#
# FUNCTIONS
#
function usage {
if [ ${GETOPT_OLD} -eq 1 ]; then
usage_old
else
usage_new
fi
}
function usage_new {
cat << EOF
usage: ${PROGNAME} [options] releaseVersion
Update the marketing and build numbers for the xcode project. This script will
grab the info from the command line or configuration file.
OPTIONS:
-a, --add-config Adds config example to current directory
-b, --build buildNumber Sets build to buildNumber specified
-d, --debug Turn debugging on (increases verbosity)
-c, --path-config cFilePath Path to config file (overrides default)
-l, --path-plist iFilePath Path to target Info.plist file (disables search)
-p, --prefix tagPrefix String to prepend to generated commit tag
-e, --empty-prefix Sets tagPrefix to an empty string
-r, --release Create a final release
-t, --target targetName Sets target to work on
-s, --path-podspec sFilePath Path to podspec file (disables search)
-u, --update-podspec Update podspec file (for Cocoapod libraries)
-w, --url-podspec podspecUrl Podspec file source url
-i, --info Show keys/values from Info.plist and podspec
-f, --force Execute updates without user prompt
-h, --help Show this message
-v, --version Output version of this script
NOTE: If Podspec file source url does not end with a ".git" file extension, the
"targetName.git" string will be appended to the url.
EOF
}
# support for old getopt (non-enhanced, only supports short param names)
#
function usage_old {
cat << EOF
usage: ${PROGNAME} [options] releaseVersion
Update the marketing and build numbers for the xcode project. This script will
grab the info from the command line or configuration file.
OPTIONS:
-a Adds config example to current directory
-b buildNumber Sets build to buildNumber specified
-d Turn debugging on (increases verbosity)
-c cFilePath Path to config file (overrides default)
-l iFilePath Path to target Info.plist file (disables search)
-p tagPrefix String to prepend to generated commit tag
-e Sets tagPrefix to an empty string
-r Create a final release
-t targetName Sets target to work on
-s sFilePath Path to podspec file (disables search)
-u Update podspec file (for Cocoapod libraries)
-w podspecUrl Podspec file source url
-f Execute updates without user prompt
-i Show keys/values from Info.plist and podspec
-h Show this message
-v Output version of this script
NOTE: If Podspec file source url does not end with a ".git" file extension, the
"targetName.git" string will be appended to the url.
EOF
}
function version {
echo ${PROGNAME} ${VERSION};
}
# cleanString
#
# Pass a variable name and this function will determine its current value, clean
# up the value, and then assign it back to the variable. This is tricky because
# we will dereference the var in order to access its value.
#
# Given a variable ${example} - or - $example, you will want to access this
# function like this:
#
# cleanString example
#
# Not:
#
# cleanString ${example} - or - cleanString $example
#
# Because the latter two will past the value and not the name of the variable.
# Which means we wouldn't be able to dereference it and assign a new value.
#
function cleanString {
# remove quotes (leading or trailing, single or double)
local t
eval t=\$${1}
if [ -n "${t}" ]; then
# fetch name of variable passed in arg1
_argVarName=\$${1}
# get the current value of the variable
_argVarValue=`eval "expr \"${_argVarName}\""`
# clean up the value (1) - remove leading/trailing quotes (single or double)
_argVarValue_Clean=$(echo ${_argVarValue} | ${PATH_STD_SED} "s/^[\'\"]//" | ${PATH_STD_SED} "s/[\'\"]$//" );
# clean up the value (2) - convert encoded values to unencoded
_argVarValue_Clean=$(echo ${_argVarValue_Clean} | ${PATH_STD_SED} 's@%3D@=@g' | ${PATH_STD_SED} 's@%3A@:@g' | ${PATH_STD_SED} 's@%2F@\\/@g' );
# assign the cleaned up value to the variable passed in arg1
eval "${1}=\${_argVarValue_Clean}"
fi
}
# Support for urlEncode and urlDecode string manipulation.
#
export LANG=C
# urlEncode()
#
# Encode a string to html encoded.
#
# See: http://blogs.gnome.org/shaunm/2009/12/05/urlencode-and-urldecode-in-sh/
#
urlencode() {
local arg
arg="$1"
while [[ "$arg" =~ ^([0-9a-zA-Z/:_\.\-]*)([^0-9a-zA-Z/:_\.\-])(.*) ]] ; do
echo -n "${BASH_REMATCH[1]}"
printf "%%%X" "'${BASH_REMATCH[2]}'"
arg="${BASH_REMATCH[3]}"
done
# the remaining part
echo -n "$arg"
}
# urlDecode()
#
# Decode an html encoded string.
#
# See: http://blogs.gnome.org/shaunm/2009/12/05/urlencode-and-urldecode-in-sh/
#
function urlDecode() {
arg="$1"
i="0"
while [ "$i" -lt ${#arg} ]; do
c0=${arg:$i:1}
if [ "x$c0" = "x%" ]; then
c1=${arg:$((i+1)):1}
c2=${arg:$((i+2)):1}
printf "\x$c1$c2"
i=$((i+3))
else
echo -n "$c0"
i=$((i+1))
fi
done
}
# isNumber()
#
function isNumber() {
if [[ ${1} =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then
echo 1; return 0
else
echo 0; return 1
fi
}
# semverToArray()
#
# Split a SemVer format version string (e.g. "1.0.0") into an array. We will
# write back the array to the variable that is passed to us.
#
# Call like this:
#
# BUILDSTRING="1.2.3"
# semverToArray BUILDSTRING
# for e in "${BUILDSTRING[@]}"
# do
# echo $e
# done
#
function semverToArray() {
if [ -n "${1}" ]; then
# fetch name of variable passed in arg1
_argVarName=\$${1}
# get the current value of the variable
_argVarValue=`eval "expr ${_argVarName}"`
# clean up the value (1) - remove leading/trailing quotes (single or double)
_argVarValue_Clean=$(echo ${_argVarValue} | ${PATH_SED} "s/^[\'\"]//" | ${PATH_SED} "s/[\'\"]$//" );
# split into array, parse on dot character
array=(${_argVarValue_Clean//./ })
# if [[ ${DEBUG} -ne 0 ]]; then
# for i in "${array[@]}"
# do
# echo $i
# done
# fi
# assign the array to the variable passed in arg1
eval "${1}=(\${array[@]})"
fi
}
# isSemver()
#
# Check if string arg is in SemVer (1.0.0) format.
#
# NOTE: The return pattern here is structured so that all of the following tests
# will work because we echo a value and set the return status...
#
# Using return value (function exit status captured in $?):
# STAT=$(isSemver "${BUILDVER}")
# STAC=$?
# if [[ ${STAC} -eq 0 ]]; then
#
# - or -
# Using echo value (captured in output from function):
# if [[ $(isSemver "${BUILDVER}") -eq 1 ]]; then
#
# - or -
# Using echo value (captured in output from function):
# if [ $(isSemver "${BUILDVER}") -eq 1 ]; then
#
function isSemver() {
if [[ -z "${1}" ]]; then
echo 0; return 1;
fi
isSemverArgArray=${1}
semverToArray isSemverArgArray
if [[ ${#isSemverArgArray[@]} -ne 3 ]]; then
echo 0; return 1;
fi
# check each element to make sure it is a number
for elem in "${isSemverArgArray[@]}"
do
isSemverArgArrayElement=${elem}
if [[ $(isNumber "${isSemverArgArrayElement}") -eq 0 ]] || [[ ${isSemverArgArrayElement} -lt 0 ]]; then
echo 0; return 1;
fi
done
# got this far, we must have a valid SemVer string!
echo 1; return 0;
}
# isGnuGrep()
#
# Checks for GNU Grep which supports PCRE (perl-type regex).
#
function isGnuGrep() {
if [[ -z "${1}" ]]; then
echo 0; return 1;
fi
RESP=$({ ${1} --version | ${PATH_HEAD} -n 1; } 2>&1 )
RSLT=$?
if [[ ! $RESP =~ "${1} (GNU grep)" ]]; then
echo 0; return 1;
fi
echo 1; return 0;
}
# isGnuSed()
#
# Checks for GNU Sed which supports case insensitive match and replace.
#
function isGnuSed() {
if [[ -z "${1}" ]]; then
echo 0; return 1;
fi
RESP=$({ ${1} --version | ${PATH_HEAD} -n 1; } 2>&1 )
RSLT=$?
if [[ ! $RESP =~ "${1} (GNU sed)" ]]; then
echo 0; return 1;
fi
echo 1; return 0;
}
# isPathWriteable()
#
# Checks if a given path (file or directory) is writeable by the current user.
#
function isPathWriteable() {
if [ -z "${1}" ]; then
echo 0; return 1
fi
# path is a directory...
if [[ -d "${1}" ]]; then
local path="${1%/}/.test"
local resp rslt
resp=$({ ${PATH_TOUCH} "${path}"; } 2>&1)
rslt=$?
if [[ ${rslt} -ne 0 ]]; then
# not writeable directory
echo 0; return 1
else
# writeable directory
${PATH_RM} "${path}"
echo 1; return 0
fi
fi
# path is a file...
if [ -w "${1}" ]; then
# writeable file
echo 1; return 0
else
# not writeable file
echo 0; return 1
fi
# and if we fall through...
echo 0; return 128
}
# addConfig()
#
# Copy config example file to directory specified.
#
function addConfig() {
if [[ -z "${1}" ]]; then
echo 0; return 1;
fi
local _directory="${1}"
if [[ -d "${_directory}" && $(isPathWriteable "${_directory}") -ne 1 ]] \
|| [[ ! -d "${_directory}" ]]; then
exit 1
echo 0; return 1;
fi
local _configFile="$(${PATH_BASENAME} "${PATH_CONFIG_EXAMPLE}")"
RESP=$({ ${PATH_CP} "${PATH_CONFIG_EXAMPLE}" "${_directory}/.${_configFile}"; } 2>&1 )
RSLT=$?
if [[ ${RSLT} -ne 0 ]]; then
echo 0; return 1;
fi
echo 1; return 0;
}
# findInfoPlist()
#
# Search the current directory for a TARGET/Info.plist file, if not found try
# looking for a TARGET-Info.plist file.
#
function findInfoPlist() {
_plistPath=$({ $PATH_FIND "./${TARGETNAME}" -type f -name "Info.plist" -print0; } 2>&1 )
if [[ -z ${_plistPath} || $? -ne 0 ]]; then
# try looking for a TARGET-Info.plist file...
_plistPath=$({ $PATH_FIND . -type f -name "${TARGETNAME}-Info.plist" -print0; } 2>&1 )
if [[ -z ${_plistPath} || $? -ne 0 ]]; then
echo ""; return 1;
fi
fi
echo ${_plistPath}; return 0
}
# findPodspec()
#
# Search the current directory for a TARGET.podspec file.
#
function findPodspec() {
_podspecPath=$({ $PATH_FIND . -type f -name "${TARGETNAME}.podspec" -print0; } 2>&1 )
if [[ -z ${_podspecPath} || $? -ne 0 ]]; then
echo ""; return 1;
fi
echo ${_podspecPath}; return 0
}
# readInfoPlist()
#
# Read keys/values from the Info.plist passed by string in arg1, and write back
# as a new string-coded hash in the variable referenced by arg2.
#
# Call like this:
#
# readInfoPlist plistPathStr, plistArray
#
# The resulting array is string-coded like this:
#
# array=( \
# "cfBundleShortVersionString=>'value'" \
# "cfBundleVersion=>'value'" \
# ")
#
function readInfoPlist() {
local _cfBundleShortVersionString
local _cfBundleVersion
local _array=()
local _length
if [[ -z "${1}" ]] || [[ ! -r "${1}" ]]; then
_array=( "error=>'Not found'" )
elif [[ -n "${2}" ]]; then
# fetch name of variable passed in arg1
_argVarName=\$${2}
_cfBundleShortVersionString=$({ $PATH_PLIST_BUDDY -c "Print CFBundleShortVersionString" "${1}"; } 2>&1 )
if [[ $? -ne 0 ]]; then
_cfBundleShortVersionString="";
fi
_cfBundleVersion=$({ $PATH_PLIST_BUDDY -c "Print CFBundleVersion" "${1}"; } 2>&1 )
if [[ $? -ne 0 ]]; then
_cfBundleVersion="";
fi
_array=( \
"cfBundleShortVersionString=>'${_cfBundleShortVersionString}'" \
"cfBundleVersion=>${_cfBundleVersion}" \
)
fi
length=${#_array[*]}
for ((i=0; i<=$(($length -1)); i++))
do
eval "${2}[$i]=\"${_array[$i]}\""
done
}
# showInfoPlist()
#
# Show keys/values from the Info.plist passed by string in arg1.
#
# Call like this:
#
# showInfoPlist plistPathStr
#
function showInfoPlist() {
local _cfBundleShortVersionString
local _cfBundleVersion
_plistInfo=()
readInfoPlist "${1}" _plistInfo
if [[ ${#_plistInfo[@]} -gt 0 ]]; then
# declare -a hash=("${_plistInfo[@]}")
# for elem in "${hash[@]}"
for elem in "${_plistInfo[@]}"
do
if [ "${DEBUG}" -ne 0 ]; then
echo "Key: ${elem%%=>*}"
echo "Value: ${elem#*=>}"
fi
local key=${elem%%=>*}
local val=${elem#*=>}
case "${key}" in
cfBundleShortVersionString) _cfBundleShortVersionString="${val}";;
cfBundleVersion) _cfBundleVersion="${val}";;
error) # format errors
local _val=${val};
cleanString _val;
echo "Plist Error: ${_val}";
;;
*) ;;
esac
done
fi
if [[ -n ${_cfBundleShortVersionString} ]]; then
cleanString _cfBundleShortVersionString
echo "Plist CFBundleShortVersionString: ${_cfBundleShortVersionString}"
fi
if [[ -n ${_cfBundleVersion} ]]; then
cleanString _cfBundleVersion
echo "Plist CFBundleVersion: ${_cfBundleVersion}"
fi
}
# readPodspec()
#
# Read keys/values from the Target.podspec passed by string in arg1, and write
# back as a new string-coded hash in the variable referenced by arg2.
#
# Call like this:
#
# readPodspec podspecPathStr, podspecArray
#
# The resulting array is string-coded like this:
#
# array=( \
# "version=>'value'" \
# "source=>'value'" \
# ")
#
function readPodspec() {
local _podspecVersion
local _podspecSource
local _array=()
local _length
if [[ -z "${1}" ]] || [[ ! -r "${1}" ]]; then
_array=( "error=>'Not found'" )
elif [[ -n "${2}" ]]; then
# fetch name of variable passed in arg1
_argVarName=\$${2}
_podspecVersion=$({ ${PATH_SED} -n -r "s|.*version\s*=\s*[\'\"]([0-9a-z\.\-]*)[\'\"]$|\1|gIp" ${1}; } 2>&1)
if [[ $? -ne 0 ]]; then
_podspecVersion="";
fi
_podspecSource=$({ ${PATH_SED} -n -r "s|.*source\s*=\s*(\{(.*)\})$|\1|gIp" ${1}; } 2>&1)
if [[ $? -ne 0 ]]; then
_podspecSource="";
fi
_array=( \
"version=>'${_podspecVersion}'" \
"source=>${_podspecSource}" \
)
fi
length=${#_array[*]}
for ((i=0; i<=$(($length -1)); i++))
do
eval "${2}[$i]=\"${_array[$i]}\""
done
}
# showPodspec()
#
# Show keys/values from the Target.podspec passed by string in arg1.
#
# Call like this:
#
# showPodspec podspecPathStr
#
function showPodspec() {
local _podspecVersion
local _podspecSource
_podInfo=()
readPodspec "${1}" _podInfo
if [[ ${#_podInfo[@]} -gt 0 ]]; then
# declare -a hash=("${_podInfo[@]}")
# for elem in "${hash[@]}"
for elem in "${_podInfo[@]}"
do
if [ "${DEBUG}" -ne 0 ]; then
echo "Key: ${elem%%=>*}"
echo "Value: ${elem#*=>}"
fi
local key=${elem%%=>*}
local val=${elem#*=>}
case "${key}" in
version) _podspecVersion="${val}";;
source) _podspecSource="${val}";;
error) # format errors
local _val=${val};
cleanString _val;
echo "Podspec Error: ${_val}";
;;
*) ;;
esac
done
fi
if [[ -n ${_podspecVersion} ]]; then
cleanString _podspecVersion
echo "Podspec Version: ${_podspecVersion}"
fi
if [[ -n ${_podspecSource} ]]; then
echo "Podspec Source: ${_podspecSource}"
fi
}
# promptConfirm()
#
# Confirm a user action. Input case insensitive.
#
# Returns "yes" or "no" (default).
#
function promptConfirm() {
read -p "$1 ([y]es or [N]o): "
case $(echo $REPLY | tr '[A-Z]' '[a-z]') in
y|yes) echo "yes" ;;
*) echo "no" ;;
esac
}
# parse cli parameters
#
# Our options:
# --add-config, a
# --build, b
# --path-config, c
# --path-plist, l
# --prefix, p
# --empty-prefix, e
# --release, r
# --target, t
# --path-podspec, s
# --update-podspec, u
# --url-podspec, w
# --debug, d
# --force, f
# --info, i
# --help, h
# --version, v
#
params=""
getopt -T > /dev/null
if [ $? -eq 4 ]; then
# GNU enhanced getopt is available
PROGNAME=`basename $0`
params="$(getopt --name "$PROGNAME" --long add-config,build:,path-config:,path-plist:,prefix:,empty-prefix,release,target:,path-podspec:,update-podspec,url-podspec:,force,info,help,version,debug --options ab:c:l:p:ert:s:uw:fihvd -- "$@")"
else
# Original getopt is available
GETOPT_OLD=1
PROGNAME=`basename $0`
params="$(getopt ab:c:l:p:ert:s:uw:fihvd "$@")"
fi
# check for invalid params passed; bail out if error is set.
if [ $? -ne 0 ]
then
usage; exit 1;
fi
eval set -- "$params"
unset params
while [ $# -gt 0 ]; do
case "$1" in
-a | --add) cli_ADDCONFIG=1; ADDCONFIG=${cli_ADDCONFIG};;
-b | --build) cli_BUILDNUM="$2"; shift;;
-c | --path-config) cli_CONFIGPATH="$2"; shift;;
-l | --path-plist) cli_PLISTPATH="$2"; shift;;
-p | --prefix) cli_TAG_PREFIX="$2"; shift;;
-e | --empty-prefix) cli_EMPTYPREFIX=1; EMPTYPREFIX=${cli_EMPTYPREFIX};;
-r | --release) cli_MAKERELEASE=1; MAKERELEASE=${cli_MAKERELEASE};;
-t | --target) cli_TARGETNAME="$2"; shift;;
-s | --path-podspec) cli_PODSPECPATH="$2"; shift;;
-u | --update-podspec) cli_UPDATEPODSPEC=1; UPDATEPODSPEC=${cli_UPDATEPODSPEC};;
-w | --url-podspec) cli_PODSPECURL="$2"; shift;;
-d | --debug) cli_DEBUG=1; DEBUG=${cli_DEBUG};;
-f | --force) cli_FORCEEXEC=1;;
-i | --info) cli_FETCHINFO=1; FETCHINFO=${cli_FETCHINFO};;
-v | --version) version; exit;;
-h | --help) usage; exit;;
--) shift; break;;
esac
shift
done
# Copy config example file and quit
#
if [ "${ADDCONFIG}" -eq 1 ]; then
echo
printf "Copying example config file to current directory... "
if [[ $(addConfig "${PWD}") -eq 0 ]]; then
printf "!!"
echo
echo "ABORTING. Unable to access Xcodebump output directory: ${PWD}"
echo "Must be a write permissions error."
echo
exit 1
fi
echo "Copied config file."
echo "Make sure you edit the file and rename it to \".xcodebump.cfg\"."
echo
exit 0
fi
if [ "${FETCHINFO}" -eq 0 ]; then
# Grab final argument (the release version aka BUILDVER)
shift $((OPTIND-1))
if [ -z "${1}" ]; then
echo "ABORTING. You must specify a releaseVersion string."
echo
usage
exit 1
else
cli_BUILDVER="${1}"
fi
fi
# Configure std sed
#
if [[ -n "${PATH_SED}" ]] && [[ -x "${PATH_SED}" ]]; then
PATH_STD_SED="${PATH_SED}"
elif [[ -x "/usr/bin/sed" ]]; then
PATH_STD_SED="/usr/bin/sed"
else
echo
echo "FATAL. Something is wrong with this system. Unable to find standard sed."
echo
exit 1
fi
# Grab our config file path from the cli if provided
#
if [ -n "${cli_CONFIGPATH}" ]; then
cleanString cli_CONFIGPATH;
PATH_CONFIG=${cli_CONFIGPATH};
fi
# load config
echo
printf "Checking for a config file... "
if [ -s "${PATH_CONFIG}" ] && [ -r "${PATH_CONFIG}" ]; then
source "${PATH_CONFIG}" &> /dev/null
else
printf "!!"
echo
echo "ABORTING. The xcodebump config file ("${PATH_CONFIG}") is missing or empty!"
echo
_configDir=$(${PATH_DIRNAME} "${PATH_CONFIG}")
_configExample="${_configDir}/.xcodebump-example.cfg"
if [ -f "${_configExample}" ]; then
echo "It looks like the example config file exists in the same location: "
echo
echo " ${_configExample}"
echo
echo "Did you remember to customize and appropriately rename a copy of the example?"
echo
fi
unset _configDir
unset _configExample
exit 1
fi
echo "Found: ${PATH_CONFIG}"
echo
# Verify grep version
printf "Checking for a compatible version of grep... "
if [[ $(isGnuGrep "${PATH_GREP}") -eq 0 ]]; then
printf "!!"
echo
echo "ABORTING. Couldn't find a compatible version of grep. GNU grep is required."
echo
exit 1
fi
echo "Found: ${PATH_GREP}"
echo
# Verify sed version
printf "Checking for a compatible version of sed... "
if [[ $(isGnuSed "${PATH_SED}") -eq 0 ]]; then
printf "!!"
echo
echo "ABORTING. Couldn't find a compatible version of sed. GNU sed is required."
echo
exit 1
fi
echo "Found: ${PATH_SED}"
echo
# Update standard sed to configured value (maybe have been overriden in cfg)
PATH_STD_SED="${PATH_SED}"
##
## SAFE TO CALL GNU GREP AND GNU SED FROM HERE ON IN!
##
# Clean up config file parameters
#
cleanString TARGETNAME
cleanString TAG_PREFIX
cleanString BUILDVER
cleanString BUILDVER_START
cleanString BUILDNUM
cleanString BUILDNUM_START
cleanString PATH_PLIST
cleanString PATH_PODSPEC
cleanString PODSPEC_URL
cleanString PODSPEC_BRANCH_DEV
cleanString PODSPEC_BRANCH_REL
# Rangle our vars (EARLY)
#
# We need TARGETNAME, and possibly PLISTPATH and PODSPECPATH before we run
# FETCHINFO calls.
#
if [ -n "${cli_TARGETNAME}" ]; then
cleanString cli_TARGETNAME;
TARGETNAME=${cli_TARGETNAME};
fi
if [ -n "${cli_PLISTPATH}" ]; then
cleanString cli_PLISTPATH;
PATH_PLIST=${cli_PLISTPATH};
fi
if [ -n "${cli_PODSPECPATH}" ]; then
cleanString cli_PODSPECPATH;
PATH_PODSPEC=${cli_PODSPECPATH};
fi
##
## IF FETCHINFO IS ON, SHOW INFO AND QUIT!
##
if [ "${FETCHINFO}" -eq 1 ]; then
echo "Showing current values..."
if [ -n "${TARGETNAME}" ]; then
if [ -z "${PATH_PLIST}" ]; then
PATH_PLIST=$(findInfoPlist)
fi
if [ -z "${PATH_PODSPEC}" ]; then
PATH_PODSPEC=$(findPodspec)
fi
fi
showInfoPlist "${PATH_PLIST}"
if [ -r "${PATH_PODSPEC}" ]; then
showPodspec "${PATH_PODSPEC}"
fi
exit 0
fi
# Rangle our vars (LATER)
#
# The cli_VARS will override config file vars!!
#
if [ -n "${cli_FORCEEXEC}" ]; then
FORCEEXEC=${cli_FORCEEXEC};
fi
if [ -n "${cli_BUILDVER}" ]; then
# check that the BUILDVER provided is in semVer format
cleanString cli_BUILDVER
BUILDVER=${cli_BUILDVER}
if [[ $(isSemver "${BUILDVER}") -eq 0 ]]; then
echo "ABORTING. You have specified a non-conforming releaseVersion. The"
echo "release version string must conform to SemVer (Semantic Versioning)"
echo "format."
exit 1
fi
if [ "${DEBUG}" -ne 0 ]; then
echo "BUILDVER set from cli: ${BUILDVER}"
fi
fi
if [ -n "${BUILDVER_START}" ]; then
if [[ $(isSemver "${BUILDVER_START}") -eq 0 ]]; then
echo "ABORTING. You have specified a non-conforming BUILDVER_START. The"
echo "BUILDVER_START string must conform to SemVer (Semantic Versioning)"
echo "format."
exit 1
fi
else
# use BUILDVER for BUILDVER_START
BUILDVER_START=${BUILDVER};
fi
if [ -n "${cli_BUILDNUM}" ]; then
cleanString cli_BUILDNUM;
BUILDNUM=${cli_BUILDNUM};
# if a number, buildnum must not be negative
if [[ $(isNumber "${BUILDNUM}") -eq 1 ]] && [[ ${BUILDNUM} -lt 0 ]]; then
echo "ABORTING. You have specified a buildNumber with a negative value!"
exit 1
fi
# if a string, warn the user!
if [[ $(isNumber "${BUILDNUM}") -eq 0 ]] && [[ ! -z ${BUILDNUM} ]]; then
echo "WARNING. You have specificed a buildNumber that is a string."
##