Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Last active August 6, 2017 15:14
Show Gist options
  • Save fliiiix/8acca998a59869c95dea1404541c4bf1 to your computer and use it in GitHub Desktop.
Save fliiiix/8acca998a59869c95dea1404541c4bf1 to your computer and use it in GitHub Desktop.
OCR on Nextcloud 12 with Freebsd

pkglist for poudriere

# nextcloud
www/nginx
www/php70-opcache
devel/php70-pcntl
databases/pecl-redis
www/nextcloud
# nextcould OCR
graphics/tesseract
graphics/tesseract-data
graphics/unpaper
print/ghostscript9-agpl-base
print/qpdf
lang/python36
devel/py3-pip
devel/py3-cffi
databases/py36-sqlite3
www/node6
www/npm3
databases/redis

Note: graphics/unpaper & databases/redis should be updated in the ports

Install all pkgs. This is after your Nextcloud is already running!

$ pkg install vim-lite git graphics/tesseract graphics/tesseract-data graphics/unpaper print/ghostscript9-agpl-base print/qpdf lang/python36 devel/py3-pip devel/py3-cffi databases/py36-sqlite3 www/node6 www/npm3 databases/redis databases/pecl-redis

setup redis is super easy

$ echo redis_enable="YES" >> /etc/rc.conf
$ service redis start 

Install more things, to be precise ocrmypdf

$ pip-3.6 install setuptools ocrmypdf

Needs more work don't like the dir structure

mkdir -p /home/node/worker && mkdir /home/node/output
#/data should be your nextcloud data dir
ln -s /data/ /home/node/data
chown -R www /home/node/output
chown -h www /home/node/data

Add to the config: nextcloud/config/config.php

'tempdirectory' => '/home/node/output',

Install the plugin to your Nextcloud

$ git clone https://github.com/janis91/ocr /usr/local/www/nextcloud/apps/ocr
$ cd /usr/local/www/nextcloud/apps/ocr
$ git checkout 57b2bbf5001373da8936a7b3a21dc9c3999ee97d

Create and setup the node worker

# copy the worker stuff 
cp -r /usr/local/www/nextcloud/apps/ocr/worker/* /home/node/worker
cd /home/node/worker

npm install
npm run build

Configure the OUTPUT_PATH to '' since the tempdirectory from the nextcould config is used.

./dist/configuration/worker.configuration.js
Configuration.OUTPUT_PATH = '';

Test your setup:

$ setenv REDIS_HOST 127.0.0.1
$ su -m www -c 'node /home/node/worker/dist/main.js'

Or just download the ocr service file to /usr/local/etc/rc.d and mark it executable with chmod +x /usr/local/etc/rc.d. And now you can add it to your rc.conf file ocr_enable="YES" and start & stop it like any other service service ocr start|stop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment