Skip to content

Instantly share code, notes, and snippets.

@tavinus
Last active March 29, 2016 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tavinus/0b60e453a05deb6b2118 to your computer and use it in GitHub Desktop.
Save tavinus/0b60e453a05deb6b2118 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# gcp Starts GCP CUPS Connector daemnon
# description: Google cloudprint is a service for sharing printers \
# among computers through the internet and LAN.
#
### BEGIN INIT INFO
# Provides: cloudprint
# Required-Start: $cups $network $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts the cloudprint connector daemon
# Description: Google CUPS Connector shares printers locally
# and with the Google Cloud Print webservice.
### END INIT INFO
####################################################################
# GCP Cups Connector service service for /etc/init.d/gcp
#
# Run GCP CUPS Connector on boot as a service
# Author: Gustavo Arnosti Neves
# System: Centos 6.5
#
# Google CUPS Connector:
# https://github.com/google/cups-connector
#
# This script:
# https://gist.github.com/tavinus/0b60e453a05deb6b2118
#
# Cron checker script:
# https://gist.github.com/tavinus/90382c20f8ac923796a8
#
# Instructions:
# You should follow the linked guide for the installation of
# Google CUPS Connector, including creating a config file.
# You should adjust the file locations if you used different
# ones. You should also adjust the user/group if you used
# something other than gcp.
#
# Install GCP CUPS Connector:
# https://github.com/google/cups-connector/wiki/Installing-on-Raspberry-Pi-Raspbian-Jessie
#
# Run on boot:
# $ sudo cp gcp /etc/init.d/gcp && sudo chmod 755 /etc/init.d/gcp # copy file
# $ sudo chkconfig --level 2345 gcp on # turn on
#
####################################################################
GCP_USER="gcp"
CP_BIN='/opt/gcp_cups_connector/gcp-cups-connector'
PIDFILE='/var/run/gcp_cups_connector_pid'
CREDENTIALS_FILE='/etc/gcp_cups_connector/gcp-cups-connector.config.json'
LOGFILE='/tmp/gcp_cups_connector.log'
print_results() {
if [[ $1 -eq 0 ]]; then
echo '[ Ok ]'
else
echo '[ Fail ]'
fi
}
case $1 in
start)
if [[ -f $PIDFILE ]]; then
echo "[ -- ] GCP CUPS Connector is already running..."
else
echo -ne '[ -- ] Starting GCP CUPS Connector...\r'
sudo -H -u "$GCP_USER" $CP_BIN -config-filename $CREDENTIALS_FILE > $LOGFILE & echo $! > $PIDFILE
print_results $?
fi
;;
stop)
if [[ -f $PIDFILE ]]; then
echo -ne '[ -- ] Stopping GCP CUPS Connector...\r'
kill $(cat "$PIDFILE")
wait ${!} 2>/dev/null
print_results $?
rm -f "$PIDFILE" 2>/dev/null
else
echo "[ -- ] Nothing to be stopped..."
fi
;;
status)
if [[ -f $PIDFILE ]]; then
echo 'GCP CUPS Connector is running with PID: '$(cat "$PIDFILE")
else
echo 'GCP CUPS Connector is NOT running...'
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: gcp {start|stop|status|restart}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment