aboutsummaryrefslogtreecommitdiffstats
path: root/version-manifest/src/main/scripts/check-sorted.sh
blob: eb41ddef2aef06e6de5de0e94a309996b16c507e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

if [ "$#" -ne 1 ]; then
    echo This script checks the input file to verify that it is sorted
    echo "$0 <manifest.csv>"
    exit 1
fi

LC_ALL=C sort -c $1

retval=$?
if [ $retval -ne 0 ]; then
    echo
    echo "[ERROR] $1 is not properly sorted.  Please sort it with the following commands:"
    echo
    echo "  LC_ALL=C sort < $1 > $1.tmp"
    echo "  mv $1.tmp $1"
    echo
fi

# check that there are no duplicate records
DUPLICATES=$(rev < $1 | cut -f2- -d, | uniq -d | rev | tr ',' ':')
for DUP in $DUPLICATES; do
    echo "[ERROR] $DUP has duplicate entries"
    ((retval++))
done

exit $retval