Google CloudPrint on Linux

Google CloudPrint allows users to print to the cloud from devices such as your mobile phone. That is, you can print documents and pictures from your phone to printers you have access to (e.g., at home) but is not directly connected to your phone. As of 5/12/2011, only printing from mobile Gmail and Google Docs (from the browser) are supported besides the Chrome OS. Also, only printers that are accessible to computers running Windows or Mac with the Chrome browser installed are supported. What about Linux? This thread points to the cloudprint python program. I installed it and have it started at startup via the following:

 <pre class="src src-sh">git clone https://github.com/armooo/cloudprint.git

sudo apt-get install python-pip sudo pip install daemon sudo python setup.py install ## or skip the whole git process and do: sudo pip install cloudprint ## place content daemon script in /etc/init.d/cloudprint sudo chmod +x /etc/init.d/cloudprint

where the daemon script was adapted from this:

<pre class="src src-sh"><span style="color: #ff4500;">#</span><span style="color: #ff4500;">!/bin/</span><span style="color: #00ffff;">bash</span>

# /etc/rc.d/cloudprint # Description: Starts the Google Cloud Print script on startup # —————- # ### BEGIN INIT INFO # Provides: Cloud-Print # Required-Start: $cups $network $local_fs $syslog # Required-Stop: $local_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Description: Start Google Cloud Print ### END INIT INFO

case $1 in start) echo -n “Starting Google Cloud Print: “ ##/root/cloudprint/cloudprint.py sudo -u vinh cloudprint -d ;; stop) echo -n “Stopping Google Cloud Print: “ ##killall cloudprint.py ;; restart) # echo -n “Restarting Google Cloud Print: “ ##killall cloudprint.py ##/root/cloudprint/cloudprint.py killall cloudprint sudo -u vinh cloudprint -d ;; # echo “Usage: cloudprint {start|stop|restart}” esac

Then, add it to the startup list: sudo update-rc.d cloudprint defaults.

Make sure you log in manually at least once so that you can enter your username and password.

UPDATE 5/19/2011: I modified the init script so that I can print from a particular user. That way, if I print to cups-pdf, my files will be in ~/PDF/. When cloudprint is run as root, I don’t know where the PDF’s generated from cups-pdf are. The README and /etc/cups/cups-pdf.conf documentation states that outputs are always in $HOME/PDF, and anonymous files are stored in /var/spool/cups-pdf/ANONYMOUS. However, I do not see the files in these locations. Therefore, I will just run cloudprint as my myself instead of root.

Also, I discovered PrinterShare, a pretty useful printing app for Android devices.

UPDATE 4/2/2012: You actually need to hard code your google credentials in order for the daemon to work (path: /usr/local/lib/python2.7/dist-packages/cloudprint-0.5-py2.7.egg/cloudprint/cloudprint.py). As I did not want to expose my credentials, I created a new gmail account dedicated to CloudPrint. I hard code these credentials, and add the google account to my Android device.

About Vinh Nguyen

Statistician

18 comments

  1. when i installt it on my ubuntu 10.04 server. i get “No module named cups”

    I think i need to install something.

  2. Pingback: Steven Nay
  3. Pingback: junichi_y
  4. Pingback: Helmuth B
  5. Cloud Print is available for Chromium > 11. Enter this into the address bar: about:Flags This will open a page showing many disabled features. Go to the “Cloud Print Proxy” entry, and click on the “Enable” link. You will have to restart the browser in order for the change to fully take effect. Then wrench>Preferences>Under The Hood>Google Cloud Print will then be available.

  6. I modifed the init script to use debian startup functions. I couldn’t find a good way to log the output to syslog, but so far so good (hopefully this looks okay):

    !/bin/bash

    /etc/rc.d/cloudprint

    Description: Starts the Google Cloud Print script on startup


    #

    BEGIN INIT INFO

    Provides: Cloud-Print

    Required-Start: $cups $network $local_fs $syslog

    Required-Stop: $local_fs $syslog

    Default-Start: 2 3 4 5

    Default-Stop: 0 1 6

    Description: Start Google Cloud Print

    END INIT INFO

    name of app

    DESC="Google Cloud Print"

    path to daemon

    DAEMON=/usr/local/bin/cloudprint

    user to switch to after startup

    RUN_AS=

    PIDFILE=/var/run/cloudprint.pid

    load in LSB functions (log_*)

    . /lib/lsb/init-functions

    do_start() { RETVAL=0 start-stop-daemon --start --pidfile $PIDFILE --chuid $RUN_AS --make-pidfile --background --exec $DAEMON RETVAL=$? log_end_msg ${RETVAL} }

    do_stop() { RETVAL=0 start-stop-daemon --stop --pidfile $PIDFILE RETVAL=$? log_end_msg ${RETVAL} }

    case $1 in start) log_daemon_msg "Starting $DESC" do_start ;; stop) log_daemon_msg "Stopping $DESC" do_stop ;; restart|force-reload) log_daemon_msg "Restarting $DESC" do_stop sleep 5 do_start ;; *) echo "Usage: cloudprint {start|stop|restart|force-reload}" exit 3 ;; esac

      1. Vinh, first of all, I just realized that this problem is outdated. With the latest version you are asked for your credentials and they will be saved, crypted, in a ~/.cloudprintauth. Just like you say by the way when you “log in manually at least once”. The way 2-step authentication works is that for gmail login through the website you have to authenticate with your normal credentials AND with a code you get either by SMS or the Google Authenticator App. You can save this code in a cookie for 30 days. You can start it here. For applications not supporting 2-step auth you must create application specific passwords as per here. These can not be used to login to the website, only by POP, IMAP and the like. You must also use such a password for cloudprint. That way, even when it is hardcoded, when compromised access is very limited and can be revoked remotely. Does this help you further? Or do you have more specific questions?

  7. GREAT POST, BRILLIANT, very useful!

    It’s true, the last version do NOT need hardcode credentials, and… Nowadays, Google Print allows you to share printers from one account to others, so, it’s no more necessary to “expose” an account, just use any account on your printer server, and share printers with any google users you want.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>