summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-03-16 23:30:01 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-03-17 00:40:13 +0100
commitf1c7bb4aa9b8feaeaa585292b8b9c1925ada2692 (patch)
tree046e16007d4a20aeb6a9634773503a51eb9c017e
parent19d1f3d45d6816d6540b6bcbde97bfb2f6b24b75 (diff)
Script to find duplicate usernames only differing in case
Usage: cd /path/to/All-Users.git find-duplicate-usernames.sh [username|gerrit] This script finds duplicate usernames only differing in case in the given account schema ("username" or "gerrit") and their respective accountIds. Change-Id: I16713471ef026736274695f815428bf68c768e0c
-rwxr-xr-xcontrib/find-duplicate-usernames.sh49
1 files changed, 49 insertions, 0 deletions
diff --git a/contrib/find-duplicate-usernames.sh b/contrib/find-duplicate-usernames.sh
new file mode 100755
index 0000000000..f9bcf8810e
--- /dev/null
+++ b/contrib/find-duplicate-usernames.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+# Copyright (C) 2021 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+usage() {
+ f="$(basename -- $0)"
+ cat <<EOF
+Usage:
+ cd /path/to/All-Users.git
+ "$f [username|gerrit]"
+
+This script finds duplicate usernames only differing in case in the given
+account schema ("username" or "gerrit") and their respective accountIds.
+EOF
+ exit 1
+}
+
+if [[ "$#" -ne "1" ]] || ! [[ "$1" =~ ^(gerrit|username)$ ]]; then
+ usage
+fi
+
+# find lines with user name and subsequent line in external-ids notes branch
+# remove group separators
+# remove line break between user name and accountId lines
+# unify separators to ":"
+# cut on ":", select username and accountId fields
+# sort case-insensitive
+# flip columns
+# uniq case-insensitive, only show duplicates, avoid comparing first field
+# flip columns back
+git grep -A1 "\[externalId \"$1:" refs/meta/external-ids \
+ | sed -E "/$1/,/accountId/!d" \
+ | paste -d ' ' - - \
+ | tr \"= : \
+ | cut -d: --output-delimiter="" -f 5,8 \
+ | sort -f \
+ | sed -E "s/(.*) (.*)/\2 \1/" \
+ | uniq -Di -f1 \
+ | sed -E "s/(.*) (.*)/\2 \1/"