ScanServJS

At first i tried to make saned work, the great network extension to Sane scan tool for Linux. Unfortunately it turns out that the scanner i own (a MFD HP Laser printer/scanner) cannot be shared with saned over the network because the HP provided driver does not allow it. Frankly it seems more an oversight / bug than anything else, but still that's an issue, because i do not want to install HP drivers on all my computers just for scanning.

Luckly, ScanServJS is very nice, simple and powerful WEB GUI to the sane backend which works wonders and can be self-hosted on your home server.

Prerequisites

ScanServJs require, of course, sane-backends package to be installed and your scanners to be configured to work locally on the server. I will not cover those steps here, i assume your scanner is already properly configured and can scan with the saned user on the server.

You must install nodejs and the deb2targz packages, because ScanServJS is deployed as a DEB package and requires NodeJS to run.

So, if you don't already have them:

emerge -vp app-arch/deb2targz nodejs

Also, you might want to install tesseract to enable OCR functionalities.

Installation

You will need to alter a little bit the content of the DEB package, because it's better to install it on /opt/scanservjs rather than having it mess with your /usr and /var system folders, so as root:

mkdir /opt/scanservjs
chown saned:scanner /opt/scanservjs

And then now, as user saned:

sudo -u saned bash
cd /opt/scanservjs
wget https://github.com/sbs20/scanservjs/releases/ << get here latest deb file for your server >>
deb2targz scanservjs_X.Y.Z-1_all.deb
tar xvf scanservjs_X.Y.Z-1_all.tar.xz
cd usr/lib/scanservjs

Now, since the DEB package assumes it's installed on /usr you need to recreate two symlinks:

 rm config 
ln -s /opt/scanservjs/etc/scanservjs config
 rm data 
ln -s /opt/scanservjs/var/lib/scanservjs data

Now move the default config file from /opt/scanservjs/etc/scanservjs/config.default.js to /opt/scanservjs/etc/scanservjs/config.local.js and edit to resemble the following (adapt where needed):

config.local.js
const options = { paths: ['/opt/scanservjs/usr/lib/scanservjs'] };
    config.host = '127.0.0.1';
    config.port = 7781;
    config.scanimage = '/usr/sbin/scanimage';
    config.convert = '/usr/bin/convert';
... [ omissis ] ...

And that's it!

NGINX configuration

I choose to install ScanServJS as a sub-path of my home.mydomain.com, so this is the relative NGINX config file:

scanner.conf
location = /scanner {
        return 301 https://$host/scanner/;
}

# Interfaccia Web stmapante HP
location /scanner/ {
        proxy_pass http://10.70.43.1:7781/;
}

For more details, see The Reverse Proxy concept

And restart your NGINX service.

Start and Autostart

Since i use OpenRC, just drop the following /etc/init.d/scanservjs:

scanservjs
#!/sbin/openrc-run
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

description="SCan from web interface"
pidfile="/run/scanservjs.pid"
command_background=true
command="node /opt/scanservjs/usr/lib/scanservjs/server/server.js "
command_args=""
command_user="saned:scanner"

depend() {
        need net
}

start_pre()
{
        cd /opt/scanservjs/usr/lib/scanservjs
        export NODE_ENV=production
}

make it executable and add it to the default runlevel:

chmod +x /etc/init.d/scanservjs
rc-update add /etc/init.d/scanservjs default
 /etc/init.d/scanservjs start

Update

Get new DEB, replace files, restart!