Overskrev en fin patch ved et uhell, la inn igjen
[einar-bin] / addpullprint.sh
1 #!/bin/sh
2 # This script installs the SafeCom pullprint print queue
3 # for Høgskolen i Gjøvik on Linux and Mac systems.
4 # Written by einarh@hig.no
5 # I consider this script public domain
6
7 # Test for system variant
8 OS=$(uname)
9 if [ "${OS}" != "Darwin" ] && [ "${OS}" != "Linux" ]; then
10 echo "I don't think I can run on "${OS}", but if you insist, please edit me and remove the test." 1>&2
11 exit 1
12 fi
13
14 # Test for root
15 if [ $(id -u) -ne 0 ]; then
16 echo "This script must be run as root. Please use sudo or log in as root" 1>&2
17 exit 1
18 fi
19
20 # Test for CUPS
21 command -v lpadmin >/dev/null 2>&1
22 if [ $? -ne 0 ]; then
23 echo "You must have CUPS installed to add printers. Please install CUPS." 1>&2
24 exit 1
25 fi
26
27 # Test for smbclient if on Linux
28 if [ "${OS}" = "Linux" ]; then
29 command -v smbclient >/dev/null 2>&1
30 if [ $? -ne 0 ]; then
31 echo "You must have smbclient installed to add printers. Please install smbclient." 1>&2
32 exit 1
33 fi
34 fi
35
36 echo "This script will add a new printer called Pullprint, connecting to
37 the print server safecom2.hig.no using your normal user name and
38 password from HiG. Do not use on multi user systems!"
39
40 printf "User name: "
41 read USERNAME
42 printf "Password: "
43 SETTINGS=$(stty -g)
44 stty -echo
45 read PASSWORD
46 stty "${SETTINGS}"
47
48 echo ""
49
50 # Test for valid username and password if on Linux
51 if [ "${OS}" = "Linux" ]; then
52 smbclient -U HIG/${USERNAME}%${PASSWORD} -L //hig.no > /dev/null 2>&1
53 if [ $? -ne 0 ]; then
54 echo "User name or password incorrect, or no contact with HiG servers." 1>&2
55 exit 1
56 fi
57 fi
58
59 # Add the printer
60
61 # The Linux way
62 if [ "${OS}" = "Linux" ]; then
63 lpadmin -p Pullprint \
64 -D "SafeCom Pullprint ved HiG" \
65 -v "smb://hig%5C${USERNAME}:${PASSWORD}@safecom2.hig.no/PullPrint" \
66 -m "drv:///sample.drv/generic.ppd" \
67 -u allow:all -E
68 fi
69
70 # The OSX way
71 if [ "${OS}" = "Darwin" ]; then
72 lpadmin -p Pullprint \
73 -D "SafeCom Pullprint ved HiG" \
74 -v "smb://HIG;${USERNAME}:${PASSWORD}@safecom2.hig.no/PullPrint" \
75 -m "drv:///sample.drv/generic.ppd" \
76 -u allow:all -E
77 fi
78
79 if [ $? -ne 0 ]; then
80 echo "Could not connect to printer share. See above error for details." 1>&2
81 exit 1
82 fi
83
84 # Set correct paper size and enable the duplexer option
85 lpadmin -p Pullprint -o PageSize=A4 -o Option1=True
86
87 if [ $? -ne 0 ]; then
88 echo "Could not set default options. See above error for details." 1>&2
89 exit 1
90 fi
91
92 # Set as default
93 lpadmin -d Pullprint
94
95 if [ $? -ne 0 ]; then
96 echo "Could not set Pullprint as default printer. See above error for details." 1>&2
97 exit 1
98 fi
99
100 echo "Printer successfully installed."