#!/bin/sh
#
#	$OpenBSD: cups-disable,v 1.2 2009/04/27 08:25:39 bernd Exp $
#
#	this script disables CUPS by removing links created by
#	cups-enable.

PREFIX=/usr/local
BINDIR=/usr/bin
SBINDIR=/usr/sbin
QUIET=No

if [ "$1x" == "-qx" ]; then
    QUIET=Yes
fi

if [ `id -u` -ne 0 ]; then
    if [ "$QUIET" == "No" ]; then
        echo "You must be root to run this script."
    fi
    exit 0
fi

if [ "$QUIET" == "No" ]; then
    echo "This script will remove CUPS links from $BINDIR and $SBINDIR"
    echo ""
    echo -n "Are you sure you want to do this (y/[n])? "

    read answer
    echo ""

    if [ X$answer != Xy ]; then
        echo "exit"
        exit
    fi
fi

if [ ! -L /usr/sbin/lpc ]; then
    if [ "$QUIET" == "No" ]; then
        echo "CUPS not enabled, script terminated."
    fi
    exit 0
fi

######################################################################
if [ "$QUIET" == "No" ]; then
    echo "Removing CUPS links:"
fi

for link in \
    lpq lpr lprm
do
    if [ -L $BINDIR/$link ]; then
        if [ "$QUIET" == "No" ]; then
            echo " $link"
        fi
        rm -f $BINDIR/$link
    fi
done

for link in \
    lpc
do
    if [ -L $SBINDIR/$link ]; then
        if [ "$QUIET" == "No" ]; then
            echo " $link"
        fi
        rm -f $SBINDIR/$link
    fi
done

if [ "$QUIET" == "No" ]; then
    echo done.
    echo ""
fi

######################################################################
if [ ! -e /usr/sbin/lpd.pre-cups ]; then
    if [ "$QUIET" == "No" ]; then
        echo "Couldn't find saved lpd files, saved files not restored."
    fi
    exit 0
else
    if [ "$QUIET" == "No" ]; then
        echo "Trying to restore lpd files:"
    fi

    for file in \
	/usr/bin/lpq \
	/usr/bin/lpr \
	/usr/bin/lprm \
	/usr/sbin/lpc \
	/usr/sbin/lpd \
	/usr/share/man/cat1/lpq.0 \
	/usr/share/man/cat1/lpr.0 \
	/usr/share/man/cat1/lprm.0 \
	/usr/share/man/cat8/lpc.0 \
	/usr/share/man/cat8/lpd.0 \
	/etc/printcap
    do
	if [ -e $file.pre-cups ]; then
            if [ "$QUIET" == "No" ]; then
	        echo " $file"
            fi
	    mv $file.pre-cups $file
	fi
    done

    if [ "$QUIET" == "No" ]; then
        echo done.
        echo ""
    fi
fi
