Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,27 @@ Install
::

pip install cloudprint

System setup (Ubuntu /etc/init.d/cloudprint)
---------------------------------------------------

::

sudo su -

useradd -d /home/cloudprint -m cloudprint
apt-get install git python-daemon python-pip python-cups cups-pdf

su - cloudprint

mkdir cloudprint
git clone -b ubuntu_etc_init.d https://github.com/drbitboy/cloudprint.git
python cloudprint/cloudprint/cloudprint.py
Google username: ...@gmail.com
Password: ...

exit

cp -p ~cloudprint/cloudprint/ubuntu_init_d_cloudprint /etc/init.d/cloudprint
update-rc.d cloudprint defaults 99 01
reboot
9 changes: 7 additions & 2 deletions cloudprint/cloudprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,21 @@ def msg(msg=' '):
return msg()

def usage():
print sys.argv[0] + ' [-d][-l][-h] [-p pid_file] [-a account_file]'
print sys.argv[0] + ' [-d][-l][-w][-h] [-p pid_file] [-a account_file]'
print '-d\t\t: enable daemon mode (requires the daemon module)'
print '-l\t\t: logout of the google account'
print '-w\t\t: Wait 20s for network resources on startup e.g. from /etc/init.d/ on boot'
print '-p pid_file\t: path to write the pid to (default cloudprint.pid)'
print '-a account_file\t: path to google account ident data (default ~/.cloudprintauth)'
print '\t\t account_file format:\t <Google username>'
print '\t\t\t\t\t <Google password>'
print '-h\t\t: display this help'

def main():
opts, args = getopt.getopt(sys.argv[1:], 'dlhp:a:')
opts, args = getopt.getopt(sys.argv[1:], 'dlwhp:a:')
daemon = False
logout = False
doWait = False
pidfile = None
authfile = None
saslauthfile = None
Expand All @@ -400,6 +402,8 @@ def main():
elif o == '-a':
authfile = a
saslauthfile = authfile+'.sasl'
elif o == '-w':
doWait = True
elif o =='-h':
usage()
sys.exit()
Expand Down Expand Up @@ -443,6 +447,7 @@ def main():
cpp.password = getpass.getpass()

#try to login
if doWait: time.sleep(20) ### N.B. A hardcoded timeout is a bad idea!
while True:
try:
sync_printers(cups_connection, cpp)
Expand Down
93 changes: 93 additions & 0 deletions ubuntu_init_d_cloudprint
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
# /etc/init.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

CPNAME="cloudprint"
CPUSER="$CPNAME"
CPHOME="/home/$CPUSER"
DIR="$CPHOME/$CPNAME/$CPNAME"
PFX="$DIR/$CPNAME"
EXE="$PFX.py"
PIDFILE="$PFX.pid"
AUTH1="$CPHOME/.${CPNAME}auth"
AUTH2="$AUTH1.sasl"
CP_OPTS="-w -d -p $PIDFILE -a $AUTH1"
QORV=--quiet
xQORV=--verbose

set -e

elog() {
( /bin/date | tr \\n ' ' ; echo $* ) \
1>>/tmp/cloudprint.log 2>>/tmp/cloudprint.err
}

test -x "$EXE" || exit 0
test -f "$AUTH1" || exit 0
test -r "$AUTH1" || exit 0
test -f "$AUTH2" || exit 0
test -r "$AUTH2" || exit 0
( "$EXE" -h 2>&1 | grep -q '/cloudprint.py.*-h' ) 2>/dev/null || exit 0

umask 022

if test -f "/etc/default/$CPNAME"; then
. "/etc/default/$CPNAME"
fi

. /lib/lsb/init-functions

if [ -n "$2" ]; then
CP_OPTS="$CP_OPTS $2"
fi

export PATH="${PATH:+$PATH:}/usr/sbin:/sbin:/usr/bin:/bin"

case "$1" in
start)
log_daemon_msg "Starting $CPNAME server; options=$CP_OPTS" "$CPNAME" || true
if start-stop-daemon --start $QORV --oknodo --chuid "$CPNAME" --group "$CPNAME" --exec "$EXE" -- $CP_OPTS; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for --chuid and --group you want to replace $CPNAME with $CPUSER.

log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
stop)
log_daemon_msg "Stopping $CPNAME server" "$CPNAME" || true
if start-stop-daemon --stop $QORV --oknodo --pidfile "$PIDFILE"; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;

restart)
log_daemon_msg "Restarting $CPNAME server; options=$CP_OPTS" "$CPNAME" || true
start-stop-daemon --stop $QORV --oknodo --retry 30 --pidfile "$PIDFILE"
if start-stop-daemon --start $QORV --oknodo --chuid "$CPNAME" --group "$CPNAME" --exec "$EXE" -- $CP_OPTS; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above comment on line 59.

log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;

status)
status_of_proc -p "$PIDFILE" "$EXE" "$CPNAME" && exit 0 || exit $?
;;

*)
log_action_msg "Usage: /etc/init.d/$CPNAME {start|stop|reload|force-reload|restart|try-restart|status}" || true
exit 1
esac

exit 0