@@ -48,7 +48,7 @@ clean_templates() {
4848# Commit to template-library-core the removal of obsolete configuration modules
4949remove_obsolete_components () {
5050 (
51- cd " ${LIBRARY_CORE_DIR} " || echo_error " Failed to change directory to ' $LIBRARY_CORE_DIR ' "
51+ cd_or_die " ${LIBRARY_CORE_DIR} "
5252 # FIXME: ideally should check that there is only deleted files left
5353 git add -A .
5454 git commit -m ' Remove obsolete components'
@@ -61,12 +61,12 @@ publish_templates() {
6161 echo_info " Publishing Component Templates"
6262 type=$1
6363 tag=$2
64- cd " configuration-modules-$1 " || echo_error " Failed to change directory to 'configuration-modules- $1 ' "
64+ cd_or_die " configuration-modules-$1 "
6565 git checkout " $tag "
6666 mvn-c clean compile
6767 # ugly hack
6868 if [ -d ncm-metaconfig ]; then
69- cd ncm-metaconfig || echo_error " Failed to change directory to 'ncm-metaconfig' "
69+ cd_or_die ncm-metaconfig
7070 mvn -e clean test
7171 cd ..
7272 fi
@@ -77,7 +77,7 @@ publish_templates() {
7777 cp -r ncm-* /target/pan/components/* " ${components_root} "
7878 cp -r ncm-metaconfig/target/pan/metaconfig/* " ${metaconfig_root} "
7979 git checkout master
80- cd " ${LIBRARY_CORE_DIR} " || return
80+ cd_or_die " ${LIBRARY_CORE_DIR} "
8181 git add .
8282 git commit -m " Component templates (${type} ) for tag ${tag} "
8383 cd ..
@@ -139,7 +139,7 @@ update_version_file() {
139139 fi
140140 version_template=quattor/client/version.pan
141141 (
142- cd " $LIBRARY_CORE_DIR " || echo_error " Failed to change directory to ' $LIBRARY_CORE_DIR ' "
142+ cd_or_die " $LIBRARY_CORE_DIR "
143143
144144 cat > ${version_template} << EOF
145145template quattor/client/version;
@@ -157,7 +157,7 @@ tag_repository() {
157157 repo=$1
158158 tag=$2
159159 (
160- cd " $repo " || echo_error " Failed to change directory to ' $repo ' "
160+ cd_or_die " $repo "
161161 # FIXME: we may want to check that the tag doesn't exist already
162162 git tag -s -m " Release ${tag} " " ${tag} "
163163 git push origin --tags HEAD
@@ -168,7 +168,7 @@ tag_branches() {
168168 repo=$1
169169 version=$2
170170 (
171- cd " $repo " || echo_error " Failed to change directory to ' $repo ' "
171+ cd_or_die " $repo "
172172 # Ignore remote HEAD symlink and branches marked as obsolete
173173 branches=$( git branch -r | grep -v ' -> ' | grep -Ev ' obsolete$' )
174174 for branch in ${branches}
@@ -204,6 +204,12 @@ function exit_usage {
204204 exit 3
205205}
206206
207+ function cd_or_die {
208+ # Change directory or die trying
209+ cd " $@ " || error 2 " Failed to change directory to $* "
210+ return 0
211+ }
212+
207213# Check that dependencies required to perform a release are available
208214missing_deps=0
209215for cmd in {gpg,gpg-agent,git,mvn,createrepo,tar,sed}; do
@@ -253,7 +259,7 @@ if gpg-agent; then
253259 if [[ ! -d " $r " ]]; then
254260 git clone -q
" [email protected] :quattor/$r .git" 255261 fi
256- cd " $r " || echo_error " Failed to change directory to ' $r ' "
262+ cd_or_die " $r "
257263 if git branch -r | grep -q " $RELEASE " ; then
258264 git checkout -q " quattor-$RELEASE "
259265 else
@@ -272,7 +278,7 @@ if gpg-agent; then
272278 if [[ $prompt == " yes" ]]; then
273279 for r in $REPOS_MVN ; do
274280 echo_info " ---------------- Releasing $r ----------------"
275- cd " $r " || echo_error " Failed to change directory to ' $r ' "
281+ cd_or_die " $r "
276282 mvn_prepare=" mvn -e -q -DautoVersionSubmodules=true -Dgpg.useagent=true -Darguments=-Dgpg.useagent=true -B -DreleaseVersion=$VERSION clean release:prepare"
277283 if ! $mvn_prepare ; then
278284 echo_error " RELEASE FAILURE"
@@ -308,7 +314,7 @@ if gpg-agent; then
308314
309315 echo_success " ---------------- YUM repositories complete, tagging git repositories ----------------"
310316
311- cd " $RELEASE_ROOT /src" || echo_error " Failed to change directory to ' $RELEASE_ROOT /src' "
317+ cd_or_die " $RELEASE_ROOT /src"
312318
313319 echo_info " ---------------- Updating template-library-core ----------------"
314320 clean_templates
0 commit comments