1
0
mirror of https://github.com/ru-de/faq.git synced 2024-11-23 19:02:19 +00:00
faq-de/files/check.sh

67 lines
2.3 KiB
Bash
Raw Normal View History

2016-01-18 23:38:49 +00:00
#!/bin/bash
2016-01-19 08:15:30 +00:00
DIR=`dirname $0`
2016-01-18 23:38:49 +00:00
EXIT_CODE=0
2018-01-03 00:57:31 +00:00
git config --global core.quotepath false
(cat $DIR/dictionary.dic; echo) | sed '/^$/d' | wc -l > /tmp/dictionary.dic
(cat $DIR/dictionary.dic; echo) | sed '/^$/d' >> /tmp/dictionary.dic
echo "SET UTF-8" >> /tmp/dictionary.aff
sudo mv /tmp/dictionary.* /usr/share/hunspell
2016-01-19 12:50:18 +00:00
git diff HEAD^ --name-status | grep "^D" -v | sed 's/^.\t//g' | grep "\.md$" > /tmp/changed_files
go build -o /tmp/spell-checker $DIR/spell-checker.go
2016-01-18 23:38:49 +00:00
while read FILE; do
echo -n "Проверка файла $FILE на опечатки... ";
OUTPUT=$(cat "$FILE" | sed 's/https\?:[^ ]*//g' | sed "s/[(][^)]*\.md[)]//g" | sed "s/[(]files[^)]*[)]//g" | hunspell -d dictionary,russian-aot-utf8,ru_RU,de_DE-utf8,en_US-utf8 | /tmp/spell-checker);
2016-01-19 15:36:03 +00:00
OUTPUT_EXIT_CODE=$?
2016-01-18 23:38:49 +00:00
2016-01-19 15:36:03 +00:00
if [ $OUTPUT_EXIT_CODE -ne 0 ]; then
EXIT_CODE=1
2016-01-18 23:38:49 +00:00
echo "ошибка";
2016-01-19 15:25:59 +00:00
echo "$OUTPUT";
2016-01-18 23:38:49 +00:00
else
echo "пройдена";
fi
rm -f /tmp/file.html
blackfriday-tool "$FILE" /tmp/file.html
2016-01-18 23:38:49 +00:00
if [ -f "/tmp/file.html" ]; then
grep -Po '(?<=href=")http[^"]*(?=")' "/tmp/file.html" > /tmp/links
2017-01-12 23:27:07 +00:00
if [ -s /tmp/links ]; then
2017-01-13 09:34:55 +00:00
echo "Проверка файла $FILE на недоступные ссылки... ";
2017-01-12 23:27:07 +00:00
while read LINK; do
2017-01-13 01:14:17 +00:00
REGEXP_LINK=$(echo $LINK | sed 's/[]\.|$(){}?+*^[]/\\&/g')
2017-01-12 23:27:07 +00:00
LINK=$(echo "$LINK" | sed -e 's/\[/\\\[/g' -e 's/\]/\\\]/g' -e 's/\&amp;/\&/g')
status=$(curl --insecure -XGET -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" -m 10 -L -s --head -w %{http_code} $LINK -o /dev/null)
expectedStatus=$(grep -oP "[^,]+,$REGEXP_LINK$" $DIR/known_url.csv | cut -d',' -f1)
2017-01-12 23:27:07 +00:00
if [ -z "$expectedStatus" ]; then
expectedStatus="200"
fi
2017-01-13 01:24:06 +00:00
if [ "$status" != "$expectedStatus" -a "$status" != "200" ]; then
2017-01-12 23:27:07 +00:00
EXIT_CODE=1
echo "Ссылка $LINK ... недоступна с кодом $status, ожидается $expectedStatus";
echo
2017-01-12 23:27:07 +00:00
fi
done < /tmp/links
2017-01-12 23:27:07 +00:00
echo
fi
fi
echo
done < /tmp/changed_files
2017-01-12 23:27:07 +00:00
2016-01-19 08:52:01 +00:00
exit $EXIT_CODE