#!/bin/sh -e

# make sure directories exist for checkpc
echo "Running checkpc..." >&2
if [ ! -d /var/spool/lpd ]; then
    mkdir /var/spool/lpd
    mkdir /var/spool/lpd/%P
else
    if [ ! -d /var/spool/lpd/%P ]; then
	mkdir /var/spool/lpd/%P
    fi
fi
chmod og=rwx /var/spool/lpd
chmod og=rwx /var/spool/lpd/%P

if [ -e /usr/lib/gutenbach/config/printername ]; then
    printername=$(cat /usr/lib/gutenbach/config/printername)
    /usr/sbin/checkpc -P"$printername" -f
else
    echo "Error: /usr/lib/gutenbach/config/printername does not exist!" >&2
    exit 1
fi