Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installer, docs and preview by source #207

Merged
merged 16 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ complicated installation.
* Filters: Autolevels, Threshold, Blur
* Configurable overrides for all defaults as well as filters and formats
* Multipage scanning (with collation for double sided scans)
* International translations: Czech, French, German, Italian, Mandarin, Spanish
(**help requested**)
* Light and dark mode
* **NEW**: International translations: Czech, French, German, Italian, Mandarin,
Spanish (**help requested**)
* Responsive design

It supports any
[SANE compatible devices](http://www.sane-project.org/sane-supported-devices.html).
Expand Down
39 changes: 27 additions & 12 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Running scanservjs under docker

If you're already running Debian, Ubuntu or similar, and haven't used docker
before then it's probably easier just to install directly. For what it's worth,
that is my preferred installation method.

## Quickstart

Get the image
Expand Down Expand Up @@ -38,8 +42,9 @@ you're putting a lot of trust in the container. In short, best not.

Depending on your setup you have a number of options.

* If your scanner is connected by USB to the host then you can map the device.
The best way to do this is to map the actual USB ports.
* If your scanner is connected by USB to the host, and there are standard SANE
drivers, then you can map the device. The best way to do this is to map the
actual USB ports.
* Run `sudo sane-find-scanner -q` and you will get a result like
`found USB scanner (vendor=0x04a9 [Canon], product=0x220d [CanoScan], chip=LM9832/3) at libusb:001:003`.
* Or run `lsusb` which gives you
Expand Down Expand Up @@ -69,10 +74,14 @@ Depending on your setup you have a number of options.
network. Adding more backends to the docker container feels wrong and will add
cruft for many users who don't need it.

* The best fallback position for many cases is simply to
[share the host scanner over the network](https://github.com/sbs20/scanservjs/issues/129#issuecomment-800226184)
and referencing that within the guest. This means that the docker container is
just running the app.
* The best fallback position for most cases is simply to
[share the host scanner over the network](https://github.com/sbs20/scanservjs/blob/master/docs/sane.md#configuring-the-server)
on the host (where the scanner is connected) and then set the
`SANED_NET_HOSTS`
[environment variable](https://github.com/sbs20/scanservjs/blob/master/docs/docker.md#environment-variables)
on the docker container.
[This](https://github.com/sbs20/scanservjs/issues/129#issuecomment-800226184)
user uses docker compose instead. See examples below.

## Mapping volumes

Expand Down Expand Up @@ -108,22 +117,28 @@ The solution in most cases is either to
* `AIRSCAN_DEVICES`: If you want to specifically add `sane-airscan` devices to
your `/etc/sane.d/airscan.conf` then use the `AIRSCAN_DEVICES` environment
variable (semicolon delimited).
* `DELIMITER`: if you need to inlcude semi-colons (`;`) in your environment
* `DELIMITER`: if you need to include semi-colons (`;`) in your environment
variables, this allows you to choose an alternative delimiter.
* `DEVICES`: Force add devices use `DEVICES` (semicolon delimited)
* `SCANIMAGE_LIST_IGNORE`: To force ignore `scanimage -L`

## Examples

### Connect to the scanner over the network (recommended)
```sh
docker run -d -p 8080:8080 \
-e SANED_NET_HOSTS="10.0.100.30" \
--name scanservjs-container sbs20/scanservjs:latest
```

### Mapped USB device with mapped volumes

```sh
docker run -d \
-p 8080:8080 \
docker run -d -p 8080:8080 \
-v $HOME/scan-data:/app/data/output \
-v $HOME/scan-cfg:/app/config \
--device /dev/bus/usb/001/003:/dev/bus/usb/001/003 \
--name scanservjs-container scanservjs-image
--name scanservjs-container sbs20/scanservjs:latest
```

### Use airscan and a locally detected scanner
Expand All @@ -133,7 +148,7 @@ This should support most use cases
```sh
docker run -d -p 8080:8080 \
-v /var/run/dbus:/var/run/dbus \
--name scanservjs-container scanservjs-image
--name scanservjs-container sbs20/scanservjs:latest
```

### A bit of everything
Expand All @@ -150,7 +165,7 @@ docker run -d -p 8080:8080 \
-e DEVICES="net:10.0.100.30:plustek:libusb:001:003;net:10.0.100.31:plustek:libusb:001:003;airscan:e0:Canon TR8500 series;airscan:e1:EPSON Cool Series" \
-e OCR_LANG="fra" \
-v /var/run/dbus:/var/run/dbus \
--name scanservjs-container --privileged scanservjs-image
--name scanservjs-container --privileged sbs20/scanservjs:latest
```

## Staging builds
Expand Down
59 changes: 33 additions & 26 deletions docs/sane.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ Just use your package manager.

Either try:

```
```sh
$ scanimage -L
device `net:localhost:plustek:libusb:001:004' is a Canon CanoScan N1240U/LiDE30 flatbed scanner
```

or
```

```sh
$ sane-find-scanner -q
found USB scanner (vendor=0x04a9 [Canon], product=0x220d [CanoScan]) at libusb:003:005
```
Expand All @@ -37,41 +38,47 @@ underlying problem is. In order of likelihood:

## Defining network scanners

From the scanimage manpage:
### Configuring the server

> The -L or --list-devices option requests a (partial) list of devices that are
> available. The list is not complete since some devices may be available, but
> are not listed in any of the configuration files (which are typically stored
> in directory /etc/sane.d). This is particularly the case when accessing
> scanners through the network. If a device is not listed in a configuration
> file, the only way to access it is by its full device name. You may need to
> consult your system administrator to find out the names of such devices.
Assume the host (the device the scanner is connected to) has an IP of
`192.168.0.10`

Find the name of the scanner on the remote server by running `scanimage -L` (on
the remote server) e.g:

```
device `airscan:e0:Canon TR8500 series' is a eSCL Canon TR8500 series eSCL network scanner
```sh
# Allow access from the following networks
## Local network
echo "192.168.0.0/24" >> /etc/sane.d/saned.conf
## Default docker network
echo "172.17.0.0/16" >> /etc/sane.d/saned.conf
sudo systemctl enable saned.socket
sudo systemctl start saned.socket
```

Then on the client, prefix it with `net:<ip-address>:` The result is the device
to use with scanimage. Using the value above we get:
### Configuring the client

Add the host (`192.168.0.10`) to the client.

```sh
echo "192.168.0.10" >> /etc/sane.d/net.conf
```
net:192.168.0.10:airscan:e0:Canon TR8500 series
```

Now if you run `scanimage -L` on the client you should see the scanner on the
host (prefixed with `net:192.168.0.10:`)

For more information on configuring the server and client see
[SaneOverNetwork](https://wiki.debian.org/SaneOverNetwork#Server_Configuration).

### TL;DR; configuring server:
It's worth noting that network scanners do not always show up on the client. In
such cases you will need to get the device name from the host, prefix it with
`net:$ip:` and use the `-d` switch. From the scanimage manpage:

> The -L or --list-devices option requests a (partial) list of devices that are
> available. The list is not complete since some devices may be available, but
> are not listed in any of the configuration files (which are typically stored
> in directory /etc/sane.d). This is particularly the case when accessing
> scanners through the network. If a device is not listed in a configuration
> file, the only way to access it is by its full device name. You may need to
> consult your system administrator to find out the names of such devices.

```console
# Allow access from network
echo "192.168.0.1/24" >> /etc/sane.d/saned.conf
sudo systemctl enable saned.socket
sudo systemctl start saned.socket
```

## SANE Airscan

Expand Down
38 changes: 33 additions & 5 deletions server/bin/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,42 @@ install() {
# Reload the deamon info
systemctl daemon-reload

# Enable and start the new service
if [ -z "$(netstat -tulpn | grep '\:8080\s')" ]; then
# Enable and start the new service
systemctl enable scanservjs
systemctl start scanservjs

cat << EOF

scanservjs installed and running
http://127.0.0.1:8080
EOF

else
cat << EOF

scanservjs installed but it looks as if something might be running on port 8080.

$ netstat -tulpn | grep :8080 --->
$(netstat -tulpn | grep ":8080\s")

Either
* update the port in $location/config/config.local.js or
* Stop the other program

After that you can just enable and start:
systemctl enable scanservjs
systemctl start scanservjs
EOF
fi

cat << EOF

If you encounter problems when running, try
sudo journalctl -e -u scanservjs

EOF

echo "scanservjs installed and running"
echo "http://127.0.0.1:8080"
echo
echo "If you have problems, try 'sudo journalctl -e -u scanservjs'"
}

uninstall() {
Expand Down
2 changes: 1 addition & 1 deletion server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scanservjs-server",
"version": "2.9.2",
"version": "2.10.0",
"description": "scanservjs is a simple web-based UI for SANE which allows you to share a scanner on a network without the need for drivers or complicated installation. scanserv does not do image conversion or manipulation (beyond the bare minimum necessary for the purposes of browser preview) or OCR.",
"scripts": {
"serve": "nodemon --exec 'vue-cli-service serve'",
Expand Down
19 changes: 12 additions & 7 deletions server/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Api {
params: {
deviceId: req.params.deviceId,
mode: req.params.mode,
source: req.params.source,
resolution: Config.previewResolution,
brightness: req.params.brightness,
contrast: req.params.contrast,
Expand Down Expand Up @@ -95,13 +96,17 @@ class Api {
// If not then it's possible the default image is not quite the correct aspect ratio
const buffer = new FileInfo(`${Config.previewDirectory}default.jpg`).toBuffer();

// We need to know the correct AR from the device
const context = await Context.create();
const device = context.getDevice();
const heightByWidth = device.features['-y'].limits[1] / device.features['-x'].limits[1];
const width = 868;
const height = Math.round(width * heightByWidth);
return await Process.spawn(`convert - -resize ${width}x${height}! jpg:-`, buffer);
try {
// We need to know the correct aspect ratio from the device
const context = await Context.create();
const device = context.getDevice();
const heightByWidth = device.features['-y'].limits[1] / device.features['-x'].limits[1];
const width = 868;
const height = Math.round(width * heightByWidth);
return await Process.spawn(`convert - -resize ${width}x${height}! jpg:-`, buffer);
} catch (e) {
return Promise.resolve(buffer);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion webui/src/components/About.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div>
<div class="text-h2">{{ $t('global.application-name') }} v{{ version }}</div>
<div class="text-h5">{{ $t('global.application-name') }}</div>
<div class="text-h6">v{{ version }}</div>
<div class="caption mb-4">&copy; 2016 - {{ new Date().getFullYear() }} Sam Strachan</div>
<div class="body-1 mb-4">
{{ $t('about.main') }}
Expand Down
4 changes: 2 additions & 2 deletions webui/src/components/Scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ export default {

methods: {
_resizePreview() {
const paperRatio = this.device.features['-x'].limits[1] /
this.device.features['-y'].limits[1];
const paperRatio = this.deviceSize.width / this.deviceSize.height;

// This only makes a difference when the col-width="auto" - so md+
const mdBreakpoint = 960;
Expand Down Expand Up @@ -433,6 +432,7 @@ export default {
}
}).then(data => {
this.img = 'data:image/jpeg;base64,' + data.content;
this._resizePreview();
});
},

Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<div class="text-h2 mb-4">{{ $t('settings.title') }}</div>
<div class="text-h5 mb-4">{{ $t('settings.title') }}</div>
<settings-section>
<template v-slot:title>{{ $t('settings.behaviour-ui') }}</template>
<template v-slot:items>
Expand Down
2 changes: 1 addition & 1 deletion webui/src/locales/cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"left": "Vlevo",
"width": "Šířka",
"height": "Výška",
"paperSize": "Paper size",
"paperSize": "Velikost papíru",
"brightness": "Jas",
"contrast": "Kontrast",
"message:loading-devices": "Načítání zařízení...",
Expand Down
2 changes: 1 addition & 1 deletion webui/src/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"left": "Sinistra",
"width": "Larghezza",
"height": "Altezza",
"paperSize": "Paper size",
"paperSize": "Formato carta",
"brightness": "Luminosità",
"contrast": "Contrasto",
"message:loading-devices": "Caricamento dispositivi...",
Expand Down