From 5794cc5217975dcf46b80d7c1a3685895a3150a8 Mon Sep 17 00:00:00 2001 From: James Hodgkinson Date: Tue, 20 Feb 2024 18:39:16 +1000 Subject: [PATCH] Adding duplicate-finder script (#2550) * Adding duplicate-finder script * removing unused constant and updated doctstring --- scripts/find_duplicated_names.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 scripts/find_duplicated_names.sh diff --git a/scripts/find_duplicated_names.sh b/scripts/find_duplicated_names.sh new file mode 100755 index 000000000..42911ca64 --- /dev/null +++ b/scripts/find_duplicated_names.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# This script will find all duplicated names in the Kanidm database, handy for upgrading from 1.1.0 RC15 to RC16 + +if [ -z "${KANIDM_NAME}" ]; then + echo "Setting the KANIDM_NAME env var will save you selecting a user multiple times!" >&2 +fi + +RES="$( + kanidm group list | grep -E '^name' | awk '{print $2}' || exit 1 + kanidm person list | grep -E '^name' | awk '{print $2}' || exit 1 + kanidm service-account list | grep -E '^name' | awk '{print $2}' || exit 1 + kanidm system oauth2 list | grep -E '^oauth2_rs_name' | awk '{print $2}' || exit 1 +)" + +DUPES="$(echo "${RES}" | sort | uniq -c | grep -vE '^\s+1' | awk '{print $2}')" + +if [ -z "${DUPES}" ]; then + echo "No duplicates found" >&2 + exit 0 +else + echo "Duplicates found, here's a list" >&2 + echo "${DUPES}" + exit 1 +fi \ No newline at end of file