Files
paperless-ngx/scripts/docker-entrypoint.sh
T

91 lines
2.1 KiB
Bash
Raw Normal View History

#!/bin/bash
2020-10-29 00:46:57 +01:00
set -e
# Source: https://github.com/sameersbn/docker-gitlab/
map_uidgid() {
USERMAP_ORIG_UID=$(id -u paperless)
2018-02-24 11:20:00 +01:00
USERMAP_ORIG_GID=$(id -g paperless)
USERMAP_NEW_UID=${USERMAP_UID:-$USERMAP_ORIG_UID}
USERMAP_NEW_GID=${USERMAP_GID:-${USERMAP_ORIG_GID:-$USERMAP_NEW_UID}}
if [[ ${USERMAP_NEW_UID} != "${USERMAP_ORIG_UID}" || ${USERMAP_NEW_GID} != "${USERMAP_ORIG_GID}" ]]; then
echo "Mapping UID and GID for paperless:paperless to $USERMAP_NEW_UID:$USERMAP_NEW_GID"
usermod -u "${USERMAP_NEW_UID}" paperless
2020-01-05 18:20:03 -08:00
groupmod -o -g "${USERMAP_NEW_GID}" paperless
fi
}
migrations() {
(
# flock is in place to prevent multiple containers from doing migrations
# simultaneously. This also ensures that the db is ready when the command
# of the current container starts.
flock 200
sudo -HEu paperless python3 manage.py migrate
) 200>/usr/src/paperless/data/migration_lock
}
initialize() {
2020-10-29 00:46:57 +01:00
map_uidgid
for dir in export data data/index media media/documents media/documents/originals media/documents/thumbnails; do
if [[ ! -d "../$dir" ]]
2020-10-29 00:46:57 +01:00
then
echo "creating directory ../$dir"
mkdir ../$dir
2020-10-29 00:46:57 +01:00
fi
done
2020-10-29 00:46:57 +01:00
chown -R paperless:paperless ../
migrations
2020-10-29 00:46:57 +01:00
}
2020-10-29 00:46:57 +01:00
install_languages() {
local langs="$1"
read -ra langs <<<"$langs"
# Check that it is not empty
if [ ${#langs[@]} -eq 0 ]; then
return
fi
apt-get update
for lang in "${langs[@]}"; do
pkg="tesseract-ocr-$lang"
# English is installed by default
2020-10-29 00:46:57 +01:00
#if [[ "$lang" == "eng" ]]; then
# continue
#fi
2018-02-24 11:20:00 +01:00
2020-10-29 00:46:57 +01:00
if dpkg -s $pkg &> /dev/null; then
echo "package $pkg already installed!"
continue
fi
2020-10-29 00:46:57 +01:00
if ! apt-cache show $pkg &> /dev/null; then
echo "package $pkg not found! :("
continue
fi
2020-10-29 00:46:57 +01:00
echo "Installing package $pkg..."
if ! apt-get -y install "$pkg" &> /dev/null; then
echo "Could not install $pkg"
exit 1
fi
done
}
2020-11-01 23:01:36 +01:00
initialize
2020-10-29 00:46:57 +01:00
2020-11-01 23:01:36 +01:00
# Install additional languages if specified
if [[ ! -z "$PAPERLESS_OCR_LANGUAGES" ]]; then
install_languages "$PAPERLESS_OCR_LANGUAGES"
fi
exec "$@"