aboutsummarylogtreecommitdiffstats
path: root/harvard-linux-printer.sh
blob: 62aab77a1d8b49a11a4c73411745aa5fde3df788 (plain)
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
#!/bin/bash

sudo echo "Installing dependencies..."

sudo apt-get update > /dev/null
sudo apt-get install cups-client cups-server-common smbclient > /dev/null

echo "Done installing dependencies."

printf "\n"

echo "Go to the following URL and log in to determine your PaperCut username:"
echo "https://papercut.fas.harvard.edu/app"

printf "\n"

read -p "Enter your PaperCut username: " papercut_username
read -sp "Enter your PaperCut password: " papercut_password

while [[ $papercut_username != ${papercut_username/ /} || $papercut_password != ${papercut_password/ /} ]]; do
	echo "Username and password cannot contain spaces. Please try again."
	printf "\n"
	read -p "Enter your PaperCut username: " papercut_username
	read -sp "Enter your PaperCut password: " papercut_password
done


sudo sed -i '/syslog/d' /etc/samba/smb.conf
# sudo echo "logging = syslog@0 file" >> /etc/samba/smb.conf

{
	IFS=$'\n'
	print1_array=$(smbclient -L //HUIT-PPC-Print1.fas.harvard.edu -U FAS_DOMAIN/$papercut_username"%"$papercut_password | awk '!/\$/ && !/faculty/ && !/NetBIOS/ && !/session/ && !/Connection/ && !/Sharename/ && !/\-\-/ {print $1}')
} &> ./harvard-linux-printer.log

printf "\n"

worked=false

# echo $print1_array

for x in $print1_array; do
	if [ $x ];
		then 
		worked=true
	fi
done

if [ "$worked" = false ]; 
	then
		echo "Authentication error. Please make sure you entered your credentials correctly. Note that at this time passwords containing % or : cannot successfully authenticate." 
		echo "If you suspect there is a bug, please submit a bug report at https://github.com/djsavvy/harvard-linux-printer/issues and upload the file harvard-linux-printer.log." 
	exit 1
fi


echo "Connected to HUIT-PPC-Print1."

{
	for x in $print1_array; do 
		if [ $x ];
			then 
				sudo lpadmin -p $x -E -v smb://$papercut_username:$papercut_password@FAS_DOMAIN/HUIT-PPC-Print1.fas.harvard.edu/$x
		fi
	done
} &> /dev/null

echo "Added printers from HUIT-PPC-Print1."

# printf "\n"

{
	IFS=$'\n'
	print2_array=$(smbclient -L //HUIT-PPC-Print2.fas.harvard.edu -U FAS_DOMAIN/$papercut_username"%"$papercut_password | awk '!/\$/ && !/faculty/ && !/NetBIOS/ && !/session/ && !/Connection/ && !/Sharename/ && !/\-\-/ {print $1}')
} &> /dev/null

echo "Connected to HUIT-PPC-Print2."

{
	for x in $print2_array; do 
		if [ $x ];
			then 
				sudo lpadmin -p $x -E -v smb://$papercut_username:$papercut_password@FAS_DOMAIN/HUIT-PPC-Print2.fas.harvard.edu/$x
		fi
	done
} &> /dev/null

echo "Added printers from HUIT-PPC-Print2."

printf "\n"

echo "Done. Enjoy!"
echo "Please report any bugs to https://github.com/djsavvy/harvard-linux-printer/issues"