-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-linux.sh
43 lines (36 loc) · 1.69 KB
/
install-linux.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# ------------------------------------------------------------------------------
# @brief Install a RICOH C306Z printer with a UserCode
# @author Florian TOUEIX (https://github.com/ftwex)
# @version 1.0.0
#
# The script discover the printer ip, download and adapt the driver
# with the correct UserCode and install the printer.
#
# ------------------------------------------------------------------------------
# Discover printers and get Ricoh printer uri
echo -n 'Discovering the printer...'
printerInfos=$(lpinfo -l -v | grep -B 3 -A 2 'make-and-model = RICOH MP C306Z')
printerURI=$(echo "$printerInfos" | head -n1 | sed 's/Device: uri = //g')
printerMakeAndModel=$(echo "$printerInfos" | sed -n 3p | sed 's/\s*info = //g')
printerMakeAndModelSlug=$(echo "$printerMakeAndModel" | tr ' ' '-')
echo '\033[0;32m'"$printerMakeAndModel"' found !\033[0m'
# Ask for UserCode
echo -n 'Enter your UserCode :'
read userCode
if [ -z $(echo "$userCode" | grep -oE '^[0-9]{1,8}$') ] ;then
echo '\033[0;31mUserCode empty or invalid\033[0m'
else
# Get printer driver, update it with given UserCode and write it in cups ppd's path
echo -n 'Downloading and preparing the driver...'
curl -s 'https://www.openprinting.org/ppd-o-matic.php?driver=Postscript-Ricoh&printer=Ricoh-MP_C306Z&show=1' | sed "s/1001/$userCode/g" | sed "s/DefaultUserCode: None/DefaultUserCode: $userCode/g" > /usr/share/ppd/CustomRICOH_MP_C306Z.ppd
echo '\033[0;32mOK\033[0m'
echo -n 'Installing the printer...'
# Add printer to system
lpadmin -p "$printerMakeAndModelSlug" \
-v $printerURI \
-m "$printerMakeAndModelSlug" \
-P '/usr/share/ppd/CustomRICOH_MP_C306Z.ppd' \
-E
echo '\033[0;32mOK\033[0m\n\nReady to print !'
fi