forked from UoE-macOS/jss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoreconfig-check-xerox-drivers.sh
194 lines (146 loc) · 4.5 KB
/
coreconfig-check-xerox-drivers.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
#
###################################################################
#
# Script clears out the bad ppd code from the Xerox drivers.
#
# Date: Tue 8 May 2018 14:12:39 BST
# Version: 0.1.3
# Creator: dsavage
#
##################################################################
#
LogFile="/Library/Logs/Xerox-Watchman.log"
date > $LogFile
# Check to make sure script isn't running already
ps | grep -w "[X]eroxWatchman.sh" > /var/tmp/XeroxWatchman.sh.pid
echo "Creating the lock file" >> $LogFile
pids=$(cat /var/tmp/XeroxWatchman.sh.pid | cut -d ' ' -f 1)
for pid in $pids
do
if [ $pid -ne $$ ]; then
echo "[`date`] : XeroxWatchman.sh : Process is already running"
rm -f /var/tmp/XeroxWatchman.sh.pid
exit 1;
fi
done
Clear_JobPatch ()
{
Path="$1"
echo "Entering loop to fix the PPD files" >> $LogFile
cat /tmp/temp.txt | ( while read DriverNm;
do
echo $DriverNm
# Remove the JobPatchFile 1 line, this causes the print job to appear as US Letter
grep -v "JobPatchFile 1" "${Path}${DriverNm}" > "${Path}${DriverNm}".tmp
echo done the first fix
# Remove the reporting commands, this delays printing as we go through a server not direct IP
grep -v "cupsCommands" "${Path}${DriverNm}".tmp > "${Path}${DriverNm}"
#sed -e s/ReportLevels//g -e s/ReportStatus//g -e s/com.xerox.LDAPQuery//g "${Path}${DriverNm}".tmp > "${Path}${DriverNm}"
echo done the second fix ${DriverNm}
# Clean up the tmp file
rm -f "${Path}${DriverNm}".tmp
done)
}
Xero_Watch ()
{
# The drivers could be updating at the moment so go to sleep to allow any update to complete.
sleep 20
# Fix any printers first, as we use printer status as a test to see if modification is required
Path="/private/etc/cups/ppd/"
# create the file with list of printers
ls "$Path" | grep -v '^[.*]' > /tmp/temp.txt
Clear_JobPatch "${Path}"
# Clear the file
rm -f /tmp/temp.txt
# Fix the drivers Xerox ship
Path="/Library/Printers/PPDs/Contents/Resources/"
# Create the file with list of Xerox drivers
ls $Path | grep "Xerox" | grep ".gz" > /tmp/temp.txt
cat /tmp/temp.txt | ( while read ppd;
do
# Unzip each driver
gunzip -vf "${Path}${ppd}"
done)
# Clean up the ppd file
ls $Path | grep "Xerox" | grep -v ".gz" > /tmp/temp.txt
Clear_JobPatch "${Path}"
cat /tmp/temp.txt | ( while read ppd;
do
# Gzip each driver
gzip -vf "${Path}${ppd}"
done)
# Clear the file
rm -f /tmp/temp.txt
}
Reset_Cups ()
{
# Do some maintenance and give the cups component a kick if a managed machine
if [ -e /usr/local/bin/jamf ];
then
echo "Mac Supported Desktop, resetting cups." >> $LogFile
launchctl stop org.cups.cupsd
rm /etc/cups/cupsd.conf
cp /etc/cups/cupsd.conf.default /etc/cups/cupsd.conf
launchctl start org.cups.cupsd
cupsctl WebInterface=yes
fi
}
GZ_Driver_Cleanup ()
{
# Check if the drivers are actually ok...
Path="/Library/Printers/PPDs/Contents/Resources/"
ls $Path | grep "Xerox" | grep -v ".gz" > /tmp/DriverTest.txt
cat /tmp/DriverTest.txt | ( while read PPD;
do
echo $PPD
TestGZ=`gzip -t "${Path}${PPD}.gz" 2>&1`
if ! [ -z "${TestGZ}" ]
then
rm -f "${Path}${PPD}.gz"
gzip -vf "${Path}${PPD}"
else
rm -f "${Path}${PPD}"
fi
done)
rm -f /tmp/DriverTest.txt
}
Check_lpoperator ()
{
# All users should be in the Print Operator group, otherwise they can't interact with the printing system without admin rights.
AllUsers=(`ls "/Users/" | grep -v '^[.*]' | grep -v 'Shared'`)
for User_Name in ${AllUsers[@]}
do
User_LP=`id "${User_Name}" | grep "_lpoperator"`
if [ -z "${User_LP}" ]; then
dseditgroup -o edit -a "${User_Name}" _lpoperator
fi
done
}
# Find out if the driver files need to be fixed
AllPrinters=$(ls /private/etc/cups/ppd)
for ppd in $AllPrinters
do
# Use grep -l for simplicity, if what we are looking for is found it returns the file name
XeroxQ=`grep -l "Xerox" /private/etc/cups/ppd/$ppd | awk -F "/" '{print $6}'`
if [ "${XeroxQ}" == "${ppd}" ]
then
# This queue uses the Xerox driver.
Check1=`grep -l "JobPatchFile 1" /private/etc/cups/ppd/$ppd | awk -F "/" '{print $6}'`
Check2=`grep -l "cupsCommands" /private/etc/cups/ppd/$ppd | awk -F "/" '{print $6}'`
if [ "${Check1}" == "${ppd}" ] || [ "${Check2}" == "${ppd}" ]
then
# This queue has a JobPatchFile 1 line.
Xero_Watch
Reset_Cups
else
echo "No action taken, drivers are correct - no JobPatchFile 1 line or Reporting." >> $LogFile
fi
fi
done
# Sort out any driver issues with uncompressed files and corrupt .gzs.
GZ_Driver_Cleanup
Check_lpoperator
echo "Deleting the lock file" >> $LogFile
rm -f /var/tmp/XeroxWatchman.sh.pid
exit 0;