Skip to content

Commit

Permalink
Airscan, multiple saned hosts etc #83 #84 #85 #86
Browse files Browse the repository at this point in the history
  • Loading branch information
sbs20@omicron.sbs20.com committed Oct 11, 2020
1 parent e253d94 commit 03669f6
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 22 deletions.
30 changes: 23 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,38 @@ WORKDIR "$APP_DIR"
COPY package*.json "$APP_DIR/"
RUN npm install
COPY . "$APP_DIR"
RUN npm run server-build
RUN npm run client-build
RUN npm run server-build && npm run client-build

# production image
FROM node:buster-slim
ENV APP_DIR=/app
WORKDIR "$APP_DIR"
# Install sane
RUN apt-get update && apt-get install -yq sane sane-utils imagemagick tesseract-ocr
RUN sed -i 's/policy domain="coder" rights="none" pattern="PDF"/policy domain="coder" rights="read | write" pattern="PDF"'/ /etc/ImageMagick-6/policy.xml
COPY --from=builder "$APP_DIR/dist" "$APP_DIR/"

# Install dependencies
RUN apt-get update && \
apt-get install -yq curl gpg && \
echo 'deb http://download.opensuse.org/repositories/home:/pzz/Debian_10/ /' | tee /etc/apt/sources.list.d/home:pzz.list && \
curl -fsSL https://download.opensuse.org/repositories/home:pzz/Debian_10/Release.key | gpg --dearmor | tee /etc/apt/trusted.gpg.d/home:pzz.gpg > /dev/null && \
apt-get update && \
apt-get install -yq sane sane-utils imagemagick tesseract-ocr sane-airscan && \
sed -i 's/policy domain="coder" rights="none" pattern="PDF"/policy domain="coder" rights="read | write" pattern="PDF"'/ /etc/ImageMagick-6/policy.xml

RUN npm install --production

ENV NET_HOST=""
# This goes into /etc/sane.d/net.conf
ENV SANED_NET_HOSTS=""

# This gets added to /etc/sane.d/airscan.conf
ENV AIRSCAN_DEVICES=""

# This directs scanserv not to bother querying `scanimage -L`
ENV SCANIMAGE_LIST_IGNORE=""

# This gets added to scanservjs/config/config.js:devices
ENV DEVICES=""

# Override OCR language
ENV OCR_LANG=""

# Copy entry point
COPY run.sh /run.sh
Expand Down
20 changes: 14 additions & 6 deletions client/components/Scanserv.vue
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,21 @@ export default {
return this._fetch(url).then(context => {
this.context = context;
this.device = context.devices[0];
this.$refs.toastr.i(`Found device ${this.device.id}`);
this.request = this.readRequest();
for (let test of context.diagnostics) {
const toast = test.success ? this.$refs.toastr.s : this.$refs.toastr.e;
toast(test.message);
if (context.devices.length > 0) {
for (let device of context.devices) {
this.$refs.toastr.i(`Found device ${device.id}`);
}
this.device = context.devices[0];
this.request = this.readRequest();
for (let test of context.diagnostics) {
const toast = test.success ? this.$refs.toastr.s : this.$refs.toastr.e;
toast(test.message);
}
} else {
this.$refs.toastr.e('Found no devices');
}
if (force) {
this.clear();
this.readPreview();
Expand Down
26 changes: 23 additions & 3 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const Config = {};
// Things to change
Config.port = 8080;

// scanservjs will attempt to find scanners locally using `scanimage -L` but you
// will need to manually add network devices here which will be appended. e.g.
// Config.devices = ['net:192.168.0.10:airscan:e0:Canon TR8500 series'];
Config.devices = [];
Config.ocrLanguage = 'eng';
Config.log = {};
Expand Down Expand Up @@ -177,4 +174,27 @@ if (Config.tesseract) {
]);
}

// Process environment variables

// scanservjs will attempt to find scanners locally using `scanimage -L` but
// sometimes you may need to manually add network devices here if they're not
// found e.g.
// Config.devices = ['net:192.168.0.10:airscan:e0:Canon TR8500 series'];
// This is done with an environment variable. Multiple entries are separated by
// semicolons
if (process.env.DEVICES !== undefined && process.env.DEVICES.length > 0) {
Config.devices = process.env.DEVICES.split(';');
}

// scanservjs will attempt to find scanners locally using `scanimage -L` but
// sometimes it will return nothing. If you are specifying devices manually you
// may also with to turn off the find.
Config.devicesFind = process.env.SCANIMAGE_LIST_IGNORE === undefined
|| process.env.SCANIMAGE_LIST_IGNORE.length === 0;

// Override the OCR language here
if (process.env.OCR_LANG !== undefined && process.env.OCR_LANG.length > 0) {
Config.ocrLanguage = process.env.OCR_LANG;
}

module.exports = Config;
4 changes: 4 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ gulp release
Install docker
```
sudo apt install docker.io
sudo systemctl unmask docker
sudo systemctl start docker
# Hack to make docker accessible.
sudo chmod 666 /var/run/docker.sock
```

Expand Down
28 changes: 27 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#!/bin/sh
set -xve
[ ! -z "$NET_HOST" ] && echo $NET_HOST > /etc/sane.d/net.conf

# turn off globbing
set -f

# split at newlines only (airscan devices can have spaces in)
IFS='
'

# Insert a list of net hosts
if [ ! -z "$SANED_NET_HOSTS" ]; then
hosts=$(echo $SANED_NET_HOSTS | sed "s/;/\n/")
for host in $hosts; do
echo $host >> /etc/sane.d/net.conf
done
fi

# Insert airscan devices
if [ ! -z "$AIRSCAN_DEVICES" ]; then
devices=$(echo $AIRSCAN_DEVICES | sed "s/;/\n/")
for device in $devices; do
sed -i "/^\[devices\]/a $device" /etc/sane.d/airscan.conf
done
fi

unset IFS
set +f

node ./server/server.js

13 changes: 8 additions & 5 deletions server/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ class Devices {
}

if (devices === null) {
let data = await Process.execute(Scanimage.devices());
log.debug('Device list: ', data);
const localDevices = Devices._parseDevices(data);
const deviceIds = localDevices.concat(Config.devices);
let deviceIds = Config.devices;
if (Config.devicesFind) {
const data = await Process.execute(Scanimage.devices());
log.debug('Device list: ', data);
const localDevices = Devices._parseDevices(data);
deviceIds = deviceIds.concat(localDevices);
}

devices = [];
for (let deviceId of deviceIds) {
data = await Process.execute(Scanimage.features(deviceId));
const data = await Process.execute(Scanimage.features(deviceId));
log.debug('Device features: ', data);
devices.push(Device.from(data));
}
Expand Down

0 comments on commit 03669f6

Please sign in to comment.