#!/bin/bash
#======================================================================
# Copyright (c) 1997 Daniele Giacomini daniele@pluto.linux.it
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#======================================================================
# stampa-smb
#
# Esempio di una sorta di filtro di stampa per utilizzare una stampante
# condivisa da un server SMB.
#======================================================================

#======================================================================
# Variabili.
#======================================================================

    #------------------------------------------------------------------
    # Il nome del file temporaneo da utilizzare per la stampa.
    #------------------------------------------------------------------
    STAMPA="$HOME/stampa-smb-$(date +%Y%m%d%H%M%S)"
    #------------------------------------------------------------------
    # Il nome del servizio di stampa SMB.
    #------------------------------------------------------------------
    SMB_PRINT='\\paperone.zagozigo.dg\lp'

#======================================================================
# Inizio.
#======================================================================

    #------------------------------------------------------------------
    # Scarica lo standard input nel file temporaneo, trasformandolo
    # in un testo ``Dos'' in cui ``newline'' corrisponda alla sequenza
    # <CR><LF>.
    #------------------------------------------------------------------
    cat | unix2dos > $STAMPA
    #------------------------------------------------------------------
    # Invia il file ad un servizio di stampa SMB.
    #------------------------------------------------------------------
    smbclient $SMB_PRINT "" -P -c "print $STAMPA" > /dev/null
    #------------------------------------------------------------------
    # Elimina il file transitorio.
    #------------------------------------------------------------------
    rm $STAMPA > /dev/null

#======================================================================
# Fine.
#======================================================================
