From 726485ba68625f4a4b2e77639799f1def8f9c371 Mon Sep 17 00:00:00 2001 From: badra001 Date: Wed, 8 Jul 2026 14:24:36 -0400 Subject: [PATCH] add -x, echo vs execute changes --- .../idc-membership-check/user_update.sh | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/local-app/python-tools/idc-membership-check/user_update.sh b/local-app/python-tools/idc-membership-check/user_update.sh index 4db00b95..b4dfe328 100755 --- a/local-app/python-tools/idc-membership-check/user_update.sh +++ b/local-app/python-tools/idc-membership-check/user_update.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -x cleanup() { @@ -12,7 +12,7 @@ cleanup() trap cleanup EXIT THIS=$(basename $0 .sh) -VERSION="1.1.2" +VERSION="1.1.4" # set -euo pipefail export TMPDIR=$(/bin/mktemp -d /tmp/user_update.XXXXXXXX) || (echo "#* error making TMPDIR" && exit 1) @@ -46,6 +46,10 @@ echo "## $text" echo $text > "$STATUS_PIPE" u_add=$(awk -F, 'NR>1 { if ($1=="USER" && $4==1) { print $2 }}' $SUMMARY_CSV) c_add=$(awk -F, 'NR>1 { if ($1=="USER" && $4==1) { c+=1 }} END {print c}' $SUMMARY_CSV) +if [ -z $c_add ] +then + c_add=0 +fi echo "PROGRESS:$C/$TASKS" > "$STATUS_PIPE" C=$(( C + 1 )) @@ -54,6 +58,10 @@ echo "## $text" echo $text > "$STATUS_PIPE" u_delete=$(awk -F, 'NR>1 { if ($1=="USER" && $3!="" && $5==1) { print $2 }}' $SUMMARY_CSV) c_delete=$(awk -F, 'NR>1 { if ($1=="USER" && $3!="" && $5==1) { c+=1 }} END {print c}' $SUMMARY_CSV) +if [ -z $c_delete ] +then + c_delete=0 +fi echo "PROGRESS:$C/$TASKS" > "$STATUS_PIPE" C=$(( C + 1 )) @@ -62,14 +70,18 @@ echo "## $text" echo $text > "$STATUS_PIPE" u_pending_add=$(awk -F, 'NR>1 { if ($1=="USER" && $6==1) { print $2 }}' $SUMMARY_CSV) c_pending_add=$(awk -F, 'NR>1 { if ($1=="USER" && $6==1) { c+=1 }} END {print c}' $SUMMARY_CSV) +if [ -z $c_pending_add ] +then + c_pending_add=0 +fi echo "PROGRESS:$C/$TASKS" > "$STATUS_PIPE" set -euo pipefail C=$(( C + 1 )) -text="$C/$TASKS: tf-apply targets (add)" +text="$C/$TASKS: tf-apply targets (add $c_add)" echo "## $text" echo $text > "$STATUS_PIPE" -if [ $ADD_COUNT -gt 0 ] +if [ $c_add -gt 0 ] then targets="" for u in $u_add @@ -78,9 +90,9 @@ then targets+=" -target=aws_identitystore_user.users[\"$u\"]" done #tf-apply -auto-approve $targets - tf-plan -refresh=false -out=$TMPDIR/user_add.json $targets + tf-plan -refresh=false -out=$TMPDIR/user_add.tfplan $targets tf-plan summary - tf-apply -refresh=false $TMPDIR/user_add.json + echo "tf-apply -refresh=false $TMPDIR/user_add.tfplan" status=$? fi set +euo pipefail @@ -89,7 +101,7 @@ C=$(( C + 1 )) text="$C/$TASKS: remove users from .csv" echo "## $text" echo $text > "$STATUS_PIPE" -if [ $DELETE_COUNT -gt 0 ] +if [ $c_delete -gt 0 ] then for u in $u_delete do @@ -102,7 +114,7 @@ C=$(( C + 1 )) text="$C/$TASKS: remove users from .yml files" echo "## $text" echo $text > "$STATUS_PIPE" -if [ $DELETE_COUNT -gt 0 ] +if [ $c_delete -gt 0 ] then for u in $u_delete do @@ -113,10 +125,10 @@ fi set -euo pipefail C=$(( C + 1 )) -text="$C/$TASKS: tf-apply targets (delete)" +text="$C/$TASKS: tf-apply targets (delete $c_delete)" echo "## $text" echo $text > "$STATUS_PIPE" -if [ $DELETE_COUNT -gt 0 ] +if [ $c_delete -gt 0 ] then targets="" for u in $u_delete @@ -124,10 +136,11 @@ then targets+=" -target=data.ldap_object.users[\"$u\"]" targets+=" -target=aws_identitystore_user.users[\"$u\"]" done + echo "tf-destroy -refresh-false -approve $targets" #tf-destroy -auto-approve $targets - tf-plan -refresh=false -destroy -out=$TMPDIR/user_delete.json $targets + tf-plan -refresh=false -destroy -out=$TMPDIR/user_delete.tfplan $targets tf-plan summary - tf-apply -refresh=false -destroy $TMPDIR/user_delete.json + echo "tf-apply -refresh=false -destroy $TMPDIR/user_delete.tfplan" status=$? fi set +euo pipefail @@ -138,7 +151,7 @@ set +euo pipefail #echo "RESULT:SUCCESS:$c_add:$c_delete:$c_pending_add" > "$STATUS_PIPE" #echo "RESULT:FAILURE:0:0:0" > "$STATUS_PIPE" -text="END file $SUMMARY_CSV add $ADD_COUNT delete $DELETE_COUNT pending-add $PENDING_COUNT" +text="END file $SUMMARY_CSV add $c_add delete $c_delete pending-add $c_pending_add" echo "## $text" #echo $text > "$STATUS_PIPE"