diff --git a/bin/local-key-gen-functions.sh b/bin/local-key-gen-functions.sh index 37c8dda9c..8fd424a59 100755 --- a/bin/local-key-gen-functions.sh +++ b/bin/local-key-gen-functions.sh @@ -3,7 +3,17 @@ ACTION_TRACKER="/tmp/intranet_action_tracker" FILE_PRIVATE="/tmp/intranet_private_key.pem" FILE_PUBLIC="/tmp/intranet_public_key.pem" -touch $ACTION_TRACKER + +ENV_FILE=".env" +FILE_OUTPUT="/tmp/intranet_secrets_string" + +# Create outputs files +touch $FILE_OUTPUT +{ + echo -e "\n# # # # # # # # # # # # # # # # # #" + echo "# --> auto-gen secrets keys <-- #" + echo "# # # # # # # # # # # # # # # # # #" +} > $FILE_OUTPUT env_var_exists(){ VAR=$(< "$ENV_FILE" grep -w "$1") @@ -18,6 +28,7 @@ env_var_exists(){ fi } +touch $ACTION_TRACKER action_track(){ TRACKER_SIZE=$(sed -n '$=' "$ACTION_TRACKER") if [[ "$TRACKER_SIZE" -gt 1 ]] ; then @@ -68,12 +79,8 @@ clean_up(){ unset AWS_CLOUDFRONT_PUBLIC_KEY unset AWS_CLOUDFRONT_PUBLIC_KEY_SHORT_HASH - [[ "$1" != "quiet" ]] && echo "Deleting temporary files" - [[ -f "$ACTION_TRACKER" ]] && rm "$ACTION_TRACKER" [[ -f "$FILE_PRIVATE" ]] && rm "$FILE_PRIVATE" [[ -f "$FILE_PUBLIC" ]] && rm "$FILE_PUBLIC" [[ -f "$FILE_OUTPUT" ]] && rm "$FILE_OUTPUT" } - - diff --git a/bin/local-key-gen.sh b/bin/local-key-gen.sh index cb53577dd..08aadd8bb 100755 --- a/bin/local-key-gen.sh +++ b/bin/local-key-gen.sh @@ -5,32 +5,23 @@ # The script follows the instructions from the AWS 'Creating key pairs for your signers' documentation: # https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-trusted-signers.html#private-content-creating-cloudfront-key-pairs +echo "Key Generation: detection..." source bin/local-key-gen-functions.sh -ENV_FILE=".env" -FILE_OUTPUT="/tmp/intranet_secrets_string" - -# Create outputs file -touch $FILE_OUTPUT -{ - echo -e "\n# # # # # # # # # # # # # # # # # #" - echo "# --> auto-gen secrets keys <-- #" - echo "# # # # # # # # # # # # # # # # # #" -} > $FILE_OUTPUT - [[ "$(env_var_exists JWT_SECRET)" == "0" ]] && make_secret JWT [[ "$(env_var_exists AWS_CLOUDFRONT_PRIVATE_KEY)" == "0" ]] && make_secret PRIVATE_KEY [[ "$(env_var_exists AWS_CLOUDFRONT_PUBLIC_KEY)" == "0" ]] && make_secret PUBLIC_KEY [[ "$(env_var_exists AWS_CLOUDFRONT_PUBLIC_KEYS_OBJECT)" == "0" ]] && make_secret PUBLIC_KEYS_OBJECT if [[ "$(action_track)" == "0" ]]; then - echo "No new secrets were created." + echo "Key Generation: no new keys were created." clean_up quiet exit 0 fi # Append secrets to the .env file -cat $FILE_OUTPUT >> $ENV_FILE +cat "$FILE_OUTPUT" >> "$ENV_FILE" +echo "Key Generation: new keys were created." # Clear the variables. clean_up