-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_hp_printer.sh
executable file
·55 lines (52 loc) · 1.6 KB
/
fix_hp_printer.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
#!/bin/bash
#
# Author: Nate Levesque <[email protected]>
# Language: Shell
# Filename: fix_hp_printer.sh
#
# Description:
# fixes an ownership issue with HP printers in older versions of
# hplip so that the printer is usable. Requires root.
#
# Implement common code for dependency checks
depCheck(){
# Checks if a piece of software exists on a system and
# if it doesn't, stops execution and exits with an error.
#
# Arguments:
# $1: a command to test
#
if [ ! `command -v $1` ]; then
echo "You need $1 installed to use this script, exiting..."
exit 1
fi
}
# Check to make sure lsusb is available
depCheck lsusb
# Finds the bus and current HP device connected (if any)
bus=`lsusb | grep Hewlett-Packard | cut -c 5-7`
device=`lsusb | grep Hewlett-Packard | cut -c 16-18`
rootuser=root
# Finds the user who called the script
user=`whoami`
#
# Checks if the user calling the script was root and continues,
# otherwise quits
if [ $user = $rootuser ]; then
# Checks to see if an HP device is connected, quits if not
if [ "`lsusb | grep Hewlett-Packard`" = "" ]; then
echo "No HP device connected."
exit 0
else
# Changes the ownership of the device to root:lp, which is
# the correct ownership for the printer to work
chown root:lp /dev/bus/usb/$bus/$device
echo "Found HP device on /dev/bus/usb/$bus/$device"
echo "Good to go!"
exit
fi
else
# Informs the user that root is required and quits
echo "Requires root privileges!"
exit 1
fi