stack.sh invokes some helper scripts as separate processes, rather than
by source'ing them. As with stack.sh itself, abort immediately on the
first error, so that errors don't compound and result in confusing error
messages. If one of these helper scripts aborts, stack.sh itself will
also abort in the usual manner.
Due to the change in behaviour, tweak some mv invocations to ensure that
they don't trigger false failures.
As with stack.sh itself, also enable xtrace so we can see exactly what's
happening. In particular this allows us to see the cause of any
premature termination due to a command failing whilst errexit is
enabled.
Change-Id: I7a55784c31e5395e29ab9bbe2bb112b83b9be693
| ... | ... |
@@ -6,6 +6,9 @@ |
| 6 | 6 |
|
| 7 | 7 |
# Warning: This script just for development purposes |
| 8 | 8 |
|
| 9 |
+set -o errexit |
|
| 10 |
+set -o xtrace |
|
| 11 |
+ |
|
| 9 | 12 |
ACCOUNT_DIR=./accrc |
| 10 | 13 |
|
| 11 | 14 |
display_help() |
| ... | ... |
@@ -138,10 +141,14 @@ s3=`keystone endpoint-get --service s3 | awk '/\|[[:space:]]*s3.publicURL/ {prin
|
| 138 | 138 |
mkdir -p "$ACCOUNT_DIR" |
| 139 | 139 |
ACCOUNT_DIR=`readlink -f "$ACCOUNT_DIR"` |
| 140 | 140 |
EUCALYPTUS_CERT=$ACCOUNT_DIR/cacert.pem |
| 141 |
-mv "$EUCALYPTUS_CERT" "$EUCALYPTUS_CERT.old" &>/dev/null |
|
| 141 |
+if [ -e "$EUCALYPTUS_CERT" ]; then |
|
| 142 |
+ mv "$EUCALYPTUS_CERT" "$EUCALYPTUS_CERT.old" |
|
| 143 |
+fi |
|
| 142 | 144 |
if ! nova x509-get-root-cert "$EUCALYPTUS_CERT"; then |
| 143 | 145 |
echo "Failed to update the root certificate: $EUCALYPTUS_CERT" >&2 |
| 144 |
- mv "$EUCALYPTUS_CERT.old" "$EUCALYPTUS_CERT" &>/dev/null |
|
| 146 |
+ if [ -e "$EUCALYPTUS_CERT.old" ]; then |
|
| 147 |
+ mv "$EUCALYPTUS_CERT.old" "$EUCALYPTUS_CERT" |
|
| 148 |
+ fi |
|
| 145 | 149 |
fi |
| 146 | 150 |
|
| 147 | 151 |
|
| ... | ... |
@@ -168,12 +175,20 @@ function add_entry(){
|
| 168 | 168 |
local ec2_cert="$rcfile-cert.pem" |
| 169 | 169 |
local ec2_private_key="$rcfile-pk.pem" |
| 170 | 170 |
# Try to preserve the original file on fail (best effort) |
| 171 |
- mv -f "$ec2_private_key" "$ec2_private_key.old" &>/dev/null |
|
| 172 |
- mv -f "$ec2_cert" "$ec2_cert.old" &>/dev/null |
|
| 171 |
+ if [ -e "$ec2_private_key" ]; then |
|
| 172 |
+ mv -f "$ec2_private_key" "$ec2_private_key.old" |
|
| 173 |
+ fi |
|
| 174 |
+ if [ -e "$ec2_cert" ]; then |
|
| 175 |
+ mv -f "$ec2_cert" "$ec2_cert.old" |
|
| 176 |
+ fi |
|
| 173 | 177 |
# It will not create certs when the password is incorrect |
| 174 | 178 |
if ! nova --os-password "$user_passwd" --os-username "$user_name" --os-tenant-name "$tenant_name" x509-create-cert "$ec2_private_key" "$ec2_cert"; then |
| 175 |
- mv -f "$ec2_private_key.old" "$ec2_private_key" &>/dev/null |
|
| 176 |
- mv -f "$ec2_cert.old" "$ec2_cert" &>/dev/null |
|
| 179 |
+ if [ -e "$ec2_private_key.old" ]; then |
|
| 180 |
+ mv -f "$ec2_private_key.old" "$ec2_private_key" |
|
| 181 |
+ fi |
|
| 182 |
+ if [ -e "$ec2_cert.old" ]; then |
|
| 183 |
+ mv -f "$ec2_cert.old" "$ec2_cert" |
|
| 184 |
+ fi |
|
| 177 | 185 |
fi |
| 178 | 186 |
cat >"$rcfile" <<EOF |
| 179 | 187 |
# you can source this file |