Skip to content

Checkteams #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions scripts/delete-unused-ns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ source check-available-commands.sh
checkCommandsAvailable kubectl jq awk
IFS=$'
'
USERS=($(awk -F , '{print $3}' users.csv))
USERS=($(awk -F , '{print tolower($3)}' users.csv))
TEAMS=($(awk -F , '{print tolower($3)}' teams.csv))
unset IFS
for NAMESPACE in `kubectl get ns | grep t- | awk '{print $1;}'`
do
echo "found $NAMESPACE"
NO_TDASH_NAMESPACE=${NAMESPACE:2}
CUT_NAMESPACE=${NAMESPACE:2}
NO_TDASH_NAMESPACE=`echo $CUT_NAMESPACE | awk '{print tolower($0)}'`
echo "checking list for $NO_TDASH_NAMESPACE"
if [[ " ${USERS[*]} " =~ " ${NO_TDASH_NAMESPACE} " ]]; then
echo "FOUND $NO_TDASH_NAMESPACE in users, skipping it"
echo "FOUND $NO_TDASH_NAMESPACE in users"
else
echo "did not find $NO_TDASH_NAMESPACE in users, deleting it now!"
kubectl delete ns $NAMESPACE
echo "deleted $NAMESPACE"
if [[ " ${TEAMS[*]} " =~ " ${NO_TDASH_NAMESPACE} " ]]; then
echo "FOUND $NO_TDASH_NAMESPACE in teams"
else
echo "did NOT find $NO_TDASH_NAMESPACE in users and teams. Deletig it now!"
kubectl delete ns $NAMESPACE
echo "deleted $NAMESPACE"
fi

fi
done
18 changes: 14 additions & 4 deletions scripts/list-unused-ns.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
#!/bin/bash

echo "This script shows all the namespaces that have not been used, it requires an export of the users in CTFD"
echo "It assumes you have the users.csv file from CTFD in the same folder"
echo "It assumes you have the users.csv file and teams.csv file from CTFD in the same folder"
echo "This script results in a file unusedteams.txt with all the teams that have no exact match with the registration of users and teams in CTFD"
rm unusedteams.txt
source check-available-commands.sh
checkCommandsAvailable kubectl jq awk
IFS=$'
'
USERS=($(awk -F , '{print $3}' users.csv))
USERS=($(awk -F , '{print tolower($3)}' users.csv))
TEAMS=($(awk -F , '{print tolower($3)}' teams.csv))
unset IFS
for NAMESPACE in `kubectl get ns | grep t- | awk '{print $1;}'`
do
echo "found $NAMESPACE"
NO_TDASH_NAMESPACE=${NAMESPACE:2}
CUT_NAMESPACE=${NAMESPACE:2}
NO_TDASH_NAMESPACE=`echo $CUT_NAMESPACE | awk '{print tolower($0)}'`
echo "checking list for $NO_TDASH_NAMESPACE"
if [[ " ${USERS[*]} " =~ " ${NO_TDASH_NAMESPACE} " ]]; then
echo "FOUND $NO_TDASH_NAMESPACE in users"
else
echo "did not find $NO_TDASH_NAMESPACE in users"
if [[ " ${TEAMS[*]} " =~ " ${NO_TDASH_NAMESPACE} " ]]; then
echo "FOUND $NO_TDASH_NAMESPACE in teams"
else
echo "did NOT find $NO_TDASH_NAMESPACE in users and teams"
echo $NAMESPACE >> unusedteams.txt
fi

fi
done