1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #! /bin/bash
- #
- # Run from an account directory to update all the child directory's standard files
- function argparse {
- PARAMS=""
- while (( "$#" )); do
- case "$1" in
- -h|--help)
- echo Usage: $0 '[-t|--test] [-d|--debug]'
- exit 0
- ;;
- -t|--test)
- TESTING="/bin/echo TESTING: "
- shift
- ;;
- -d|--debug)
- >&2 echo debug: Enabling debugging..
- DEBUG=1
- shift
- ;;
- # -p|--only-path)
- # if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
- # ONLY_PATH=$2
- # shift 2
- # else
- # echo "Error: Argument for $1 is missing" >&2
- # exit 1
- # fi
- # ;;
- -*|--*=) # unsupported flags
- echo "Error: Unsupported flag $1" >&2
- exit 1
- ;;
- *) # preserve positional arguments
- PARAMS="$PARAMS $1"
- shift
- ;;
- esac
- done
- # set positional arguments in their proper place
- eval set -- "$PARAMS"
- }
- # Main
- argparse $*
- SHORT_PWD=$( basename ${PWD} )
- PARENT_PWD=$( basename $( cd .. && pwd ) )
- [[ $DEBUG == 1 ]] && >&2 echo debug: PWD=$PWD
- [[ $DEBUG == 1 ]] && >&2 echo debug: SHORT_PWD=$SHORT_PWD
- # Sanity Checking
- if [[ $SHORT_PWD == "000-skeleton" ]]; then
- >&2 echo Error: Cannot run from skeleton directory. Exiting...
- exit 1
- fi
- if [[ $SHORT_PWD =~ ^[0-9]{3}-.* ]]; then
- >&2 echo Error: We appear to be in a module directory. Please run from the account directory you wish to update. Exiting...
- exit 2
- fi
- if [[ ! $PARENT_PWD =~ ^aws ]]; then
- >&2 echo Error: We do not appear to be in an account directory. Failing...
- exit 3
- fi
- for i in `seq -f "../../../000-skeleton/%g*" 0 9`; do
- MODULE=$( basename $i )
- [[ $TESTING ]] && >&2 echo debug: Processing module $MODULE...
- if [[ -d $MODULE ]]; then
- [[ $DEBUG ]] && >&2 echo debug: Module exists. Updating carefully.
- pushd . > /dev/null
- cd $MODULE
- update_from_skeleton $*
- popd > /dev/null
- else
- # Special case: 020-attach-transit-gateway-to-standard-vpc
- if [[ $MODULE == "020-attach-transit-gateway-to-standard-vpc" && $SHORT_PWD =~ -c2$ ]]; then
- echo Skipping $MODULE for C2 Accounts
- else
- [[ -d ../../../000-skeleton/$MODULE ]] && ${TESTING} cp -rv ../../../000-skeleton/$MODULE .
- fi
- fi
- done
- echo Finished. Don\'t forget to update account.hcl.
- echo '--------------- 000-skeleton/account.hcl ----------------'
- cat ../../../000-skeleton/account.hcl
- echo '--------------- finished ----------------'
|