Check for duplicate entries in manifests
[integration.git] / version-manifest / src / main / scripts / check-sorted.sh
1 #!/bin/bash
2
3 if [ "$#" -ne 1 ]; then
4     echo This script checks the input file to verify that it is sorted
5     echo "$0 <manifest.csv>"
6     exit 1
7 fi
8
9 LC_ALL=C sort -c $1
10
11 retval=$?
12 if [ $retval -ne 0 ]; then
13     echo
14     echo "[ERROR] $1 is not properly sorted.  Please sort it with the following commands:"
15     echo
16     echo "  LC_ALL=C sort < $1 > $1.tmp"
17     echo "  mv $1.tmp $1"
18     echo
19 fi
20
21 # check that there are no duplicate records
22 DUPLICATES=$(rev < $1 | cut -f2- -d, | uniq -d | rev | tr ',' ':')
23 for DUP in $DUPLICATES; do
24     echo "[ERROR] $DUP has duplicate entries"
25     ((retval++))
26 done
27
28 exit $retval