forked from dentys03/manual_duplex_linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·109 lines (93 loc) · 2.88 KB
/
install.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
all_printers=$(lpstat -s | tail +2 | awk '{print $3}' | sed 's/.$//')
echo
echo "These are your installed printers:"
echo
declare printers_array
i=0
for p in $all_printers
do
i=$(( $i + 1 ))
echo $i. $p
printers_array[$i]=$p
done
echo
echo "Type the number of the printer you want to add duplexing capabilities, then type ENTER:"
echo
read chosen_printer
first_printer=${printers_array[$chosen_printer]}
function setup_duplexer {
first_printer=$1
if [ -z "$first_printer" ]
then
echo "No printer submitted. You trickster!"
exit 1
else
echo "found printer: "$first_printer
echo going ahead.
fi
#create dir for files to be printed
mkdir -p /var/spool/cups/duplex/
chmod 777 /var/spool/cups/duplex/
#create dir for our files
mkdir -p /usr/share/manual_duplex_linux/
cp printer.png /usr/share/manual_duplex_linux/
cp document-print.svg /usr/share/manual_duplex_linux/
#permit lp user to run zenity as the user running the installer
zenity_user=$(logname)
touch /etc/sudoers.d/lp
chmod 640 /etc/sudoers.d/lp
echo '#user host = (runas user) command' > /etc/sudoers.d/lp
echo "lp ALL=($zenity_user) NOPASSWD:/usr/bin/zenity" >> /etc/sudoers.d/lp
chmod 440 /etc/sudoers.d/lp
cp -rf usr/lib/cups/backend/duplex-print /usr/lib/cups/backend/duplex-print
chown root:root /usr/lib/cups/backend/duplex-print
chmod 700 /usr/lib/cups/backend/duplex-print
cp -rf usr/lib/cups/backend/duplex-print /usr/lib/cups/backend-available/duplex-print
chown root:root /usr/lib/cups/backend-available/duplex-print
chmod 700 /usr/lib/cups/backend-available/duplex-print
echo "Deleting printer if already exists"
lpadmin -x Manual_Duplexer_$first_printer
cp -praf /etc/cups/ppd/$first_printer.ppd /etc/cups/ppd/Manual_Duplexer_$first_printer.ppd
# sed -i 's/"0 hpcups"/"duplex_print_filter"/g' /etc/cups/ppd/Manual_Duplexer_$first_printer.ppd
sed -i '/^*cupsFilter/d' /etc/cups/ppd/Manual_Duplexer_$first_printer.ppd
echo '*cupsFilter2: "application/pdf application/pdf 100 -"' >> /etc/cups/ppd/Manual_Duplexer_$first_printer.ppd
sleep 1
service cups restart
#add duplexing printer
lpadmin -p Manual_Duplexer_$first_printer -E -v duplex-print:$first_printer -P /etc/cups/ppd/Manual_Duplexer_$first_printer.ppd
lpadmin -d Manual_Duplexer_$first_printer
echo
echo "Duplexer installed."
echo
exit 0
}
clear
if [ $(whoami) == root ]
then
echo
echo "This script assumes /var/spool/cups/ is the folder used by the printing system."
echo
echo "The script will add"
echo " $first_printer "
echo
echo " printer with the duplex setup. Is this what you want?"
echo
echo "(Y/N) followed by [ENTER]:"
read approve
if [ $approve == "Y" ]
then
echo
echo
echo
setup_duplexer $first_printer
else
echo
echo "Nothing was changed."
echo
exit 0
fi
else
echo "This must be run as root."
exit 1
fi