Skip to content

Instantly share code, notes, and snippets.

@AlessandroVaccarino
Created March 19, 2020 09:45
Show Gist options
  • Save AlessandroVaccarino/9a344aad2f3bdbbaeca76f5313bcc35f to your computer and use it in GitHub Desktop.
Save AlessandroVaccarino/9a344aad2f3bdbbaeca76f5313bcc35f to your computer and use it in GitHub Desktop.
A script that installs and configures AirPrint on a Raspberry PI. Tested on Raspbian
# System setup
sudo apt-get update
sudo apt-get -y upgrade
# Software setup
sudo apt-get -y install cups
sudo apt-get -y install python-cups
sudo apt-get -y install avahi-daemon
sudo apt-get -y install system-config-printer
# Software configuration
sudo usermod -aG lpadmin $USER
sudo /etc/init.d/cups start
sudo /etc/init.d/avahi-daemon start
sudo sed -i "/MaxLogSize 0/a SystemGroup lpadmin" /etc/cups/cupsd.conf
sudo sed -i 's/Listen localhost:631/Port 631/g' /etc/cups/cupsd.conf
sudo sed -i "/WebInterface Yes/a ServerAlias *" /etc/cups/cupsd.conf
sudo sed -i "/Order allow,deny/a Allow @Local" /etc/cups/cupsd.conf
#sudo sed 's/# Allow shared printing…\\nOrder allow,deny/# Allow shared printing…\\nOrder allow,deny\\nAllow @LOCAL/g' /etc/cups/cupsd.conf
#sudo sed 's/<Location \/admin>\\nOrder allow,deny/<Location \/admin>\\nOrder allow,deny\\nAllow @Local/g' /etc/cups/cupsd.conf
#sudo sed 's/Require user @SYSTEM\\nOrder allow,deny/Require user @SYSTEM\\nOrder allow,deny\\nAllow @Local/g' /etc/cups/cupsd.conf
# System restart
sudo /etc/init.d/cups restart
# AirPrint configuration
sudo mkdir /opt/airprint
sudo wget -O /opt/airprint/airprint-generate.py –no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
sudo bash -c 'cat >> /usr/share/cups/mime/airprint.types <<EOL
#
# “$Id: $”
#
# AirPrint type
image/urf urf string(0,UNIRAST<00>)
#
# End of “$Id: $”.
#
EOL'
sudo bash -c 'cat >> /usr/share/cups/mime/airprint.convs <<EOL
#
# “$Id: $”
#
# AirPrint
# Updated list with minimal set 25 Sept
image/urf application/pdf 100 pdftoraster
#
# End of “$Id: $”.
#
EOL'
# System restart
sudo /etc/init.d/cups restart
sudo chmod 755 /opt/airprint/airprint-generate.py
sudo /opt/airprint/airprint-generate.py -d /etc/avahi/services
# Conclusion
echo "###################################################################################"
echo "INSTALLATION COMPLETED"
echo "Configure desired printer on Web Interface (port 631), then restart the system"
echo ""
echo "Thanks to:"
echo "https://claudiosi.wordpress.com/2013/03/02/airprint-con-raspberry-pi/"
echo "###################################################################################"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment