Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- prnt=`lpstat -p`
- echo Checking if you are starting this Script as sudo
- if [ `id -u` -eq 0 ];
- then
- echo Ok, you have sudo-privs
- else
- echo Sorry, please start this script again with sudo ./airprint.sh. Exit.
- exit 0
- fi
- declare -a ips
- ips[0]=0
- readdev=(eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 wlan1 wlan2 wlan3 wlan4 wlan5 wlan6 wlan7 wlan8 wlan9)
- for dev in $readdev
- do
- ip=`ifconfig $dev | head -n 2 | tail -n 1 | cut -d: -f2 | cut -d" " -f 1`
- #echo Found IP $ip
- if [ $ip != "" ]; then
- ind=${ips[0]}
- ind=$[$ind+1]
- ips[$ind]=$ip
- ips[0]=$ind
- fi
- done
- amount=${ips[0]}
- if [ $amount -eq 0 ]; then
- echo No working network devices found. Exit.
- exit 0
- fi
- if [ $amount -eq 1 ]; then
- CUPSIP=${ips[1]}
- echo Using the only working network device $CUPSIP
- fi
- if [ $amount -gt 1 ]; then
- echo Select Network Interface to publish AirPrint
- i=1
- for ip in $ips
- do
- echo $i...${ips[i]}
- done
- read sel
- if [ "${ips[sel]}" = "" ]; then
- echo Invalid Input. Exit.
- exit 0
- fi
- if [ $sel -eq 0 ]; then
- echo Invalid Input. Exit.
- exit 0
- fi
- CUPSIP=${ips[sel]}
- fi
- echo Activating AirPrint on $CUPSIP
- echo ----------------------------------------
- echo Making CUPS share printers on network
- cupsctl --share-printers
- echo ----------------------------------------
- declare -a printers
- printers[0]=0
- index=0
- foundprinter=0
- for word in $prnt
- do
- if [ $foundprinter -eq 1 ]; then
- index=${printers[0]}
- index=$[$index+1]
- #echo Found Printer $word for Index $index
- printers[$index]=$word
- printers[0]=$index
- foundprinter=0
- fi
- if [ "$word" = "printer" ]; then
- foundprinter=1
- fi
- done
- amount=${printers[0]}
- if [ $amount -eq 0 ]; then
- echo No working printer found. Exit.
- exit 0
- fi
- if [ $amount -eq 1 ]; then
- CUPSPRINTER=${printers[1]}
- echo Using the only working printer $CUPSPRINTER
- fi
- if [ $amount -gt 1 ]; then
- echo Select Printer
- i=1
- for prnt in $printers
- do
- echo $i...${printers[i]}
- done
- read sel
- if [ "${printers[sel]}" = "" ]; then
- echo Invalid Input. Exit.
- exit 0
- fi
- if [ $sel -eq 0 ]; then
- echo Invalid Input. Exit.
- exit 0
- fi
- CUPSPRINTER=${ips[sel]}
- fi
- echo Activating AirPrint for $CUPSPRINTER
- echo ----------------------------------------
- echo Creating printer.service
- targ=/etc/avahi/services/printer.service
- unlink $targ
- echo \<?xml version=“1.0″ standalone=’no’?\>\<!–*-nxml-*–\> >> $targ
- echo \<!DOCTYPE service-group SYSTEM „avahi-service.dtd“\> >> $targ
- echo \<service-group\> >> $targ
- echo \<name\>$CUPSPRINTER\</name\> >> $targ
- echo \<service\> >> $targ
- echo \<type\>_ipp._tcp\</type\> >> $targ
- echo \<subtype\>_universal._sub._ipp._tcp\</subtype\> >> $targ
- echo \<port\>631\</port\> >> $targ
- echo \<txt-record\>txtver=1\</txt-record\> >> $targ
- echo \<txt-record\>qtotal=1\</txt-record\> >> $targ
- echo \<txt-record\>rp=printers/$CUPSPRINTER\</txt-record\> >> $targ
- echo \<txt-record\>ty=$CUPSPRINTER\</txt-record\> >> $targ
- echo \<txt-record\>adminurl=http://$CUPSIP:631/printers/$CUPSPRINTER\</txt-record\> >> $targ
- echo \<txt-record\>note=$CUPSPRINTER\</txt-record\> >> $targ
- echo \<txt-record\>priority=0\</txt-record\> >> $targ
- echo \<txt-record\>product=virtual Printer\</txt-record\> >> $targ
- echo \<txt-record\>printer-state=3\</txt-record\> >> $targ
- echo \<txt-record\>printer-type=0×801046\</txt-record\> >> $targ
- echo \<txt-record\>Transparent=T\</txt-record\> >> $targ
- echo \<txt-record\>Binary=T\</txt-record\> >> $targ
- echo \<txt-record\>Fax=F\</txt-record\> >> $targ
- echo \<txt-record\>Color=T\</txt-record\> >> $targ
- echo \<txt-record\>Duplex=F\</txt-record\> >> $targ
- echo \<txt-record\>Staple=F\</txt-record\> >> $targ
- echo \<txt-record\>Copies=T\</txt-record\> >> $targ
- echo \<txt-record\>Collate=F\</txt-record\> >> $targ
- echo \<txt-record\>Punch=F\</txt-record\> >> $targ
- echo \<txt-record\>Bind=F\</txt-record\> >> $targ
- echo \<txt-record\>Sort=F\</txt-record\> >> $targ
- echo \<txt-record\>Scan=F\</txt-record\> >> $targ
- echo \<txt-record\>pdl=application/octet-stream,application/pdf,application/postscript,image/jpeg,image/png,image/urf\</txt-record\> >> $targ
- echo \<txt-record\>URF=W8,SRGB24,CP1,RS600\</txt-record\> >> $targ
- echo \</service\> >> $targ
- echo \</service-group\> >> $targ
- echo ----------------------------------------
- echo Editing CUPS-Daemon Config
- targ=/etc/cups/cupsd.conf
- echo ServerAlias * >> $targ
- echo Port 631 >> $targ
- echo Listen /var/run/cups/cups.sock >> $targ
- echo ----------------------------------------
- echo Restarting CUPS
- service cups restart
- echo Finished. Exit.
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment