2024-02-10 17:26:34 +01:00
|
|
|
#!/bin/bash
|
2014-03-26 18:12:48 +01:00
|
|
|
# Recursively deduplicate file lines on a per file basis
|
|
|
|
|
# Useful to deduplicate language files
|
|
|
|
|
#
|
|
|
|
|
# Needs awk 4.0 for the inplace fixing command
|
|
|
|
|
#
|
2024-02-10 17:26:34 +01:00
|
|
|
# Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
|
|
|
|
# Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
2014-03-26 18:12:48 +01:00
|
|
|
|
2024-02-10 17:26:34 +01:00
|
|
|
exit_code=0
|
2024-01-12 21:03:08 +01:00
|
|
|
|
2024-02-10 17:26:34 +01:00
|
|
|
# Check arguments
|
|
|
|
|
if [ "$1" != "list" ] && [ "$1" != "fix" ]
|
2014-03-26 18:12:48 +01:00
|
|
|
then
|
2015-03-13 16:20:42 +01:00
|
|
|
echo "Find exact duplicated lines into file (not cross file checking)"
|
2024-02-10 17:26:34 +01:00
|
|
|
echo "Usage: $(basename "$0") [list|fix]"
|
|
|
|
|
exit_code=1
|
2014-03-26 18:12:48 +01:00
|
|
|
fi
|
|
|
|
|
|
2024-02-10 17:26:34 +01:00
|
|
|
ACTION=$1
|
|
|
|
|
|
2014-03-26 18:12:48 +01:00
|
|
|
# To detect
|
2024-02-10 17:26:34 +01:00
|
|
|
if [ "${ACTION}" = "list" ] || [ "${ACTION}" = "fix" ]
|
2014-03-26 18:12:48 +01:00
|
|
|
then
|
2024-02-10 17:26:34 +01:00
|
|
|
echo "Search duplicate lines for lang en_US"
|
|
|
|
|
echo ""
|
|
|
|
|
for file in htdocs/langs/en_US/*.lang
|
2024-01-10 19:47:29 +01:00
|
|
|
do
|
2024-02-10 17:26:34 +01:00
|
|
|
if [ "$(sort "$file" | grep -v -P '^#?$' | uniq -d | wc -l)" -gt 0 ]
|
2024-01-10 19:47:29 +01:00
|
|
|
then
|
2024-02-10 17:26:34 +01:00
|
|
|
sort "$file" | grep -v -P '^#?$' | uniq -d | awk '$0="'"$file"':"$0'
|
|
|
|
|
exit_code=1
|
2024-01-10 19:47:29 +01:00
|
|
|
fi
|
|
|
|
|
done
|
2014-03-26 18:12:48 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# To fix
|
2024-02-10 17:26:34 +01:00
|
|
|
if [ "${ACTION}" = "fix" ]
|
2014-03-26 18:12:48 +01:00
|
|
|
then
|
2016-10-11 10:24:02 +02:00
|
|
|
echo "Fix duplicate line for lang en_US"
|
2024-02-10 17:26:34 +01:00
|
|
|
# shellcheck disable=2016
|
|
|
|
|
for file in htdocs/langs/en_US/*.lang ; do
|
2024-01-10 19:47:29 +01:00
|
|
|
awk -i inplace ' !x[$0]++' "$file"
|
2024-02-10 17:26:34 +01:00
|
|
|
done
|
2014-03-26 18:12:48 +01:00
|
|
|
fi
|
2024-02-10 17:26:34 +01:00
|
|
|
|
|
|
|
|
exit $exit_code
|