2022-03-26 13:21:17 -07:00
#!/usr/bin/env bash
2020-10-29 00:46:57 +01:00
2016-02-17 18:45:04 +01:00
set -e
# Source: https://github.com/sameersbn/docker-gitlab/
map_uidgid() {
2021-05-19 22:26:51 +02:00
USERMAP_ORIG_UID = $( id -u paperless)
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 "
2022-03-18 23:26:04 +01:00
usermod -o -u " ${ USERMAP_NEW_UID } " paperless
2021-05-19 22:26:51 +02:00
groupmod -o -g " ${ USERMAP_NEW_GID } " paperless
fi
2016-02-17 18:45:04 +01:00
}
2022-06-03 09:18:48 -07:00
map_folders() {
# Export these so they can be used in docker-prepare.sh
export DATA_DIR = " ${ PAPERLESS_DATA_DIR :- /usr/src/paperless/data } "
export MEDIA_ROOT_DIR = " ${ PAPERLESS_MEDIA_ROOT :- /usr/src/paperless/media } "
}
2016-02-17 18:45:04 +01:00
initialize() {
2022-06-03 09:18:48 -07:00
# Change the user and group IDs if needed
2020-10-29 00:46:57 +01:00
map_uidgid
2016-02-17 18:45:04 +01:00
2022-06-03 09:18:48 -07:00
# Check for overrides of certain folders
map_folders
2022-06-03 14:02:58 -07:00
local export_dir = "/usr/src/paperless/export"
for dir in " ${ export_dir } " " ${ DATA_DIR } " " ${ DATA_DIR } /index" " ${ MEDIA_ROOT_DIR } " " ${ MEDIA_ROOT_DIR } /documents" " ${ MEDIA_ROOT_DIR } /documents/originals" " ${ MEDIA_ROOT_DIR } /documents/thumbnails" ; do
2022-06-03 09:18:48 -07:00
if [[ ! -d " ${ dir } " ]] ; then
echo "Creating directory ${ dir } "
mkdir " ${ dir } "
2020-10-29 00:46:57 +01:00
fi
done
2016-02-17 18:45:04 +01:00
2022-06-03 09:18:48 -07:00
local tmp_dir = "/tmp/paperless"
echo "Creating directory ${ tmp_dir } "
mkdir -p " ${ tmp_dir } "
2021-01-21 01:02:41 +01:00
2021-05-19 22:26:51 +02:00
set +e
2021-06-13 12:54:24 +02:00
echo "Adjusting permissions of paperless files. This may take a while."
2022-06-03 09:18:48 -07:00
chown -R paperless:paperless ${ tmp_dir }
2022-06-03 14:02:58 -07:00
for dir in " ${ export_dir } " " ${ DATA_DIR } " " ${ MEDIA_ROOT_DIR } " ; do
2022-06-03 09:18:48 -07:00
find " ${ dir } " -not \( -user paperless -and -group paperless \) -exec chown paperless:paperless {} +
done
2021-05-19 22:26:51 +02:00
set -e
2020-10-29 00:46:57 +01:00
2021-05-19 22:26:51 +02:00
gosu paperless /sbin/docker-prepare.sh
2020-10-29 00:46:57 +01:00
}
2017-12-20 16:17:58 +02:00
2020-10-29 00:46:57 +01:00
install_languages() {
2021-01-13 19:58:09 +01:00
echo "Installing languages..."
2020-10-29 00:46:57 +01:00
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
2021-05-19 22:26:51 +02:00
pkg = "tesseract-ocr- $lang "
# English is installed by default
#if [[ "$lang" == "eng" ]]; then
# continue
#fi
2022-03-20 15:58:37 +01:00
if dpkg -s " $pkg " & >/dev/null; then
2021-05-19 22:26:51 +02:00
echo "Package $pkg already installed!"
continue
fi
2022-03-20 15:58:37 +01:00
if ! apt-cache show " $pkg " & >/dev/null; then
2021-05-19 22:26:51 +02:00
echo "Package $pkg not found! :("
continue
fi
echo "Installing package $pkg ..."
if ! apt-get -y install " $pkg " & >/dev/null; then
echo "Could not install $pkg "
exit 1
fi
done
2016-02-17 18:45:04 +01:00
}
2022-03-01 14:09:09 -08:00
echo "Paperless-ngx docker container starting..."
2021-01-13 19:58:09 +01:00
2020-11-01 23:01:36 +01:00
# Install additional languages if specified
2022-03-20 15:58:37 +01:00
if [[ -n " $PAPERLESS_OCR_LANGUAGES " ]] ; then
2021-05-19 22:26:51 +02:00
install_languages " $PAPERLESS_OCR_LANGUAGES "
2016-02-17 18:45:04 +01:00
fi
2020-12-09 23:45:53 +01:00
initialize
2020-11-13 18:42:32 +01:00
if [[ " $1 " != "/" * ]] ; then
2021-01-13 19:58:09 +01:00
echo Executing management command " $@ "
2021-04-26 19:06:30 -05:00
exec gosu paperless python3 manage.py " $@ "
2020-11-13 18:42:32 +01:00
else
2021-01-13 19:58:09 +01:00
echo Executing " $@ "
2020-11-13 18:42:32 +01:00
exec " $@ "
fi