Obsah

Ultimate Raspberry Pi: LAN Print, Scan and PDF Server

Článek jsem měl historicky uložený a pochází ze zdroje, který už neexistuje. Jeho přesná název zněl: Ultimate Raspberry Pi : LAN Print , Scan and PDF Server : CUPS + AirPrint + IPP + cups-pdf + sanescan ( SaneTwain ) + phpSANE / PHP-Scanner-Server ( scanner webinterface ) + samba ( remote file access ).

Datum článku byl 2.4.2014. Samozřejmě už některé věci nebudou aktuální a je potřeba se přizpůsobit. Dávám zde alespoň přepis článku.

Assumptions

Install Dependencies

apt-get update && apt-get install -f avahi-daemon cups cups-pdf python-cups avahi-discover libnss-mdns sane-utils xinetd printer-driver-gutenprint system-config-printer-udev

Optional: Install one of the relevant printer drivers

apt-get install printer-driver-c2050 #printer driver for Lexmark 2050 Color Jetprinter
apt-get install printer-driver-c2esp #printer driver for Kodak ESP AiO color inkjet Series
apt-get install printer-driver-cjet #printer driver for Canon LBP laser printers
apt-get install printer-driver-escpr #printer driver for Epson Inkjet that use ESC P-R
apt-get install printer-driver-foo2zjs #printer driver for ZjStream-based printers
apt-get install printer-driver-gutenprint #printer drivers for CUPS
apt-get install printer-driver-hpcups #HP Linux Printing and Imaging - CUPS Raster driver (hpcups)
apt-get install printer-driver-hpijs #HP Linux Printing and Imaging - gs IJS driver (hpijs)
apt-get install printer-driver-m2300w #printer driver for Minolta magicolor 2300W 2400W color laser printers
apt-get install printer-driver-min12xxw #printer driver for KonicaMinolta PagePro 1[234]xxW
apt-get install printer-driver-pnm2ppa #printer driver for HP-GDI printers
apt-get install printer-driver-postscript-hp #HP Printers PostScript Descriptions
apt-get install printer-driver-ptouch #printer driver Brother P-touch label printers
apt-get install printer-driver-pxljr #printer driver for HP Color LaserJet 35xx 36xx
apt-get install printer-driver-sag-gdi #printer driver for Ricoh Aficio SP 1000s SP 1100s
apt-get install printer-driver-splix #Driver for Samsung and Xerox SPL2 and SPLc laser printers

Configure cups to listen on the LAN

sed -i "s|Listen localhost:631|Listen *:631|" /etc/cups/cupsd.conf

Allow LAN access to CUPS

sed -i "s|<Location />|<Location />\nAllow from all\n</Location>|g" /etc/cups/cupsd.conf

Add the server name and browse address

Replace 192.168.1.255 with your LAN broadcast address.

echo -e "\nServerName raspberrypi" >> /etc/cups/cupsd.conf
sed -i -e "s|BrowseAddress|BrowseAddress 192.168.1.255\n#BrowseAddress|" /etc/cups/cupsd.conf

Restart CUPS

service cups restart

Add the pi user to the lpadmin group

adduser pi lpadmin

Enable print sharing and remote administration

cupsctl --share-printers --remote-admin --remote-printers
sed -i "s|Shared No|Shared Yes|g" /etc/cups/printers.conf
lpoptions -d PDF -o printer-is-shared=true

Custom cups-pdf output directory

PDF storage directory: /storage/pdf

mkdir -p /storage/pdf
chown root:lpadmin /storage/pdf
chmod 777 /storage/pdf

Append the date to the PDF file name

mkdir -p /opt/extremeshok
cat > /opt/extremeshok/cups-pdf-postprocess <<EOF
#!/bin/bash
## eXtremeSHOK.com
FILENAME=\`basename $1\`
DIRNAME="/storage/pdf"
DATE=\`date +"%Y-%m-%d_%H-%M-%S"\`
mv $1 $DIRNAME"/"$DATE"_"$FILENAME
EOF

Enable cups-pdf post processing

chmod 777 /opt/extremeshok/cups-pdf-postprocess
chown root:lpadmin /opt/extremeshok/cups-pdf-postprocess
sed -i "s|#PostProcessing|PostProcessing /opt/extremeshok/cups-pdf-postprocess|" /etc/cups/cups-pdf.conf
sed -i "s|#PDFVer 1.4|PDFVer 1.5|" /etc/cups/cups-pdf.conf

Enable automatic retrying of failed print jobs

sed -i -e "s|BrowseAddress|ErrorPolicy retry-job\nJobRetryInterval 30\nBrowseAddress|" /etc/cups/cupsd.conf

Restart CUPS

service cups restart

Configure your printer

Visit the web interface: https://192.168.1.111:631/admin

Steps:

service cups restart
service avahi-daemon restart

Optional: Enable AirPrint

(Not needed on iOS 7 and above)

Enhanced iOS support:

echo "image/urf urf (0,UNIRAST)" > /usr/share/cups/mime/apple.types
mkdir /opt/AirPrint
cd /opt/AirPrint
wget -O airprint-generate.py --no-check-certificate https://raw.github.com/vidaren/airprint-generate/master/airprint-generate.py
chmod +x airprint-generate.py
./airprint-generate.py -d /etc/avahi/services --cups

Using your PDF postscript printer via IPP

Driver: Microsoft Windows

Via IPP: Use the following as the printer's location:

http://192.168.1.111:631/printers/PDF

Using your printer via IPP

Driver: Microsoft Vista and 7/8

Driver: Microsoft 2000 and XP

Via IPP: Use the following as the printer's location:

http://192.168.1.111:631/printers/printer_name

Optional: Enable Scanning

Enable scanning support and share a scanner on your network

Install:

apt-get install -f sane-utils xinetd

Enable the saned service:

echo -e "\n192.168.1.0/24" >> /etc/sane.d/saned.conf
sed -i "s|RUN=no|RUN=yes|g" /etc/default/saned

Enable the xinetd sane service:

cat > /etc/xinetd.d/saned <<EOF
# eXtremeSHOK.com
service saned {
    socket_type = stream
    server = /usr/sbin/saned
    protocol = tcp
    user = saned
    group = scanner
    wait = no
    disable = no
}
EOF

BUG FIX: Scanner not working: usbfs: interface 1 claimed by usblp while `scanimage` sets config #1:

echo -e "\nblacklist usblp" >> /etc/modprobe.d/blacklist.conf

Reboot:

sync && shutdown -r now

Verify the scanner is supported and listening:

scanimage -L

Example output:

device `xerox_mfp:libusb:001:004' is a Samsung Samsung SCX-4623 Series multi-function peripheral

Verify the service:

cat /etc/services | grep sane

Example output:

sane-port 6566/tcp sane saned # SANE network scanner daemon

Optional: phpSANE (Web-Based Frontend for SANE)

Note: Simple and low requirements.

Install Requirements:

apt-get install -y libapache2-mod-php5 unzip netpbm gocr imagemagick

Install phpSANE:

mkdir -p /tmp/phpSANE
cd /tmp/phpSANE
wget -O phpSANE-0.8.0.zip "http://downloads.sourceforge.net/project/phpsane/phpsane/0.8.0/phpSANE-0.8.0.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fphpsane%2F&use_mirror=tenet"
unzip -q phpSANE-0.8.0.zip
mv /tmp/phpSANE/* /var/www/

Configure:

sed -i "s|\" --jpeg-quality 0\"|\"\"|g" /var/www/incl/config.php
sed -i "s|/opt/bin/gocr|/usr/bin/gocr|g" /var/www/incl/config.php
sed -i "s|/usr/local/bin/pdfunite|/usr/bin/pdfunite|g" /var/www/incl/config.php
sed -i "s|Timeout 300|Timeout 900|g" /etc/apache2/apache2.conf
sed -i "s|max_execution_time = 30|max_execution_time = 900|g" /etc/php5/apache2/php.ini
sed -i "s|max_input_time = 60|max_input_time = 900|g" /etc/php5/apache2/php.ini

Set Permissions:

chmod +s /usr/bin/scanimage
mkdir -p /var/www/tmp && chmod 775 /var/www/tmp
mkdir -p /var/www/output && chmod 775 /var/www/output
mkdir -p /var/www/scanners && chmod 775 /var/www/scanners

Optional: PHP-Scanner-Server (Advanced Web-Based Frontend for SANE)

Note: Requires 1GB+ drive space and a 512MB Raspberry Pi.

Install Requirements:

apt-get install -y imagemagick sane-utils usbutils libapache2-mod-php5 php5-curl tesseract-ocr tar zip php-fpdf libpaper-utils grep sed coreutils

Add `www-data` to the `lp` group:

adduser www-data lp

Install PHP-Scanner-Server:

mkdir -p /tmp/PHP-Scanner-Server
cd /tmp/PHP-Scanner-Server
wget -O PHP-Scanner-Server.zip "https://github.com/GM-Script-Writer-62850/PHP-Scanner-Server/archive/master.zip"
unzip -q PHP-Scanner-Server.zip
mkdir -p /var/www/scanner/
mv -f /tmp/PHP-Scanner-Server/PHP-Scanner-Server-master/* /var/www/scanner/

Configure:

sed -i "s|Timeout 300|Timeout 900|g" /etc/apache2/apache2.conf
sed -i "s|max_execution_time = 30|max_execution_time = 900|g" /etc/php5/apache2/php.ini
sed -i "s|max_input_time = 60|max_input_time = 900|g" /etc/php5/apache2/php.ini

Create Directories and Set Permissions:

mkdir -p /var/www/scanner/scans
chmod 775 /var/www/scanner/scans
chown www-data /var/www/scanner/scans
mkdir -p /var/www/scanner/config
chmod 775 /var/www/scanner/config
chown www-data /var/www/scanner/config

Configure PHP-Scanner-Server:

sed -i "s|Timeout 300|Timeout 900|g" /var/www/scanner/config.ini
sed -i "s|FreeSpaceWarn = 2048|FreeSpaceWarn = 1024|g" /var/www/scanner/config.ini
sed -i "s|Fortune = true|Fortune = false|g" /var/www/scanner/config.ini
sed -i "s|RulerIncrement = 25.4|RulerIncrement = 10|g" /var/www/scanner/config.ini
sed -i "s|TimeZone = ''|TimeZone = 'UTC'|g" /var/www/scanner/config.ini
sed -i "s|Printer = 0|Printer = 1|g" /var/www/scanner/config.ini

Access the web interface for configuration:

http://192.168.1.111/scanner/index.php?page=Config

Using Your Scanner

Windows Users: Use TWAIN drivers to create a bridge between TWAIN and SANE on the network.

Download the Windows installer:

http://sanetwain.ozuzo.net/downloads/setup136.exe

Configure the connection:

Optional: Enable Samba

We will create a PDF share and a scanner share.

Install Samba:

apt-get install -y samba samba-common-bin

Configure `smb.conf`:

cat > /etc/samba/smb.conf <<EOF
# eXtremeSHOK.com
[global]
workgroup = WORKGROUP
netbios name = RASPBERRYPI
server string = %h
wins support = yes
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
security = share
share modes = yes
name resolve order = bcast host lmhost wins
 
[pdfs]
comment = Where PDF's get stored after printing
path = /storage/pdf
public = yes
writable = yes
browseable = yes
printable = no
guest ok = yes
create mask = 0777
directory mask = 0777
 
[scans]
comment = Where scans get stored after scanning
path = /var/www/output
public = yes
writable = yes
browseable = yes
printable = no
guest ok = yes
create mask = 0777
directory mask = 0777
EOF

Restart Samba:

service samba restart

Optional: rpisysinfoscript (Web-Based System Information Frontend)

Visit the web interface:

http://192.168.1.111/sysinfo.php

Install Requirements:

apt-get install -y libapache2-mod-php5 lsb-release lsscsi git -y

Install rpisysinfoscript:

cd /tmp
wget -O rpisysinfoscript.php "https://gist.githubusercontent.com/jvhaarst/4388108/raw/4ae8702effeafb89e583722f5a963ba6c1a4d06a/gistfile1.php"
mv /tmp/rpisysinfoscript.php /var/www/sysinfo.php

CUPS Command Line Utilities

Here is a list of CUPS command line utilities and their functions:

Instructs the printing system to accept print jobs to the specified destinations.

Cancels existing print jobs from the print queues.

Exports printers to the Samba software for use with Windows clients.

A CUPS program configuration utility.

Updates or queries the `cupsd.conf` file for a server.

The scheduler for the Common Unix Printing System.

A front-end to the CUPS filter subsystem, allowing you to convert a file to a specific format.

Tests the conformance of PostScript files.

Tests the conformance of PPD files.

Finds Internet Printing Protocol (IPP) printers.

Sends IPP requests to the specified URI and tests and/or displays the results.

Submits files for printing or alters a pending job.

Configures printer and class queues provided by CUPS.

Provides limited control over printer and class queues provided by CUPS.

Lists the available devices or drivers known to the CUPS server.

Moves the specified job to a new destination.

Displays or sets printer options and defaults.

Adds, changes, or deletes passwords in the CUPS digest password file `passwd.md5`.

Shows the current print queue status on the named printer.

Submits files for printing.

Cancels print jobs that have been queued for printing.

Displays status information about the current classes, jobs, and printers.

Compiles PPDC source files into one or more PPD files.

Reads a driver information file and produces an HTML summary page listing all the drivers in a file and their supported options.

Imports one or more PPD files into a PPD compiler source file.

Merges two or more PPD files into a single, multi-language PPD file.

Extracts UI strings from PPDC source files and updates either a GNU gettext or Mac OS X strings format message catalog source file for translation.

Instructs the printing system to reject print jobs to the specified destinations.

Contains the CUPS API functions.