#!/bin/bash

AUTHDIR=/var/lib/cloudprintd
AUTHFILE=$AUTHDIR/authfile.json

systemctl is-active cloudprintd >/dev/null
ACTIVE=$?

if [ ! -w $AUTHDIR ] ; then echo "Must run as root" ; exit 1 ; fi

if [ $ACTIVE -eq 0 ] ; then systemctl stop cloudprintd ; fi

rm -f $AUTHFILE
cloudprint -c -a $AUTHFILE

if [ $ACTIVE -eq 0 ] ; then systemctl start cloudprintd ; fi
