update_all_from_skeleton 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #! /bin/bash
  2. #
  3. # Run from an account directory to update all the child directory's standard files
  4. function argparse {
  5. PARAMS=""
  6. while (( "$#" )); do
  7. case "$1" in
  8. -h|--help)
  9. echo Usage: $0 '[-t|--test] [-d|--debug]'
  10. exit 0
  11. ;;
  12. -t|--test)
  13. TESTING="/bin/echo TESTING: "
  14. shift
  15. ;;
  16. -d|--debug)
  17. >&2 echo debug: Enabling debugging..
  18. DEBUG=1
  19. shift
  20. ;;
  21. # -p|--only-path)
  22. # if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
  23. # ONLY_PATH=$2
  24. # shift 2
  25. # else
  26. # echo "Error: Argument for $1 is missing" >&2
  27. # exit 1
  28. # fi
  29. # ;;
  30. -*|--*=) # unsupported flags
  31. echo "Error: Unsupported flag $1" >&2
  32. exit 1
  33. ;;
  34. *) # preserve positional arguments
  35. PARAMS="$PARAMS $1"
  36. shift
  37. ;;
  38. esac
  39. done
  40. # set positional arguments in their proper place
  41. eval set -- "$PARAMS"
  42. }
  43. # Main
  44. argparse $*
  45. SHORT_PWD=$( basename ${PWD} )
  46. PARENT_PWD=$( basename $( cd .. && pwd ) )
  47. [[ $DEBUG == 1 ]] && >&2 echo debug: PWD=$PWD
  48. [[ $DEBUG == 1 ]] && >&2 echo debug: SHORT_PWD=$SHORT_PWD
  49. # Sanity Checking
  50. if [[ $SHORT_PWD == "000-skeleton" ]]; then
  51. >&2 echo Error: Cannot run from skeleton directory. Exiting...
  52. exit 1
  53. fi
  54. if [[ $SHORT_PWD =~ ^[0-9]{3}-.* ]]; then
  55. >&2 echo Error: We appear to be in a module directory. Please run from the account directory you wish to update. Exiting...
  56. exit 2
  57. fi
  58. if [[ ! $PARENT_PWD =~ ^aws ]]; then
  59. >&2 echo Error: We do not appear to be in an account directory. Failing...
  60. exit 3
  61. fi
  62. for i in `seq -f "../../../000-skeleton/%g*" 0 9`; do
  63. MODULE=$( basename $i )
  64. [[ $TESTING ]] && >&2 echo debug: Processing module $MODULE...
  65. if [[ -d $MODULE ]]; then
  66. [[ $DEBUG ]] && >&2 echo debug: Module exists. Updating carefully.
  67. pushd . > /dev/null
  68. cd $MODULE
  69. update_from_skeleton $*
  70. popd > /dev/null
  71. else
  72. # Special case: 020-attach-transit-gateway-to-standard-vpc
  73. if [[ $MODULE == "020-attach-transit-gateway-to-standard-vpc" && $SHORT_PWD =~ -c2$ ]]; then
  74. echo Skipping $MODULE for C2 Accounts
  75. else
  76. [[ -d ../../../000-skeleton/$MODULE ]] && ${TESTING} cp -rv ../../../000-skeleton/$MODULE .
  77. fi
  78. fi
  79. done
  80. echo Finished. Don\'t forget to update account.hcl.
  81. echo '--------------- 000-skeleton/account.hcl ----------------'
  82. cat ../../../000-skeleton/account.hcl
  83. echo '--------------- finished ----------------'