-
Notifications
You must be signed in to change notification settings - Fork 3
/
zanata-functions
executable file
·809 lines (745 loc) · 23 KB
/
zanata-functions
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
#!/bin/bash -eu
### NAME
### zanata-functions
###
### SYNOPSIS
### zanata-functions help
### zanata-functions help-list-sections
### zanata-functions help-section <section>
### zanata-functions run <function> [functionArguments] ...
###
### DESCRIPTION
### This program can be sourced by other program and serve as library,
### or run the individual function.
###
### You can just source this program to use all the functions.
### Or run as standalone by using:
###
### zanata-functions run <function> [functionArguments]
###
### If you don't want to clone the whole zanata-scripts, you can invoke this
### by:
###
### curl -q https://raw.githubusercontent.com/zanata/zanata-scripts/master/zanata-functions | bash -s - [opt1...]
###
###
### FUNCTIONS
function zanata_functions_get_path(){
shopt -s extdebug
declare -F zanata_functions_get_path| sed -e 's|^[^ ]* [0-9]* ||'
shopt -u extdebug
}
###
### zanata_help_raw <script>
### Print raw help (the lines start with '###') of a script.
zanata_help_raw(){
local script="$1"
[ -z "$script" ] && script=$0
sed -r -n -e '/^### ?/ {s|^### ?||p}' $script
}
zanata_help_parse_raw(){
declare -gA ZanataHelpSections
local currentSection=''
local regex='^[A-Z][A-Z_]*'
while read ;do
if [[ $REPLY =~ $regex ]];then
currentSection=$REPLY
elif [[ -n $currentSection ]];then
[[ -n ${ZanataHelpSections[$currentSection]:-} ]] && ZanataHelpSections[$currentSection]+='\n'
ZanataHelpSections[$currentSection]+="$REPLY"
fi
done
}
###
### zanata_help_init <script>
### Read help from script and zanata-env.sh when ZanataHelpSections is not defined
zanata_help_init(){
local script="$1"
if [[ -z ${ZanataHelpSections:-} ]]; then
zanata_help_parse_raw < <(zanata_help_raw $script)
[[ -n ${ZanataEnvSh:-} && -r $ZanataEnvSh ]] && zanata_help_parse_raw < <(zanata_help_raw "$ZanataEnvSh")
fi
}
###
### zanata_help_list_sections <script>
### List the help sections of a script.
function zanata_help_list_sections(){
local script="$1"
zanata_help_init "$script"
for section in "${!ZanataHelpSections[@]}"; do
echo $section
done
}
###
### zanata_help_section <script> <section>
### Print the specified help section of a script.
function zanata_help_section(){
local script="$1"
local section="$2"
zanata_help_init "$script"
echo -e "${ZanataHelpSections[$section]}"
}
###
### zanata_script_help_short <script>
### Print the short help of a script.
function zanata_script_help_short(){
local script=$1
zanata_help_init "$script"
MustHaveSectionArray=( SYNOPSIS ARGUMENTS OPTIONS ENVIRONMENT )
for section in "${MustHaveSectionArray[@]}"; do
if [[ -n ${ZanataHelpSections[$section]:-} ]]; then
echo $section
echo -e "${ZanataHelpSections[$section]}\n"
fi
done
}
###
### zanata_script_help <script> <section>
### Print the detail help of a script.
function zanata_script_help(){
local script=$1
zanata_help_init "$script"
HeaderSectionArray=( NAME SYNOPSIS DESCRIPTION ARGUMENTS OPTIONS )
FooterSectionArray=( EXIT_STATUS ENVIRONMENT FILES NOTES BUGS EXAMPLE SEE_ALSO )
declare -a MidSectionArray
for section in "${HeaderSectionArray[@]}"; do
if [[ -n ${ZanataHelpSections[$section]:-} ]]; then
echo $section
echo -e "${ZanataHelpSections[$section]}\n"
fi
done
## Other sections should be in middle
for section in "${!ZanataHelpSections[@]}"; do
for sec in "${HeaderSectionArray[@]}"; do
[[ $sec == $section ]] && break
done
[[ $sec == $section ]] && continue
for sec in "${FooterSectionArray[@]}"; do
[[ $sec == $section ]] && break
done
[[ $sec == $section ]] && continue
echo $section
echo -e "${ZanataHelpSections[$section]}\n"
done
for section in "${FooterSectionArray[@]}"; do
if [[ -n ${ZanataHelpSections[$section]:-} ]]; then
echo $section
echo -e "${ZanataHelpSections[$section]}\n"
fi
done
}
###
### echo_stderr [args] ...
### Echo to stderr. Args are same with echo.
### If ZANATA_QUITE_MODE=1, this function does nothing.
function echo_stderr(){
if [[ ${ZANATA_QUIET_MODE-} != 1 ]];then
echo "$@" > /dev/stderr
fi
}
###
### branch_prepare <branch> [command line args]
### Prepare and checkout correct branch
### <branch> can be actual branch name, or RELEASING for the releasing branch.
###
### This assumes the module can be determine by either
### 1. part of $0, e.g. zanata-maven-release-platform
### 2. First non-optional argument ($1)
### 3. JenkinMode=1 (which branch is ready already)
###
### Assigned Variables:
### RepoName: Repository name
### Module: (Deprecated) Same as RepoName.
### ShiftOffset: how many argument need to be shift
### Prints: shift offset (either 0 or 1)
function branch_prepare(){
local branch=$1
shift
ShiftOffset=0
## Get module name
RepoName=$(get_module $0)
if [[ $RepoName = '-' ]];then
## See whether RepoName is provided in first argument
RepoName=$(get_module ${1-})
if [[ $RepoName = '-' ]];then
if [[ ${JustUseCurrentDirectoryMode-} -ne 1 ]];then
failed ${EXIT_FATAL_UNKNOWN_MODULE} "RepoName is not given and not in JustUseCurrentDirectoryMode"
else
## Default module in JustUseCurrentDirectoryMode is the directory name
RepoName=$(basename $PWD)
fi
else
## RepoName provided in first argument
ShiftOffset=1
fi
fi
if [[ ${JustUseCurrentDirectoryMode-} -eq 0 ]];then
print_status " ensure $RepoName exists"
ensure_repo $RepoName
cd ${WORK_ROOT}/${RepoName}
if [[ $branch = "RELEASING" ]];then
WorkingBranch=$(get_releasing_branch)
else
WorkingBranch=$branch
fi
print_status " checking out $WorkingBranch of $RepoName"
checkout_branch $RepoName $WorkingBranch $WORK_ROOT
else
WorkingBranch=$(get_current_branch)
fi
## Make sure the work tree is clean
git clean -fdX
Module=$RepoName
}
###
### get_current_branch
### Return current branch name, or HEAD when detach
function get_current_branch(){
git rev-parse --abbrev-ref HEAD
}
###
### checkout_branch <repoName> <branch> [parentDir]
### checkout <branch> for <repoName>.
### Note that this won't change to the repoName directory.
function checkout_branch(){
local repoName=$1
local branch=$2
local parentDir=${3-}
[ -z $parentDir ] && parentDir=${PWD}
cd ${parentDir}/${repoName}
git remote update origin > /dev/stderr
git checkout ${branch} > /dev/stderr
git pull > /dev/stderr
cd - > /dev/stderr
}
### detect_remote_repo_latest_version <URL> <tagGlob>
### This does not need to clone the repository to get the latest version
detect_remote_repo_latest_version(){
local url=$1
local tagGlob=$2
git ls-remote --tags "$url" "refs/tags/$tagGlob" | awk -F '-' '{ print $2, ($3 == "" )?"zfinal":$3, $4}' | sort -V | tr ' ' '-' | sed -e 's/-zfinal-//g' | tail -n 1
}
###
### detect_module_tag [-q] <-j|module>
### Print latest tag of module
function detect_module_tag(){
local module=
local justUseCurrentDirectoryMode=0
local quietMode=0
if [ "$1" = "-q" ];then
quietMode=1
shift
fi
if [ "$1" = "-j" ];then
justUseCurrentDirectoryMode=1;
else
module=$1
fi
if [ $justUseCurrentDirectoryMode -eq 0 ];then
ensure_repo_generic ${WORK_ROOT} ${module}
cd ${WORK_ROOT}/${module}
fi
git fetch --tags 1>/dev/stderr
## This tell you the latest tag of all branch.
local latestTag=$(git describe --tags $( git rev-list --tags --max-count 1))
if [ $justUseCurrentDirectoryMode -eq 0 ];then
cd - > /dev/stderr
fi
if [ $quietMode -eq 0 ];then
print_status " detect_module_tag: ${module:+${module}:} Latest tag: $latestTag"
fi
echo "${latestTag}"
}
###
### detect_module_version [-q] <-j|module>
### Print latest tagged module version.
### This chops the alphabet part of detect_module_tag and
### return strings that start with number.
### e.g. platform-4.0.0-m-7 -> 4.0.0-m-7
function detect_module_version(){
local tag=$(detect_module_tag $@)
sed -n -e 's/[a-zA-Z-]*-\([0-9][0-9.-]*\)/\1/p' <<< $tag
}
###
### does_branch_exist <branch>
### Tell whether the <branch> exists.
### This function assumes you are already in the git checkout
### directory.
### Prints:
### yes: branch exists.
### remote: branch exists at remote, not local.
### no: branch does not exist in remote and local.
### Returns:
### EXIT_OK: The branch exists
### EXIT_RETURN_FALSE: The branch does not exists.
function does_branch_exist(){
local branch=$1
if git rev-parse --verify ${branch} &>/dev/null;then
echo "yes"
return $EXIT_OK
elif git ls-remote --heads origin $branch | grep $branch >& /dev/null ;then
echo "remote"
return $EXIT_OK
fi
echo "no"
return $EXIT_RETURN_FALSE
}
###
### ensure_repo_generic <parentDir> <module> [git_repo_url]
### Ensure repo is at <parentDir>/<module>
function ensure_repo_generic(){
local parentDir=$1
local module=$2
local git_repo_url=${3-}
print_status " Ensure the repo $module is at ${parentDir}/${module}"
if [ -z "$git_repo_url" ];then
git_repo_url=${ZANATA_GIT_URL_PREFIX}/${module}.git
fi
mkdir -p ${parentDir}
cd ${parentDir}
if [ ! -d ${module} ];then
git clone "${git_repo_url}"
if [ $? -ne 0 ];then
failed ${EXIT_FATAL_MISSING_DEPENDENCY} "[ERROR] Failed to clone ${git_repo_url}"
fi
fi
cd - >/dev/null
}
###
### ensure_repo <module> [git_repo_url]
### Ensure repo is at $WORK_ROOT/<module>
function ensure_repo(){
ensure_repo_generic "$WORK_ROOT" "$1" "${2-}"
}
###
### exit_if_failed <var> <exitStatus> <exitMsg>
### Exit when <var> is not 0.
function exit_if_failed(){
if [ "$1" -ne 0 ];then
failed $2 "$3"
fi
}
###
### exit_print_error <exitStatus>
### Print error message just before exit.
### This function does not meant to call directly.
### Environment:
### EXIT_MSG: Error message to print.
EXIT_MSG=
function exit_print_error(){
local exitStatus=$?
if [[ ${ZANATA_QUIET_MODE-} != 0 ]];then
if [ -n "${exitStatus-}" ];then
case $exitStatus in
${EXIT_OK} )
echo_stderr "### Done ${EXIT_MSG}"
;;
${EXIT_FATAL_INVALID_OPTIONS} )
zanata_script_help_short $0
echo_stderr "### [FATAL] Invalid Options: ${EXIT_MSG}"
;;
${EXIT_FATAL_MISSING_DEPENDENCY} )
echo_stderr "### [FATAL] Missing dependencies: ${EXIT_MSG}"
;;
${EXIT_FATAL_UNKNOWN_MODULE} )
zanata_script_help_short $0
echo_stderr "### [FATAL] Unknown or Invalid module: ${EXIT_MSG}"
;;
${EXIT_FATAL_FAIL} )
echo_stderr "### [FATAL] Fail: ${EXIT_MSG}"
;;
${EXIT_FATAL_INVALID_ARGUMENTS} )
echo_stderr "### [FATAL] Invalid Arugments: ${EXIT_MSG}"
;;
${EXIT_RETURN_FALSE} )
echo_stderr "### [RETURN] FALSE: ${EXIT_MSG}"
;;
* )
echo_stderr "### Unexpected Exit Code ${exitStatus}: ${EXIT_MSG}"
;;
esac
fi
fi
exit ${exitStatus}
}
###
### failed <exitStatus> <exitMsg>
### Exit with the error code <exitStatus> and error message <exitMsg>.
function failed(){
local exitStatus=$1
EXIT_MSG="$2"
exit $exitStatus
}
###
### get_releasing_branch
### Determine RELEASING_BRANCH, the branch that we recommend downstream to use,
### and release process should mainly happen here.
### This function assumes you are in correct checkout directory.
### It is:
### 'release' if that branch exists; otherwise "master"
function get_releasing_branch(){
local ret=$(does_branch_exist release)
if [[ $ret = yes || $ret = remote ]] ;then
echo "release"
return 0
fi
echo "master"
return 0
}
###
### get_devel_branch <module>
### Determine DEVEL_BRANCH, the branch for committing new features.
### It is 'master'.
function get_devel_branch(){
echo "master"
}
###
### get_module <argument>
### Determine module.
### Print: <module or - for unknown>
function get_module(){
case ${1-} in
*assets)
echo "zanata-assets"
;;
*jgettext)
echo "jgettext"
;;
*platform)
echo "zanata-platform"
;;
*openprops)
echo "openprops"
;;
*)
echo "-"
;;
esac
}
###
### get_artifact_id <argument>
### Obtain SCM Tag like zanata-parent, api
### Print: <SCM Tag>
function get_artifact_id(){
case $1 in
*api)
echo "api"
;;
*assets)
echo "zanata-assets"
;;
*jgettext)
echo "jgettext"
;;
*platform)
echo "platform"
;;
*openprops)
echo "openprops"
;;
*)
failed ${EXIT_FATAL_UNKNOWN_MODULE} "get_artifact_id: module $1 not recognized "
;;
esac
}
###
### is_maven_packaging [str]
function is_maven_packaging(){
case $1 in
pom | jar | maven-plugin | ejb | war | ear | rar | par | zip )
return 0
;;
esac
return 1
}
###
### is_maven_scope [str]
function is_maven_scope(){
case $1 in
compile | provided | runtime | test | system )
return 0
;;
esac
return 1
}
###
### parse_gav <GAV>
### Parse GAV.
### GAV can either in following formats
### commons-cli:commons-cli:1.0
### commons-cli:commons-cli:jar:1.0
### commons-cli:commons-cli:jar:1.0:test
### commons-cli:commons-cli:jar:source:1.0:test
function parse_gav(){
local gav=$1
GroupId=$(awk -F ':' '{print $1}'<<<$gav)
ArtifactId=$(awk -F ':' '{print $2}'<<<$gav)
Packaging=
Classifier=
Version=
Scope=
local c3=$(awk -F ':' '{print $3}'<<<$gav)
local c4=$(awk -F ':' '{print $4}'<<<$gav)
local c5=$(awk -F ':' '{print $5}'<<<$gav)
local c6=$(awk -F ':' '{print $6}'<<<$gav)
if [[ -n "$c6" ]];then
if ! is_maven_scope $c6 ;then
failed $EXIT_ERROR_FAIL "Invalid scope $c6 from $gav"
fi
Scope=$c6
fi
if [[ -n "$c5" ]];then
## c5 can either be scope or version
if [[ -n "$c6" ]];then
Version=$c5
elif is_maven_scope $c5 ;then
Scope=$c5
else
Version=$c5
fi
fi
if [[ -n "$c4" ]];then
## c4 can either be classifier, version or scope
if [[ -n "$Version" ]];then
Classifier=$c4
elif [[ -n "$Scope" ]];then
Version=$c4
elif is_maven_scope $c4 ;then
Scope=$c4
else
Version=$c4
fi
fi
if [[ -z "$c3" ]];then
failed $EXIT_FATAL_INVALID_OPTIONS "Invalid gav $gav"
fi
## c3 can either be packaging, or version
if is_maven_packaging $c3 ;then
Packaging=$c3
elif [[ -n "$Version" ]];then
failed $EXIT_FATAL_INVALID_OPTIONS "Invalid maven packaging $c3 from gav $gav"
else
Version=$c3
fi
test -n "$GroupId" -a -n "$ArtifactId" -a -n "$Version"
exit_if_failed $? ${EXIT_FATAL_INVALID_OPTIONS} "GAV $gav is invalid, should be in groupId:artifactId:version"
Gav="$GroupId:$ArtifactId:$Version"
}
###
### ga_to_rpm_name <GroupId> <artifactId>
### GroupId-ArtifactId to RPM name.
function ga_to_rpm_name(){
echo "$1-$2"
}
###
### gav_to_nv <GroupId> <artifactId> <Version>
### GroupId-ArtifactId-Version to RPM name-version
function gav_to_nv(){
local version=$(sed -e 's/-/_/g' <<<$3)
echo "$(ga_to_rpm_name $1 $2)-$version"
}
###
### gav_to_nvr <GroupId> <artifactId> <Version> [SpecRelease]
### GroupId-ArtifactId-Version to RPM name-version-release
### release default is 1
### Note the release does not include dist tag (.el7)
function gav_to_nvr(){
local groupId=$1
local artifactId=$2
local version=$(sed -e 's/-/_/g'<<<$3)
local release=${4-}
if [[ -z $release ]];then
release=1
fi
echo "$(gav_to_nv $groupId $artifactId $version)-$release"
}
function gav_to_maven_artifact_dir(){
local groupId=$1
local artifactId=$2
local version=$3
local retStr=$(sed -e 's|\.|/|g' <<< ${groupId})
retStr+="/${artifactId}/${version}"
echo "$retStr"
}
###
### gav_to_maven_artifact_file <GroupId> <artifactId> <Version> [Packaging] [Classifier]
### Return the artifact filename when given Gav.
function gav_to_maven_artifact_file(){
local groupId=$1
local artifactId=$2
local version=$3
local packaging=${4-}
local classifier=${5-}
if [ -z "$packaging" ];then
packaging=jar
fi
echo "${artifactId}-${version}${classifier:+-${classifier}}.${packaging}"
}
###
### print_status [-n] [-q] [-s] [-t <Stage>] [message]
### Print the status message.
### Options:
### -n: Do not print end-of-line in the end.
### -q: Quiet, do not output anything
### -s: prepend separation line before message
### -t <Stage>: Specify Stage
### If -s is specified, it will pad separation line before message, like
### "(Caller)[Stage]============================== Start"
### It will use following Environment variables
### Stage: As stage inside []
ZnatNoEOL=0
function print_status(){
local outputStr=
local optionArray=()
local optionN=0
local optionS=0
if [[ ${ZANATA_QUIET_MODE-} = 1 ]];then
return
fi
while [[ $1 == -* ]]; do
case $1 in
-n )
optionArray+=( -n )
shift
optionN=1
;;
-q )
return
;;
-s )
optionS=1
shift
;;
-t )
shift
Stage=$1
shift
;;
esac
done
if [ $ZnatNoEOL -eq 0 ];then
## Previous line already ended
local caller=$(basename ${BASH_SOURCE[1]})
outputStr+="### "
if [[ $caller != $ProgramName ]];then
outputStr+="($caller)"
fi
outputStr+="[${Stage-}]"
fi
if [ $optionS -eq 1 ];then
outputStr+="=============================="
fi
local message="$1"
outputStr+="$message"
if [ -n "${optionArray-}" ];then
echo_stderr ${optionArray[@]} "$outputStr"
else
echo_stderr "$outputStr"
fi
ZnatNoEOL=$optionN
}
## run_command <command> [args ... ]
## On Dry-run mode, just show the command,
## otherwise run the command.
function run_command(){
if [[ ${DryRunMode:-} -eq 1 ]];then
print_status " [Dry-Run] $*"
ExitCode=$EXIT_OK
else
set -x
"$@"
ExitCode=$?
set +x
fi
}
###
### time_stamp [DATE_FORMAT]
### Use stamp like "2015-06-29-06:56:34-953717856", base on UTC
### Default: '%F-%R-%N'
function time_stamp(){
local DATE_FORMAT=${1-}
if [ -z "$DATE_FORMAT" ];then
DATE_FORMAT='%F-%R-%N'
fi
date -u +"$DATE_FORMAT"
}
###
### version_next <version>
### Add one to last number
### Version delimiter are: . _ -
function version_next(){
local thisVersion=$1
local prefix=${thisVersion%[._-]*}
local delimiter=$(sed -n -E -e 's/^.*([._-])([0-9]+)?$/\1/p'<<<$thisVersion)
local last
if [[ -z $delimiter ]];then
## See if it just contains single number, like 27
local prefixNum=$(sed -n -E -e 's/([0-9]+)/\1/p'<<<$prefix)
if [[ -z $prefixNum ]];then
failed $EXIT_FATAL_INVALID_ARGUMENTS "version $thisVersion is invalid"
else
last=$((prefixNum+1))
echo "$last"
return
fi
else
last=$(($(sed -n -E -e 's/^.*([._-])([0-9]+)$/\2/p'<<<$thisVersion)+1))
fi
echo "$prefix$delimiter$last"
}
## Find zanata-env.sh
case $(basename $0) in
bash )
## Remote Mode assumed
export ZANATA_REMOTE=1
: ${ZANATA_SCRIPTS_BRANCH:=master}
;;
* )
;;
esac
if [[ -n ${ZANATA_REMOTE:-} ]]; then
source <(curl -q https://raw.githubusercontent.com/zanata/zanata-scripts/$ZANATA_SCRIPTS_BRANCH/zanata-env.sh)
## We keep a copy in local so help works
mkdir -p "$TMP_ROOT"
ZanataScriptsDir=$TMP_ROOT
ZanataEnvSh="$ZanataScriptsDir/zanata-env.sh"
curl -o "$ZanataEnvSh" -q https://raw.githubusercontent.com/zanata/zanata-scripts/$ZANATA_SCRIPTS_BRANCH/zanata-env.sh
ProgramName=zanata-functions
ProgramFullFilename=$ZanataScriptsDir/$ProgramName
curl -o $ProgramFullFilename -q https://raw.githubusercontent.com/zanata/zanata-scripts/$ZANATA_SCRIPTS_BRANCH/zanata-functions
else
ZanataScriptsDir=$(dirname $(realpath ${BASH_SOURCE[0]}))
ZanataEnvSh="$ZanataScriptsDir/zanata-env.sh"
source "$ZanataEnvSh"
ProgramFullFilename=${BASH_SOURCE[$((${#BASH_SOURCE[@]}-1))]}
ProgramName=$(basename $ProgramFullFilename)
fi
case $ProgramName in
*-functions )
trap exit_print_error EXIT
case ${1-} in
help )
zanata_script_help $ProgramFullFilename
exit $EXIT_OK
;;
help-section )
zanata_help_section $ProgramFullFilename $2
exit $EXIT_OK
;;
help-list-sections )
zanata_help_list_sections $ProgramFullFilename
exit $EXIT_OK
;;
run )
shift
$@
exit $?
;;
?* )
failed $EXIT_FATAL_INVALID_OPTIONS "Invalid option $1"
;;
esac
zanata_script_help_short $ProgramFullFilename
;;
esac
# vim: set expandtab ts=4 sw=4 si: