#!/bin/sh
#
# (c) Copyright 1999-2024 PaperCut Software International Pty Ltd
#
# A script to set permissions on special files
#

. "`dirname \"$0\"`/.common"

#
# Change to the provider home
#
cd "${SCRIPT_HOME}"

#
# Ensure files have execute permissions
#
chmod 755 setperms
chmod 755 roottasks

#
# Note: roottasks will endeavour to "copy" the permissions from
# another reference backend however this default is pretty
# failsafe for most situations.
#
chmod 755 cups-print-provider
chmod 755 cups-filter-print-provider
chmod 755 cups-api-helper
chmod 755 pc-event-monitor
chmod 755 pc-event-monitor.rc
chmod 755 pc-print-monitor
chmod 755 pc-send-job
chmod 755 refund-job
chmod 755 samba-print-provider
chmod 755 helper-print-provider
chmod 755 pc-gen-uuid

if [ -f novell-print-provider ]; then
    chmod 755 novell-print-provider
fi

if [ -f novell-print-provider-iprint42 ]; then
    chmod 755 novell-print-provider-iprint42
fi

if [ -f pc-print-spool-file ]; then
    chmod 755 pc-print-spool-file
fi
#
# Supporting Scripts
#
chmod 755 configure-cups
if [ -f configure-cups-mac.command ]; then
    chmod 755 configure-cups-mac.command
fi


#
# Ensure conf file can be read by all
#
chmod 664 print-provider.conf


#
# Ensure log file can be written by the "print" users such as
# cupsd, lp, etc.
#
touch print-provider.log
chmod 666 print-provider.log*

# Debug enable/disable and config helper scripts (linux and mac versions)
if [ -f debug-enable.sh ]; then
    chmod 755 debug-enable.sh
fi
if [ -f debug-snapshot-enable.sh ]; then
    chmod 755 debug-snapshot-enable.sh
fi
if [ -f debug-disable.sh ]; then
    chmod 755 debug-disable.sh
fi
if [ -f debug-enable.command ]; then
    chmod 755 debug-enable.command
fi
if [ -f debug-snapshot-enable.command ]; then
    chmod 755 debug-snapshot-enable.command
fi
if [ -f debug-disable.command ]; then
    chmod 755 debug-disable.command
fi
if [ -f set-config.sh ]; then
    chmod 755 set-config.sh
fi

#
# Ensure spool and its sub-directories can be written into
# by the "print" users such as cupsd, lp, etc.
#
chmod 777 spool 2>/dev/null
chmod 777 spool/jobreplay 2>/dev/null
chmod 777 spool/settings 2>/dev/null
chmod 777 spool/locks 2>/dev/null
chmod 777 spool/activejobs 2>/dev/null
chmod 777 spool/heldjobs 2>/dev/null
chmod 777 spool/tmpcups 2>/dev/null

#
# Ensure we're accessable from all from above up to the home level.
# We need this to ensure that CUPS and Samba can browse down and
# run our binaries.
#
chmod 755 .
chmod 755 ./..
chmod 755 ./../..

#
# Hack: We also need to ensure our home directory is 755 for same
# reason above. This should be done in the installer, however until
# we get a complete secondary server install option, we'll do this
# here also.
chmod 755 ./../../..
