|
| 1 | +#!/usr/bin/env sh |
| 2 | + |
| 3 | +# A script intended to be able to install arbitrary Konica Minolta printers from the KMbeuUX files that can be downloaded from their website, under a given printer model |
| 4 | + |
| 5 | +# lpadmin doesn't like spaces |
| 6 | +NAME="$(echo "$1" | tr ' ' '_')" |
| 7 | +HOST="$2" |
| 8 | +DESCRIPTION="$3" |
| 9 | +# A .tar.gz driver file as downloaded from Konica Minolta themselves. It should have a name like: KMbeuUXv1_26_multi_language.tar.gz (4276KB) |
| 10 | +DRIVER_PACKAGE_PATH="$4" |
| 11 | +# A PPD driver/file contained within the driver package |
| 12 | +SELECTED_DRIVER="$5" |
| 13 | +PROTOCOL="${6:-socket}" |
| 14 | +SET_STANDARD="$7" |
| 15 | + |
| 16 | +set -ex |
| 17 | + |
| 18 | +restore_original_filename() { |
| 19 | + basename "$1" | sed "s/[^_]*_//" |
| 20 | +} |
| 21 | + |
| 22 | +# "The default folder on most Linux distributions is /usr/lib/cups/filter" |
| 23 | +# "Otherwise the path can be found in CUPS configuration file /etc/cups/cups-files.conf or /etc/cups/cupsd.co" |
| 24 | +CUPS_FILTER_DIR="/usr/lib/cups/filter" |
| 25 | +# There are multiple places where CUPS reads PPD files |
| 26 | +CUPS_DRIVER_DIR="/etc/cups/ppd" |
| 27 | +# Filter file names as taken from Konica Minolta's BEU Linux CUPS Driver Guide |
| 28 | +FILTER_FILE_1="KMbeuEmpPS.pl" |
| 29 | +FILTER_FILE_2="KMbeuEnc.pm" |
| 30 | + |
| 31 | +DRIVER_DESTINATION_PATH="$CUPS_DRIVER_DIR/$SELECTED_DRIVER" |
| 32 | + |
| 33 | +cd "$(dirname "$DRIVER_PACKAGE_PATH")" |
| 34 | +DRIVER_PACKAGE_FILE=$(basename "$DRIVER_PACKAGE_PATH") |
| 35 | +tar xzvf "$DRIVER_PACKAGE_FILE" |
| 36 | +DRIVER_SOURCE_DIR="$(find . -mindepth 1 -type d)" |
| 37 | + |
| 38 | +# Copy the the driver/PPD to a dir that CUPS reads |
| 39 | +# NOTE: An alternate approach, perhaps worth considering to simplify arguments, would be to simply copy all drivers in there. |
| 40 | +# On the other hand we need to know the driver when specifying the PPD for lpadmin anyway. |
| 41 | +cp "$DRIVER_SOURCE_DIR/$SELECTED_DRIVER" $CUPS_DRIVER_DIR/ |
| 42 | + |
| 43 | +# Set the correct permissions on the PPD |
| 44 | +chmod 644 "$DRIVER_DESTINATION_PATH" |
| 45 | + |
| 46 | +# Copy the filter files to a dir that CUPS reads |
| 47 | +cp "$DRIVER_SOURCE_DIR/$FILTER_FILE_1" "$DRIVER_SOURCE_DIR/$FILTER_FILE_2" $CUPS_FILTER_DIR/ |
| 48 | + |
| 49 | +# Set the correct permissions on the filter files |
| 50 | +chmod 755 $CUPS_FILTER_DIR/$FILTER_FILE_1 $CUPS_FILTER_DIR/$FILTER_FILE_2 |
| 51 | + |
| 52 | +# Cleanup and remove the driver package |
| 53 | +rm --recursive "$DRIVER_PACKAGE_PATH" "$DRIVER_SOURCE_DIR" |
| 54 | + |
| 55 | +# Restart CUPS afterwards so it should pickup the new PPDs and filters |
| 56 | +systemctl restart cups |
| 57 | + |
| 58 | +# As copied from network_printer_add_ppd.sh |
| 59 | +lpadmin -p "$NAME" -v "$PROTOCOL://$HOST" -D "$DESCRIPTION" -E -P "$DRIVER_DESTINATION_PATH" -L "$DESCRIPTION" |
| 60 | + |
| 61 | +if [ "$SET_STANDARD" = "True" ]; then |
| 62 | + # Set the printer as standard printer |
| 63 | + lpadmin -d "$NAME" && lpstat -d |
| 64 | +fi |
0 commit comments