mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Setup the defined user folders instead of always using the defaults at Docker startup
This commit is contained in:
		@@ -15,23 +15,36 @@ map_uidgid() {
 | 
				
			|||||||
	fi
 | 
						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() {
 | 
					initialize() {
 | 
				
			||||||
 | 
						# Change the user and group IDs if needed
 | 
				
			||||||
	map_uidgid
 | 
						map_uidgid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for dir in export data data/index media media/documents media/documents/originals media/documents/thumbnails; do
 | 
						# Check for overrides of certain folders
 | 
				
			||||||
		if [[ ! -d "../$dir" ]]; then
 | 
						map_folders
 | 
				
			||||||
			echo "Creating directory ../$dir"
 | 
					
 | 
				
			||||||
			mkdir ../$dir
 | 
						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
 | 
							fi
 | 
				
			||||||
	done
 | 
						done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	echo "Creating directory /tmp/paperless"
 | 
						local tmp_dir="/tmp/paperless"
 | 
				
			||||||
	mkdir -p /tmp/paperless
 | 
						echo "Creating directory ${tmp_dir}"
 | 
				
			||||||
 | 
						mkdir -p "${tmp_dir}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	set +e
 | 
						set +e
 | 
				
			||||||
	echo "Adjusting permissions of paperless files. This may take a while."
 | 
						echo "Adjusting permissions of paperless files. This may take a while."
 | 
				
			||||||
	chown -R paperless:paperless /tmp/paperless
 | 
						chown -R paperless:paperless ${tmp_dir}
 | 
				
			||||||
	find .. -not \( -user paperless -and -group paperless \) -exec chown paperless:paperless {} +
 | 
						for dir in ${DATA_DIR} ${MEDIA_ROOT_DIR}; do
 | 
				
			||||||
 | 
							find "${dir}" -not \( -user paperless -and -group paperless \) -exec chown paperless:paperless {} +
 | 
				
			||||||
 | 
						done
 | 
				
			||||||
	set -e
 | 
						set -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gosu paperless /sbin/docker-prepare.sh
 | 
						gosu paperless /sbin/docker-prepare.sh
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,16 +3,17 @@
 | 
				
			|||||||
set -e
 | 
					set -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wait_for_postgres() {
 | 
					wait_for_postgres() {
 | 
				
			||||||
	attempt_num=1
 | 
						local attempt_num=1
 | 
				
			||||||
	max_attempts=5
 | 
						local max_attempts=5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	echo "Waiting for PostgreSQL to start..."
 | 
						echo "Waiting for PostgreSQL to start..."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	host="${PAPERLESS_DBHOST:=localhost}"
 | 
						local host="${PAPERLESS_DBHOST:-localhost}"
 | 
				
			||||||
	port="${PAPERLESS_DBPORT:=5432}"
 | 
						local port="${PAPERLESS_DBPORT:-5432}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# Disable warning, host and port can't have spaces
 | 
				
			||||||
	while [ ! "$(pg_isready -h $host -p $port)" ]; do
 | 
						# shellcheck disable=SC2086
 | 
				
			||||||
 | 
						while [ ! "$(pg_isready -h ${host} -p ${port})" ]; do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if [ $attempt_num -eq $max_attempts ]; then
 | 
							if [ $attempt_num -eq $max_attempts ]; then
 | 
				
			||||||
			echo "Unable to connect to database."
 | 
								echo "Unable to connect to database."
 | 
				
			||||||
@@ -43,17 +44,18 @@ migrations() {
 | 
				
			|||||||
		flock 200
 | 
							flock 200
 | 
				
			||||||
		echo "Apply database migrations..."
 | 
							echo "Apply database migrations..."
 | 
				
			||||||
		python3 manage.py migrate
 | 
							python3 manage.py migrate
 | 
				
			||||||
	) 200>/usr/src/paperless/data/migration_lock
 | 
						) 200>"${DATA_DIR}/migration_lock"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
search_index() {
 | 
					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..."
 | 
							echo "Search index out of date. Updating..."
 | 
				
			||||||
		python3 manage.py document_index reindex --no-progress-bar
 | 
							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
 | 
						fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user