mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-16 02:50:32 +02:00
added imap import, improved OCR configuration
Papermerge can now be configured to use IMAP for document import. OCR configuration has been rewritten, first language will be set as Papermerge's default OCR languge
This commit is contained in:
@@ -3,19 +3,45 @@
|
||||
|
||||
# Allow OCR setting
|
||||
OCRLANG="$(bashio::config "ocrlang")"
|
||||
languageCount=$(echo "$OCRLANG" | tr -cd ',' | wc -c)
|
||||
languageCount=$((languageCount+1))
|
||||
bashio::log.info "Configuring ${languageCount} languages"
|
||||
|
||||
if [ -n "$OCRLANG" ]; then
|
||||
LINE=$(sed -n '/OCR_LANGUAGES/=' /data/config/papermerge.conf.py)
|
||||
bashio::log.info "OCRLANG variable is set, processing the language packages"
|
||||
apt-get update >/dev/null
|
||||
for i in $(echo "$OCRLANG" | tr "," " "); do
|
||||
if apt-cache show tesseract-ocr-"${i}" >/dev/null 2>&1; then
|
||||
echo "installing tesseract-ocr-${i}" >/dev/null
|
||||
apt-get install -yqq tesseract-ocr-"${i}" >/dev/null
|
||||
else
|
||||
echo "package tesseract-ocr-${i} not found in the repository, skipping"
|
||||
fi
|
||||
sed -i "$LINE a \"${i}\": \"${i}\"," /data/config/papermerge.conf.py
|
||||
bashio::log.info "... ${i} installed"
|
||||
done
|
||||
lineStart=$(sed -n '/OCR_LANGUAGES/=' /data/config/papermerge.conf.py)
|
||||
bashio::log.info "OCRLANG variable is set, processing the language packages"
|
||||
lineEnd=$(sed -n '/}/=' /data/config/papermerge.conf.py)
|
||||
sed -i "${lineStart},${lineEnd}d" /data/config/papermerge.conf.py
|
||||
|
||||
bashio::log.info "Writing new configuration"
|
||||
echo "OCRLANG = {" >> /data/config/papermerge.conf.py
|
||||
|
||||
languages=$(echo "$OCRLANG" | tr "," "\n")
|
||||
|
||||
apt-get update >/dev/null
|
||||
|
||||
i=0
|
||||
for language in $languages; do
|
||||
bashio::log.info "Processing language ${language}"
|
||||
if apt-cache show tesseract-ocr-"${language}" >/dev/null 2>&1; then
|
||||
bashio::log.info "Installing tesseract-ocr-${language}"
|
||||
apt-get install -yqq tesseract-ocr-"${language}" >/dev/null
|
||||
languageFullName=$(apt-cache show tesseract-ocr-"${language}" | grep -E '^(Description|Description-en):' | grep -oE '[^ ]+$')
|
||||
bashio::log.info "${language} identified as ${languageFullName}"
|
||||
i=$((i+1))
|
||||
if [[ $i -eq $languageCount ]]; then
|
||||
echo " \"$language\" : \"$languageFullName\"" >> /data/config/papermerge.conf.py
|
||||
elif [[ $i -eq 1 ]]; then
|
||||
echo " \"$language\" : \"$languageFullName\"," >> /data/config/papermerge.conf.py
|
||||
bashio::log.info "Setting default language to ${language}"
|
||||
sed -i "s/^OCR_DEFAULT_LANGUAGE = \"eng\"/OCR_DEFAULT_LANGUAGE = \"${language}\"/g" /data/config/papermerge.conf.py
|
||||
else
|
||||
echo " \"$language\" : \"$languageFullName\"," >> /data/config/papermerge.conf.py
|
||||
fi
|
||||
bashio::log.info "... ${language} installed"
|
||||
else
|
||||
bashio::log.info "Package tesseract-ocr-${language} not found in the repository, skipping"
|
||||
fi
|
||||
done
|
||||
echo "}" >> /data/config/papermerge.conf.py
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user