Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Setup the defined user folders instead of always using the defaults at Docker startup

Trenton Holmesd118f4a3f079
diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh
index 6079d03df..0794da5ae 100755
--- a/docker/docker-entrypoint.sh
+++ b/docker/docker-entrypoint.sh
@@ -15,23 +15,36 @@ map_uidgid() {
fi
}
+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}"
+}
+
initialize() {
+ # Change the user and group IDs if needed
map_uidgid
- for dir in export data data/index media media/documents media/documents/originals media/documents/thumbnails; do
- if [[ ! -d "../$dir" ]]; then
- echo "Creating directory ../$dir"
- mkdir ../$dir
+ # Check for overrides of certain folders
+ map_folders
+
+ for dir in ${DATA_DIR} ${DATA_DIR}/index ${MEDIA_ROOT_DIR} ${MEDIA_ROOT_DIR}/documents ${MEDIA_ROOT_DIR}/documents/originals ${MEDIA_ROOT_DIR}/documents/thumbnails; do
+ if [[ ! -d "${dir}" ]]; then
+ echo "Creating directory ${dir}"
+ mkdir "${dir}"
fi
done
- echo "Creating directory /tmp/paperless"
- mkdir -p /tmp/paperless
+ local tmp_dir="/tmp/paperless"
+ echo "Creating directory ${tmp_dir}"
+ mkdir -p "${tmp_dir}"
set +e
echo "Adjusting permissions of paperless files. This may take a while."
- chown -R paperless:paperless /tmp/paperless
- find .. -not \( -user paperless -and -group paperless \) -exec chown paperless:paperless {} +
+ chown -R paperless:paperless ${tmp_dir}
+ for dir in ${DATA_DIR} ${MEDIA_ROOT_DIR}; do
+ find "${dir}" -not \( -user paperless -and -group paperless \) -exec chown paperless:paperless {} +
+ done
set -e
gosu paperless /sbin/docker-prepare.sh
diff --git a/docker/docker-prepare.sh b/docker/docker-prepare.sh
index 1756d88c4..879e1653a 100755
--- a/docker/docker-prepare.sh
+++ b/docker/docker-prepare.sh
@@ -3,16 +3,17 @@
set -e
wait_for_postgres() {
- attempt_num=1
- max_attempts=5
+ local attempt_num=1
+ local max_attempts=5
echo "Waiting for PostgreSQL to start..."
- host="${PAPERLESS_DBHOST:=localhost}"
- port="${PAPERLESS_DBPORT:=5432}"
+ local host="${PAPERLESS_DBHOST:-localhost}"
+ local port="${PAPERLESS_DBPORT:-5432}"
-
- while [ ! "$(pg_isready -h $host -p $port)" ]; do
+ # Disable warning, host and port can't have spaces
+ # shellcheck disable=SC2086
+ while [ ! "$(pg_isready -h ${host} -p ${port})" ]; do
if [ $attempt_num -eq $max_attempts ]; then
echo "Unable to connect to database."
@@ -43,17 +44,18 @@ migrations() {
flock 200
echo "Apply database migrations..."
python3 manage.py migrate
- ) 200>/usr/src/paperless/data/migration_lock
+ ) 200>"${DATA_DIR}/migration_lock"
}
search_index() {
- index_version=1
- index_version_file=/usr/src/paperless/data/.index_version
- if [[ (! -f "$index_version_file") || $(<$index_version_file) != "$index_version" ]]; then
+ local index_version=1
+ local index_version_file=${DATA_DIR}/.index_version
+
+ if [[ (! -f "${index_version_file}") || $(<"${index_version_file}") != "$index_version" ]]; then
echo "Search index out of date. Updating..."
python3 manage.py document_index reindex --no-progress-bar
- echo $index_version | tee $index_version_file >/dev/null
+ echo ${index_version} | tee "${index_version_file}" >/dev/null
fi
}