#!/usr/sbin/cfagent -f

control:
   any::
   actionsequence = ( editfiles )
   EditFileSize = ( 30000 )

editfiles:
   any::
	{ ${target}/etc/cups/cupsd.conf
	  ## Allow remote access:
	  BeginGroupIfNoSuchLine 'Port 631'
	    HashCommentLinesStarting 'Listen localhost:631'
	    LocateLineMatching '#.*Listen localhost:631'
	    InsertLine '# Allow remote access'
	    InsertLine 'Port 631'
	    InsertLine 'ServerAlias print.intern'

	    LocateLineMatching '<Location />'
	    LocateLineMatching '  Order allow,deny'
	    InsertLine '  # Allow remote access'
	    InsertLine '  Allow @LOCAL'

	    LocateLineMatching '<Location /admin>'
	    LocateLineMatching '  Order allow,deny'
	    InsertLine '  # Allow remote access'
	    InsertLine '  Allow @LOCAL'

	    LocateLineMatching '<Location /admin/conf>'
	    LocateLineMatching '  Order allow,deny'
	    InsertLine '  # Allow remote access'
	    InsertLine '  Allow @LOCAL'
	  EndGroup
	}

	{ ${target}/etc/cups/cupsd-systemd-listen.conf
	  BeginGroupIfNoSuchLine 'ListenStream=0.0.0.0:631'
	    HashCommentLinesStarting 'ListenStream='
	    AppendIfNoSuchLine '# Allow remote access:'
	    AppendIfNoSuchLine 'ListenStream=0.0.0.0:631'
	    AppendIfNoSuchLine 'ListenStream=[::]:631'
	  EndGroup
	}



# Comparable script:
#
# ## Skip if not installing/converting:
# if [ "$FAI_ACTION" != "install" ] && [ "$CONVERT" != "true" ] ; then
#     exit 0
# fi
#
# sed -i "s/Listen localhost:631/Port 631/" ${target}/etc/cups/cupsd.conf
# $ROOTCMD cupsctl ServerAlias=print.intern
# $ROOTCMD cupsctl --remote-admin
# $ROOTCMD cupsctl DefaultAuthType=Negotiate
