improve code quality based on shellcheck
continuous-integration/drone/push Build is passing 詳情
continuous-integration/drone/pr Build is passing 詳情

This commit is contained in:
Max Mehl 2019-10-02 15:44:47 +02:00
父節點 30f8ca94dc
當前提交 b1669e6868
簽署人: max.mehl
GPG 金鑰 ID: 2704E4AB371E2E92
共有 2 個檔案被更改,包括 51 行新增49 行删除

查看文件

@ -21,54 +21,56 @@ print_usage() {
echo " 0 = file is up-to-date"
echo " 1 = file is outdated"
echo " 2 = file is not supported"
exit 0
}
ALL="0"
QUIET="0"
while getopts f:o:aq OPT; do
while getopts f:o:aqh OPT; do
case $OPT in
f) FILE=$OPTARG;; # file name
a) ALL="1";;
q) QUIET="1";;
o) ONLY=$OPTARG;; # print only languages which are up/outdated
h) print_help;;
f) FILE=$OPTARG;; # file name
a) ALL="1";;
q) QUIET="1";;
o) ONLY=$OPTARG;; # print only languages which are up/outdated
h) print_usage;;
*) print_usage;;
esac
done
# show usage if no required parameter given
if [ "$1" = "" ] || [ -z "$FILE" ]; then
if [ "$1" = "" ] || [ -z "${FILE}" ]; then
print_usage
exit 0
fi
# -o suppresses all other output (-q), and implicates -a
if [ ! -z "$ONLY" ]; then
if [ -n "${ONLY}" ]; then
QUIET="1"
ALL="1"
fi
function out {
if [ "$QUIET" != "1" ]; then
if [ "${QUIET}" != "1" ]; then
echo "$@"
fi
}
# Get file extension
EXT="${FILE##*.}"
if ! [[ "$EXT" =~ ^(xhtml|xml)$ ]]; then
if ! [[ "${EXT}" =~ ^(xhtml|xml)$ ]]; then
out "Only works for files ending with .xhtml or .xml"
exit 2
fi
# remove "en.$EXT"
BASE=$(echo "$FILE" | sed -E "s/\.[a-z][a-z]\.$EXT//")
BASE=$(echo "${FILE}" | sed -E "s/\.[a-z][a-z]\.${EXT}//")
# get change date of English file
EN=$BASE.en.$EXT
if [ ! -e "$EN" ]; then
out "English file does not exist. Aborting. ($EN)"
EN="${BASE}".en."${EXT}"
if [ ! -e "${EN}" ]; then
out "English file does not exist. Aborting. (${EN})"
exit 2
fi
endate=$(git log --pretty="%cd" --date=raw -1 "$EN"|cut -d' ' -f1)
endate=$(git log --pretty="%cd" --date=raw -1 "${EN}"|cut -d' ' -f1)
# check if we have a git log of the EN base file. If not, abort
if [ -z "${endate}" ]; then
@ -78,59 +80,59 @@ fi
# Convert to YYYY-MM-DD
ymd=$(date +"%Y-%m-%d" --date="@$endate")
out "Basefile: $EN ( $ymd )"
out "Basefile: ${EN} ( ${ymd} )"
out " STATUS LANG DATE"
out " -------- ---- ----------"
if [ "$ALL" == "1" ]; then
if [ "${ALL}" == "1" ]; then
# Loop over all translations of this file
for i in "$BASE".[a-z][a-z].$EXT; do
for i in "${BASE}".[a-z][a-z]."${EXT}"; do
if [[ $i != *".en."* ]]; then
# get language code
lang=$(echo "$i"|sed "s/.*\.\([a-z][a-z]\)\.$EXT/\1/")
lang=$(echo "${i}"|sed "s/.*\.\([a-z][a-z]\)\.${EXT}/\1/")
# get change date of translation
trdate=$(git log --pretty="%cd" --date=raw -1 "$i"|cut -d' ' -f1)
trdate=$(git log --pretty="%cd" --date=raw -1 "${i}"|cut -d' ' -f1)
# Convert to YYYY-MM-DD
ymd=$(date +"%Y-%m-%d" --date="@$trdate")
ymd=$(date +"%Y-%m-%d" --date="@${trdate}")
# get time difference in seconds
diff=$((trdate-endate))
# mark as outdated if difference larger than 1 hour
if [[ $diff -lt -3600 ]]; then
out " OUTDATED $lang $ymd"
out " OUTDATED ${lang} ${ymd}"
# print outdated language code
if [ "$ONLY" == "out" ]; then
echo "$lang"
if [ "${ONLY}" == "out" ]; then
echo "${lang}"
fi
else
out " Up-to-date $lang $ymd"
out " Up-to-date ${lang} ${ymd}"
# print up-to-date language code
if [ "$ONLY" == "up" ]; then
echo "$lang"
if [ "${ONLY}" == "up" ]; then
echo "${lang}"
fi
fi
fi
done | sort
exit 0
else
i="$FILE"
i="${FILE}"
if [[ $i != *".en."* ]]; then
# get language code
lang=$(echo "$i"|sed "s/.*\.\([a-z][a-z]\)\.$EXT/\1/")
lang=$(echo "${i}"|sed "s/.*\.\([a-z][a-z]\)\.${EXT}/\1/")
# get change date of translation
trdate=$(git log --pretty="%cd" --date=raw -1 "$i"|cut -d' ' -f1)
trdate=$(git log --pretty="%cd" --date=raw -1 "${i}"|cut -d' ' -f1)
# Convert to YYYY-MM-DD
ymd=$(date +"%Y-%m-%d" --date="@$trdate")
ymd=$(date +"%Y-%m-%d" --date="@${trdate}")
# get time difference in seconds
diff=$((trdate-endate))
# mark as outdated if difference larger than 1 hour
if [[ $diff -lt -3600 ]]; then
out " OUTDATED $lang $ymd"
out " OUTDATED ${lang} ${ymd}"
exit 1
else
out " Up-to-date $lang $ymd"
out " Up-to-date ${lang} ${ymd}"
exit 0
fi
else
out " (Comparing status of English file does not make sense)"
fi
else
out " (Comparing status of English file does not make sense)"
fi
fi

查看文件

@ -9,7 +9,7 @@ for xmlfile in $(
); do
if [ -e "${xmlfile}" ]; then
xmllint --noout --nonet "${xmlfile}"
TESTS=$((${TESTS} + $?))
TESTS=$((TESTS + $?))
fi
done
@ -46,10 +46,10 @@ for xmlfile in $(
# go through all tags in this file
for tag in $(grep -Ei "<tag.*?>.+?</tag>" "${xmlfile}" | sed -E "s|.*<tag.*?>(.+?)</tag>.*|\1|g"); do
# check if this tag does exist in any other news/event item
if [ -z "$(git grep -irlE "<tag.*?>${tag}</tag>" news/ events/ | grep -v "${xmlfile}")" ]; then
if ! git grep -irlE "<tag.*?>${tag}</tag>" news/ events/ | grep -vq "${xmlfile}"; then
hit=1
tags="${tag}, ${tags}"
NEWTAGS=$((${NEWTAGS} + 1))
NEWTAGS=$((NEWTAGS + 1))
fi
done
# if any new tag has been found, enlist them
@ -64,7 +64,7 @@ if [ $NEWTAGS -gt 0 ]; then
=== NEW / DUPLICATED TAG(S) ===
Your commit introduced $NEWTAGS tag(s) which did not exist before in
our news or event items!
$(echo $FILES | sed -E -e "s/\|/\n - /g")
$(echo "${FILES}" | sed -E -e "s/\|/\n - /g")
Please make sure that you use already used tags, and only introduce a
new tag e.g. if it's about a new campaign that will be more often
@ -99,29 +99,29 @@ for file in $ENFILES; do
# check whether previously up-to-date translations will be in this commit
for trans in $LANGS_UP; do
trans="$BASE.$trans.$EXT"
if ! $(echo "${ALLFILES}" | grep -Eq "^${trans}$" ); then
OUTDATED=$((${OUTDATED} + 1))
WARN="$WARN, $trans"
trans="${BASE}.${trans}.${EXT}"
if ! echo "${ALLFILES}" | grep -Eq "^${trans}$"; then
OUTDATED=$((OUTDATED + 1))
WARN="${WARN}, ${trans}"
fi
done
WARN=$(echo $WARN | sed -E "s/^, //")
WARN=$(echo "${WARN}" | sed -E "s/^, //")
# only add to list of outdated files if at least 1 warning has been found
if [ ! -z "${WARN}" ]; then
TEXT="${TEXT}|$file => $WARN"
if [ -n "${WARN}" ]; then
TEXT="${TEXT}|${file} => ${WARN}"
fi
done
if [ $OUTDATED -gt 0 ]; then
cat <<EOF >&2
=== OUTDATE WARNING ===
Your commit caused $OUTDATED previously up-to-date translations
Your commit caused ${OUTDATED} previously up-to-date translations
to become outdated!
If you made non-content changes to the English base files,
consider making a fake-commit to these translations:
- $(echo $TEXT | sed -E -e "s/^\|//" -e "s/\|/\n - /g")
- $(echo "${TEXT}" | sed -E -e "s/^\|//" -e "s/\|/\n - /g")
Read more: https://wiki.fsfe.org/TechDocs/Mainpage/Translations/Outdated