Skip to content

Instantly share code, notes, and snippets.

@erikarvstedt
Created August 20, 2018 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikarvstedt/56df979df9cabcf714cfcb5e0dc71d0c to your computer and use it in GitHub Desktop.
Save erikarvstedt/56df979df9cabcf714cfcb5e0dc71d0c to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
set -euo pipefail
nixpkgs=$(nix eval --raw '(builtins.fetchTarball https://github.com/erikarvstedt/nixpkgs/archive/paperless.tar.gz)')
if [[ $PATH != *paperlessDemoEnv* ]]; then
nix-build --out-link /tmp/paperlessDemoEnv -E '
with (import <nixpkgs> {});
let
extra-container = callPackage (builtins.fetchGit {
url = "https://github.com/erikarvstedt/extra-container.git";
rev = "d2d732456d478168d62124ed112396ed28f7d116";
}) {};
in
buildEnv {
name = "paperlessDemoEnv";
paths = [ extra-container jq imagemagick ];
}
' > /dev/null
export PATH=/tmp/paperlessDemoEnv/bin${PATH:+:}$PATH
fi
## Create a container with a Paperless instance.
# For unknown reasons, when using `nixos-container create` the server process
# needs > 30 sec until it opens its socket.
# Work around this by using `extra-container`.
NIX_PATH=nixpkgs=$nixpkgs sudo extra-container create --start <<EOF
{
containers.pldemo = {
config = {
services.paperless = {
enable = true;
address = "0.0.0.0";
};
};
};
}
EOF
# Create a test document
sudo convert -size 400x40 xc:white -font "DejaVu-Sans" -pointsize 20 -fill black -annotate +5+20 \
"hello world 16-10-2005" /var/lib/containers/pldemo/var/lib/paperless/consume/doc.png
# Wait until the document is consumed
while [[ $(curl -s localhost:28981/api/documents/ | jq .count) != 1 ]]; do sleep 0.1; done
# Show documents
curl -s localhost:28981/api/documents/ | jq
sudo extra-container destroy pldemo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment