-
Notifications
You must be signed in to change notification settings - Fork 3
printer_install_linux.sh
Installs network printers on Linux using CUPS/lpadmin with automatic CUPS installation and PPD driver support.
This script automates network printer deployment on Linux systems using CUPS (Common Unix Printing System). It can install multiple printers in a single run, automatically installs CUPS if missing, and supports PPD driver files for full printer functionality.
Provides standardized printer deployment for managed Linux workstations, eliminating manual CUPS configuration and ensuring consistent printer settings across multiple devices.
- Operating System: Debian/Ubuntu or compatible Linux
- Privileges: Root/sudo privileges required
- Network: Access to printer hosts
- Packages: CUPS, cups-client, printer drivers (auto-installed if enabled)
- Driver File: PPD file for printer model
- Internet: Required for package installation
Edit these variables in the script before running:
PRINTERS Array:
PRINTERS=(
"printer1.example.com|Main Office|Office Printer"
"printer2.example.com|Sales Dept|Sales Printer"
)Format: "hostname|location|display_name"
PROTOCOL: Connection protocol
- Options:
lpd,ipp,socket - Default:
lpd
PPD_PATH: Path to PPD driver file
- Example:
/usr/share/cups/model/YourPrinter.ppd - Common locations:
/usr/share/cups/model//usr/share/ppd//etc/cups/ppd/
AUTO_INSTALL_CUPS: Automatically install CUPS if missing
- Options:
trueorfalse - Default:
true
- Root Check: Verifies script is run with root privileges
- OS Detection: Confirms Linux operating system
- Configuration Display: Shows protocol, PPD path, and printer count
-
CUPS Installation (if enabled):
- Checks if CUPS is installed
- Installs CUPS using apt-get, yum, or dnf
- Enables and starts CUPS service
-
PPD Verification:
- Checks if specified PPD file exists
- Falls back to generic PPD if configured PPD not found
- Exits if no PPD available
-
Printer Installation Loop:
- For each printer in PRINTERS array:
- Removes existing printer with same name
- Builds URI based on protocol
- Creates printer using lpadmin
- Sets location and display name
- Enables printer and accepts jobs
- Verifies installation with lpstat
- For each printer in PRINTERS array:
-
Results Display:
- Lists all installed printers
- Shows success/failure count
- Displays final status
The script exits immediately on critical errors due to set -euo pipefail.
- Requires root privileges for CUPS configuration
- Printer credentials not supported (use IPP authentication separately)
- No data encryption in print protocol (use IPP over TLS if required)
- PPD files executed by CUPS - ensure PPD from trusted source
- Network printers should be on trusted network segment
- 0: All printers installed successfully
-
1: Installation failed:
- Script not run as root
- Not running on Linux
- Unable to install CUPS
- No PPD files available
- All printer installations failed
Note: Partial success (some printers installed) returns exit code 1.
[ NETWORK PRINTER INSTALL - Linux ]
--------------------------------------------------------------
Protocol : lpd
PPD Path : /usr/share/cups/model/Generic-PDF_Printer-PDF.ppd
Printers : 2
[ CHECKING CUPS ]
--------------------------------------------------------------
CUPS is already installed
CUPS service started
[ VERIFYING PPD ]
--------------------------------------------------------------
PPD file verified: /usr/share/cups/model/Generic-PDF_Printer-PDF.ppd
[ INSTALLING PRINTERS ]
--------------------------------------------------------------
Installing: Office Printer
Hostname : printer1.example.com
Location : Main Office
Name : Office_Printer
Status : SUCCESS
Installing: Sales Printer
Hostname : printer2.example.com
Location : Sales Dept
Name : Sales_Printer
Status : SUCCESS
[ INSTALLED PRINTERS ]
--------------------------------------------------------------
printer Office_Printer is idle. enabled since Mon 01 Jun 2025 02:30:00 PM EDT
printer Sales_Printer is idle. enabled since Mon 01 Jun 2025 02:30:05 PM EDT
[ FINAL STATUS ]
--------------------------------------------------------------
Installed : 2 printer(s)
Failed : 0 printer(s)
Result : SUCCESS
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
-
v1.0.0: Initial release
- Multi-printer support
- Automatic CUPS installation
- PPD driver support
- Protocol selection (lpd, ipp, socket)
- Generic PPD fallback
- Installation verification
- View Script Source
- Scripts - Back to script index