Update generate-yaml for clusterctl
-#!/bin/sh
-set -e
+#!/bin/bash
+set -o errexit
+set -o nounset
+
+OUTPUT_DIR=out
PROVIDERCOMPONENT_TEMPLATE_FILE=provider-components.yaml.template
-PROVIDERCOMPONENT_GENERATED_FILE=provider-components.yaml
+PROVIDERCOMPONENT_GENERATED_FILE=${OUTPUT_DIR}/provider-components.yaml
+
+CLUSTER_TEMPLATE_FILE=cluster.yaml.template
+CLUSTER_GENERATED_FILE=${OUTPUT_DIR}/cluster.yaml
+
+MACHINES_TEMPLATE_FILE=machines.yaml.template
+MACHINES_GENERATED_FILE=${OUTPUT_DIR}/machines.yaml
OVERWRITE=0
@@ -10,7 +19,7 @@ SCRIPT=$(basename $0)
while test $# -gt 0; do
case "$1" in
-h|--help)
- echo "$SCRIPT - generates input yaml files for Cluster API on openstack"
+ echo "$SCRIPT - generates input yaml files for Cluster API on aws"
echo " "
echo "$SCRIPT [options]"
echo " "
@@ -33,22 +42,31 @@ while test $# -gt 0; do
esac
done
-if [ $OVERWRITE -ne 1 ] && [ -f $PROVIDERCOMPONENT_GENERATED_FILE ]; then
- echo "File $PROVIDERCOMPONENT_GENERATED_FILE already exists. Delete it manually before running this script."
+if [ $OVERWRITE -ne 1 ] && [ -f $MACHINES_GENERATED_FILE ]; then
+ echo File $MACHINES_GENERATED_FILE already exists. Delete it manually before running this script.
exit 1
fi
-OS=$(uname)
-if [[ "$OS" =~ "Linux" ]]; then
-elif [[ "$OS" =~ "Darwin" ]]; then
-else
- echo "Unrecognized OS : $OS"
+if [ $OVERWRITE -ne 1 ] && [ -f $CLUSTER_GENERATED_FILE ]; then
+ echo File $CLUSTER_GENERATED_FILE already exists. Delete it manually before running this script.
exit 1
fi
-cat $PROVIDERCOMPONENT_TEMPLATE_FILE \
- > $PROVIDERCOMPONENT_GENERATED_FILE
+if [ $OVERWRITE -ne 1 ] && [ -f $PROVIDERCOMPONENT_GENERATED_FILE ]; then
+ echo File $PROVIDERCOMPONENT_GENERATED_FILE already exists. Delete it manually before running this script.
+ exit 1
+fi
+
+mkdir -p ${OUTPUT_DIR}
+
+envsubst < $PROVIDERCOMPONENT_TEMPLATE_FILE \
+ > "${PROVIDERCOMPONENT_GENERATED_FILE}"
+echo "Done generating ${PROVIDERCOMPONENT_GENERATED_FILE}"
-echo "Done generating $PROVIDERCOMPONENT_GENERATED_FILE"
-echo "You will still need to generate the cluster.yaml and machines.yaml"
+envsubst < $CLUSTER_TEMPLATE_FILE \
+ > "${CLUSTER_GENERATED_FILE}"
+echo "Done generating ${CLUSTER_GENERATED_FILE}"
+envsubst < $MACHINES_TEMPLATE_FILE \
+ > "${MACHINES_GENERATED_FILE}"
+echo "Done generating ${MACHINES_GENERATED_FILE}"
